[PATCH] D31681: [ExecutionDepsFix] Don't recurse over the CFG
Keno Fischer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 4 15:18:08 PDT 2017
loladiro created this revision.
Use an explicit std::vector instead, to avoid accidentally causing stack overflows
for input with very large CFGs.
https://reviews.llvm.org/D31681
Files:
include/llvm/CodeGen/ExecutionDepsFix.h
lib/CodeGen/ExecutionDepsFix.cpp
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<MachineBasicBlock *> &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,15 +707,22 @@
MachineBasicBlock *Entry = &*MF->begin();
ReversePostOrderTraversal<MachineBasicBlock*> RPOT(Entry);
+ std::vector<MachineBasicBlock *> ToRevisit;
for (ReversePostOrderTraversal<MachineBasicBlock*>::rpo_iterator
MBBI = RPOT.begin(), MBBE = RPOT.end(); MBBI != MBBE; ++MBBI) {
MachineBasicBlock *MBB = *MBBI;
// N.B: IncomingProcessed and IncomingCompleted were already updated while
// processing this block's predecessors.
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.
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<MachineBasicBlock *> &ToRevisit,
+ MachineBasicBlock *MBB, bool PrimaryPass);
bool visitInstr(MachineInstr *);
void processDefs(MachineInstr *, bool breakDependency, bool Kill);
void visitSoftInstr(MachineInstr*, unsigned mask);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31681.94129.patch
Type: text/x-patch
Size: 2776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/d9f7caab/attachment.bin>
More information about the llvm-commits
mailing list