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(); } } }
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(); } }