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.
int shcount (Tree key, Tree t)
 Return the value of sharing count or 0.
static void annotate (Tree k, Tree t, barrier foo)
 Recursively increment the occurences count of t and its subtrees.
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.
Tree shlysis (Tree t)
 Do a sharing analysis : annotates all the subtrees of t with there occurences.

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().

00130 {
00131     cerr << "Annotate " << *t << endl;
00132     int c = shcount(k,t);
00133     if (c==0) {
00134         // First visit
00135         Tree var, body;
00136         if (isRec(t, var, body)) {
00137             // special case for recursive trees
00138             setProperty(t, k, tree(1));
00139             annotate(k, body, foo);
00140             return;
00141         } else {
00142             int n = t->arity();
00143             if (n>0 && ! foo(t)) {
00144                 for (int i=0; i<n; i++) annotate(k, t->branch(i), foo);
00145             }
00146         }
00147     } else {
00148         //printf(" annotate %p with %d\n", (CTree*)t, c+1);
00149     }
00150     setProperty(t, k, tree(c+1));
00151 }

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().

00099 { 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().

00082 {
00083     Tree c;
00084     if (getProperty(t, key, c)) {
00085         return c->node().getInt();
00086     } else {
00087         return 0;
00088     }
00089 }   

Here is the call graph for this function:

Here is the caller 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().

00118 {
00119     Tree k = shprkey(t);
00120     annotate(k, t, nobarrier);
00121     return k;
00122 }

Here is the call 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().

00106 {
00107     Tree k = shprkey(t);
00108     annotate(k, t, foo);
00109     return k;
00110 }

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().

00070 {
00071     char    name[256];
00072     snprintf(name, 256, "SHARED IN %p : ", (CTree*)t);
00073     return tree(unique(name));
00074 }   

Here is the call graph for this function:

Here is the caller graph for this function:

Generated on Tue Aug 10 08:04:16 2010 for FAUST compiler by  doxygen 1.6.3