Exemplo n.º 1
0
    private static void RenameVariables(IRGraph graph, DominatorTree dominatorTree)
    {
        // setup data structures
        Dictionary <Ident, int>          count = new Dictionary <Ident, int>();
        Dictionary <Ident, Stack <int> > stack = new Dictionary <Ident, Stack <int> >();

        foreach (Ident ident in graph.GetDefinedVars())
        {
            count[ident] = 0;
            stack[ident] = new Stack <int>();
            stack[ident].Push(0);
        }

        // recursively walk the dominator tree in-order starting with the root node
        Search(graph.GetGraphHead(), dominatorTree, count, stack);
    }
Exemplo n.º 2
0
    private static void InsertPhiFunctions(IRGraph graph, DominatorTree dominatorTree)
    {
        foreach (IRBlock block in graph.GetSetOfAllBlocks())
        {
            Console.WriteLine();
            Console.WriteLine("***");
            Console.WriteLine("Block: " + block.GetIndex());
            block.PrintStatements();

            Console.Write("Predecessors: ");
            foreach (IRBlock pred in graph.GetPredecessors(block))
            {
                Console.Write(pred.GetIndex() + ", ");
            }
            Console.WriteLine();

            Console.Write("Live in : ");
            foreach (Ident ident in block.GetLiveIn())
            {
                Console.Write(ident + ", ");
            }
            Console.WriteLine();

            Console.Write("Defined vars: ");
            foreach (Ident ident in block.GetDefinedVars())
            {
                Console.Write(ident + ", ");
            }
            Console.WriteLine();
        }

        foreach (Ident v in graph.GetDefinedVars())
        {
            // A(v) = blocks containing an assignment to v
            HashSet <IRBlock> Av = new HashSet <IRBlock>();
            foreach (IRBlock block in graph.GetSetOfAllBlocks())
            {
                if (block.GetDefinedVars().Contains(v) && block.GetLiveIn().Contains(v))
                {
                    Av.Add(block);
                }
            }

            // place Phi tuple for each v in the iterated dominance frontier of A(v)
            HashSet <IRBlock> needsPhiFunction = new HashSet <IRBlock>();
            foreach (IRBlock Avblock in Av)
            {
                // create set of blocks that need phi functions
                foreach (IRBlock block in dominatorTree.GetDominanceFrontier(Avblock))
                {
                    needsPhiFunction.Add(block);
                }
            }

            // only want one phi function per block for each variable where appropiate
            foreach (IRBlock block in needsPhiFunction)
            {
                // Phi function should have as many arguments as it does predecessors
                List <Ident> sources = new List <Ident>();
                foreach (IRBlock b in graph.GetPredecessors(block))
                {
                    sources.Add(v);
                }

                IRTupleManyOp phi = new IRTupleManyOp(IrOp.PHI, v, sources);

                block.InsertStatement(phi, 0);
                Console.WriteLine("** SSA: Inserting phi function: " + phi.toString() + " into block " + block.GetIndex());
            }
        }
    }
Exemplo n.º 3
0
    private static void InsertPhiFunctions(IRGraph graph, DominatorTree dominatorTree)
    {
        foreach (IRBlock block in graph.GetSetOfAllBlocks())
        {
          Console.WriteLine();
          Console.WriteLine("***");
          Console.WriteLine("Block: " + block.GetIndex());
          block.PrintStatements();

          Console.Write("Predecessors: ");
          foreach (IRBlock pred in graph.GetPredecessors(block))
        Console.Write(pred.GetIndex() + ", ");
          Console.WriteLine();

          Console.Write("Live in : ");
          foreach (Ident ident in block.GetLiveIn())
        Console.Write(ident + ", ");
          Console.WriteLine();

          Console.Write("Defined vars: ");
          foreach (Ident ident in block.GetDefinedVars())
        Console.Write(ident + ", ");
          Console.WriteLine();
        }

        foreach (Ident v in graph.GetDefinedVars())
        {
          // A(v) = blocks containing an assignment to v
          HashSet<IRBlock> Av = new HashSet<IRBlock>();
          foreach (IRBlock block in graph.GetSetOfAllBlocks())
          {
        if (block.GetDefinedVars().Contains(v) && block.GetLiveIn().Contains(v))
          Av.Add(block);
          }

          // place Phi tuple for each v in the iterated dominance frontier of A(v)
          HashSet<IRBlock> needsPhiFunction = new HashSet<IRBlock>();
          foreach (IRBlock Avblock in Av)
          {
        // create set of blocks that need phi functions
        foreach (IRBlock block in dominatorTree.GetDominanceFrontier(Avblock))
        {
          needsPhiFunction.Add(block);
        }
          }

          // only want one phi function per block for each variable where appropiate
          foreach (IRBlock block in needsPhiFunction)
          {
        // Phi function should have as many arguments as it does predecessors
        List<Ident> sources = new List<Ident>();
        foreach (IRBlock b in graph.GetPredecessors(block))
          sources.Add(v);

        IRTupleManyOp phi = new IRTupleManyOp(IrOp.PHI, v, sources);

        block.InsertStatement(phi, 0);
        Console.WriteLine("** SSA: Inserting phi function: " + phi.toString() + " into block " + block.GetIndex());
          }
        }
    }
Exemplo n.º 4
0
    private static void RenameVariables(IRGraph graph, DominatorTree dominatorTree)
    {
        // setup data structures
        Dictionary<Ident, int> count = new Dictionary<Ident, int>();
        Dictionary<Ident, Stack<int>> stack = new Dictionary<Ident, Stack<int>>();

        foreach (Ident ident in graph.GetDefinedVars())
        {
          count[ident] = 0;
          stack[ident] = new Stack<int>();
          stack[ident].Push(0);
        }

        // recursively walk the dominator tree in-order starting with the root node
        Search(graph.GetGraphHead(), dominatorTree, count, stack);
    }