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

{
    cerr << "Annotate " << *t << endl;
    int c = shcount(k,t);
    if (c==0) {
        // First visit
        Tree var, body;
        if (isRec(t, var, body)) {
            // special case for recursive trees
            setProperty(t, k, tree(1));
            annotate(k, body, foo);
            return;
        } else {
            int n = t->arity();
            if (n>0 && ! foo(t)) {
                for (int i=0; i<n; i++) annotate(k, t->branch(i), foo);
            }
        }
    } else {
        //printf(" annotate %p with %d\n", (CTree*)t, c+1);
    }
    setProperty(t, k, tree(c+1));
}

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

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

{
    Tree c;
    if (getProperty(t, key, c)) {
        return c->node().getInt();
    } else {
        return 0;
    }
}   

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

{
    Tree k = shprkey(t);
    annotate(k, t, foo);
    return k;
}

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

{
    Tree k = shprkey(t);
    annotate(k, t, nobarrier);
    return k;
}

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

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

Here is the call graph for this function:

Here is the caller graph for this function: