FAUST compiler  0.9.9.6b8
Functions
shlysis.cpp File Reference

The sharing analysis of tree t is the annotation of all its subtrees t' with their number of occurences in t. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "shlysis.hh"
#include "compatibility.hh"
Include dependency graph for shlysis.cpp:

Go to the source code of this file.

Functions

Tree shprkey (Tree t)
 Create a specific property key for the sharing count of subtrees of t. More...
 
int shcount (Tree key, Tree t)
 Return the value of sharing count or 0. More...
 
static void annotate (Tree k, Tree t, barrier foo)
 Recursively increment the occurences count of t and its subtrees. More...
 
static bool nobarrier (const Tree &t)
 
Tree shlysis (Tree t, barrier foo)
 Do a sharing analysis : annotates all the subtrees of t with there occurences. More...
 
Tree shlysis (Tree t)
 Do a sharing analysis : annotates all the subtrees of t with there occurences. More...
 

Detailed Description

The sharing analysis of tree t is the annotation of all its subtrees t' with their number of occurences in t.

As this annotation of t' depends of a context (the tree t for which t' is a subtree) a specific property key unique to each sharing analysis must be generated.

Definition in file shlysis.cpp.

Function Documentation

static void annotate ( Tree  k,
Tree  t,
barrier  foo 
)
static

Recursively increment the occurences count of t and its subtrees.

Definition at line 129 of file shlysis.cpp.

References CTree::arity(), CTree::branch(), isRec(), setProperty(), shcount(), and tree().

Referenced by shlysis().

130 {
131  cerr << "Annotate " << *t << endl;
132  int c = shcount(k,t);
133  if (c==0) {
134  // First visit
135  Tree var, body;
136  if (isRec(t, var, body)) {
137  // special case for recursive trees
138  setProperty(t, k, tree(1));
139  annotate(k, body, foo);
140  return;
141  } else {
142  int n = t->arity();
143  if (n>0 && ! foo(t)) {
144  for (int i=0; i<n; i++) annotate(k, t->branch(i), foo);
145  }
146  }
147  } else {
148  //printf(" annotate %p with %d\n", (CTree*)t, c+1);
149  }
150  setProperty(t, k, tree(c+1));
151 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
int shcount(Tree key, Tree t)
Return the value of sharing count or 0.
Definition: shlysis.cpp:81
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
static void annotate(Tree k, Tree t, barrier foo)
Recursively increment the occurences count of t and its subtrees.
Definition: shlysis.cpp:129

Here is the call graph for this function:

Here is the caller graph for this function:

static bool nobarrier ( const Tree t)
static

Definition at line 99 of file shlysis.cpp.

Referenced by shlysis().

99 { return false; }

Here is the caller graph for this function:

int shcount ( Tree  key,
Tree  t 
)

Return the value of sharing count or 0.

Definition at line 81 of file shlysis.cpp.

References Node::getInt(), getProperty(), and CTree::node().

Referenced by annotate().

82 {
83  Tree c;
84  if (getProperty(t, key, c)) {
85  return c->node().getInt();
86  } else {
87  return 0;
88  }
89 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
int getInt() const
Definition: node.hh:104
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

Tree shlysis ( Tree  t,
barrier  foo 
)

Do a sharing analysis : annotates all the subtrees of t with there occurences.

Definition at line 105 of file shlysis.cpp.

References annotate(), and shprkey().

106 {
107  Tree k = shprkey(t);
108  annotate(k, t, foo);
109  return k;
110 }
Tree shprkey(Tree t)
Create a specific property key for the sharing count of subtrees of t.
Definition: shlysis.cpp:69
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static void annotate(Tree k, Tree t, barrier foo)
Recursively increment the occurences count of t and its subtrees.
Definition: shlysis.cpp:129

Here is the call graph for this function:

Tree shlysis ( Tree  t)

Do a sharing analysis : annotates all the subtrees of t with there occurences.

Definition at line 117 of file shlysis.cpp.

References annotate(), nobarrier(), and shprkey().

118 {
119  Tree k = shprkey(t);
120  annotate(k, t, nobarrier);
121  return k;
122 }
Tree shprkey(Tree t)
Create a specific property key for the sharing count of subtrees of t.
Definition: shlysis.cpp:69
static bool nobarrier(const Tree &t)
Definition: shlysis.cpp:99
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static void annotate(Tree k, Tree t, barrier foo)
Recursively increment the occurences count of t and its subtrees.
Definition: shlysis.cpp:129

Here is the call graph for this function:

Tree shprkey ( Tree  t)

Create a specific property key for the sharing count of subtrees of t.

Definition at line 69 of file shlysis.cpp.

References name(), tree(), and unique().

Referenced by ScalarCompiler::sharingAnalysis(), DocCompiler::sharingAnalysis(), and shlysis().

70 {
71  char name[256];
72  snprintf(name, 256, "SHARED IN %p : ", (CTree*)t);
73  return tree(unique(name));
74 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function: