Example #1
0
    private static void printTree(DominatorTreeNode node)
    {
        Console.WriteLine("\n** Node " + node.GetBlock().GetIndex());

        foreach (DominatorTreeNode desc in node.GetDescendants())
        {
            Console.Write(desc.GetBlock().GetIndex() + ", ");
        }
        Console.WriteLine();

        foreach (DominatorTreeNode desc in node.GetDescendants())
        {
            printTree(desc);
        }
    }
Example #2
0
    private SortedSet <IRBlock> ConstructDominanceFrontierMapping(IRBlock x)
    {
        // Using Ron Cytron et al Algorithm
        SortedSet <IRBlock> dfx = new SortedSet <IRBlock>();

        // DF(X)local
        foreach (IRBlock y in x.GetSuccessors())
        {
            if (!this.imediateDominator[y].Equals(x))
            {
                dfx.Add(y);
            }
        }

        // DF(X)up
        DominatorTreeNode xnode = this.blockToNodeMappings[x];

        foreach (DominatorTreeNode z in xnode.GetDescendants())
        {
            foreach (IRBlock y in this.dominanceFrontiers[z.GetBlock()])
            {
                if (!this.imediateDominator[y].Equals(x))
                {
                    dfx.Add(y);
                }
            }
        }

        return(dfx);
    }
Example #3
0
 private void RecurseDownTree(List <IRBlock> list, DominatorTreeNode node)
 {
     foreach (DominatorTreeNode descendant in node.GetDescendants())
     {
         RecurseDownTree(list, descendant);
     }
     list.Add(node.GetBlock());
 }
Example #4
0
    private static void Search(IRBlock block, DominatorTree dominatorTree, Dictionary <Ident, int> count, Dictionary <Ident, Stack <int> > stack)
    {
        // Algorithm from Ron Cytron et al to rename variables into SSA form
        foreach (IRTuple irt in block.GetStatements())
        {
            Console.Write("Type: " + irt.GetType() + " ");
            irt.Print();
            Console.WriteLine();

            if (irt.getOp() != IrOp.PHI)
            {
                foreach (Ident v in irt.GetUsedVars())
                {
                    Console.WriteLine("Renaming variable: " + v);
                    int i = stack[v].Peek();
                    RenameTupleSourcesHelper(irt, v, i); // replace uses of v with vi in statement
                }
            }

            foreach (Ident a in irt.GetDefinedVars())
            {
                count[a] = count[a] + 1;
                int i = count[a];
                stack[a].Push(i);
                irt.setDest(RenameVar(a, i)); // replace definitions of a with ai in statement
            }
        }

        // rename Phi function arguments in the successors
        List <IRBlock> successors = block.GetSuccessors();

        for (int i = 0; i < successors.Count; i++)
        {
            foreach (IRTuple stmt in block.GetStatements())
            {
                if (stmt.getOp() == IrOp.PHI)
                {
                    IRTupleManyOp phi       = (IRTupleManyOp)stmt;
                    Ident         v         = phi.GetSources()[i];
                    int           numbering = stack[v].Peek();
                    phi.SetSource(i, RenameVar(v, numbering));
                }
            }
        }

        // for each descendant do the Search(X) renaming process
        DominatorTreeNode node = dominatorTree.GetNode(block);

        foreach (DominatorTreeNode descendant in node.GetDescendants())
        {
            Search(descendant.GetBlock(), dominatorTree, count, stack);
        }

        // pop stack phase
        foreach (IRTuple irt in block.GetStatements())
        {
            foreach (Ident v in irt.GetDefinedVars())
            {
                stack[v].Pop();
            }
        }
    }
Example #5
0
 private void RecurseDownTree(List<IRBlock> list, DominatorTreeNode node)
 {
     foreach(DominatorTreeNode descendant in node.GetDescendants())
     {
       RecurseDownTree(list, descendant);
     }
     list.Add(node.GetBlock());
 }
    private static void printTree(DominatorTreeNode node)
    {
        Console.WriteLine("\n** Node " + node.GetBlock().GetIndex());

        foreach (DominatorTreeNode desc in node.GetDescendants()) {
          Console.Write(desc.GetBlock().GetIndex() + ", ");
        }
        Console.WriteLine();

        foreach (DominatorTreeNode desc in node.GetDescendants()) {
          printTree(desc);
        }
    }