diff --git a/lib/CodeGen/StrongPHIElimination.cpp b/lib/CodeGen/StrongPHIElimination.cpp index eff02f1fbf9..aa25dfebd80 100644 --- a/lib/CodeGen/StrongPHIElimination.cpp +++ b/lib/CodeGen/StrongPHIElimination.cpp @@ -101,7 +101,7 @@ namespace { std::vector& DF, std::vector >& locals); void ScheduleCopies(MachineBasicBlock* MBB, std::set& pushed); - void InsertCopies(MachineBasicBlock* MBB); + void InsertCopies(MachineBasicBlock* MBB, std::set& v); }; char StrongPHIElimination::ID = 0; @@ -610,7 +610,10 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, } /// InsertCopies - insert copies into MBB and all of its successors -void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB) { +void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB, + std::set& visited) { + visited.insert(MBB); + std::set pushed; // Rewrite register uses from Stacks @@ -629,7 +632,8 @@ void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB) { for (GraphTraits::ChildIteratorType I = GraphTraits::child_begin(MBB), E = GraphTraits::child_end(MBB); I != E; ++I) - InsertCopies(*I); + if (!visited.count(*I)) + InsertCopies(*I, visited); // As we exit this block, pop the names we pushed while processing it for (std::set::iterator I = pushed.begin(), @@ -649,7 +653,8 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { // Insert copies // FIXME: This process should probably preserve LiveVariables - InsertCopies(Fn.begin()); + std::set visited; + InsertCopies(Fn.begin(), visited); // Perform renaming typedef std::map > RenameSetType;