Index: include/llvm/CodeGen/ExecutionDepsFix.h =================================================================== --- include/llvm/CodeGen/ExecutionDepsFix.h +++ include/llvm/CodeGen/ExecutionDepsFix.h @@ -205,7 +205,8 @@ void leaveBasicBlock(MachineBasicBlock*); bool isBlockDone(MachineBasicBlock *); void processBasicBlock(MachineBasicBlock *MBB, bool PrimaryPass); - void updateSuccessors(MachineBasicBlock *MBB, bool PrimaryPass); + void updateSuccessors(std::vector &ToRevisit, + MachineBasicBlock *MBB, bool PrimaryPass); bool visitInstr(MachineInstr *); void processDefs(MachineInstr *, bool breakDependency, bool Kill); void visitSoftInstr(MachineInstr*, unsigned mask); Index: lib/CodeGen/ExecutionDepsFix.cpp =================================================================== --- lib/CodeGen/ExecutionDepsFix.cpp +++ lib/CodeGen/ExecutionDepsFix.cpp @@ -616,7 +616,9 @@ MBBInfos[MBB].IncomingProcessed == MBB->pred_size(); } -void ExecutionDepsFix::updateSuccessors(MachineBasicBlock *MBB, bool Primary) { +void ExecutionDepsFix::updateSuccessors( + std::vector &ToRevisit, MachineBasicBlock *MBB, + bool Primary) { bool Done = isBlockDone(MBB); for (auto *Succ : MBB->successors()) { if (!isBlockDone(Succ)) { @@ -627,10 +629,7 @@ MBBInfos[Succ].IncomingCompleted++; } if (isBlockDone(Succ)) { - // Perform secondary processing for this successor. See the big comment - // in runOnMachineFunction, for an explanation of the iteration order. - processBasicBlock(Succ, false); - updateSuccessors(Succ, false); + ToRevisit.push_back(Succ); } } } @@ -708,6 +707,7 @@ MachineBasicBlock *Entry = &*MF->begin(); ReversePostOrderTraversal RPOT(Entry); + std::vector ToRevisit; for (ReversePostOrderTraversal::rpo_iterator MBBI = RPOT.begin(), MBBE = RPOT.end(); MBBI != MBBE; ++MBBI) { MachineBasicBlock *MBB = *MBBI; @@ -716,7 +716,13 @@ MBBInfos[MBB].PrimaryCompleted = true; MBBInfos[MBB].PrimaryIncoming = MBBInfos[MBB].IncomingProcessed; processBasicBlock(MBB, true); - updateSuccessors(MBB, true); + updateSuccessors(ToRevisit, MBB, true); + while (!ToRevisit.empty()) { + MachineBasicBlock *ToRevisitBB = &*ToRevisit.back(); + ToRevisit.pop_back(); + processBasicBlock(ToRevisitBB, false); + updateSuccessors(ToRevisit, ToRevisitBB, false); + } } // We need to go through again and finalize any blocks that are not done yet.