[llvm] r299569 - [ExecutionDepsFix] Don't recurse over the CFG
Keno Fischer via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 10:42:56 PDT 2017
Author: kfischer
Date: Wed Apr 5 12:42:56 2017
New Revision: 299569
URL: http://llvm.org/viewvc/llvm-project?rev=299569&view=rev
Log:
[ExecutionDepsFix] Don't recurse over the CFG
Summary:
Use an explicit work queue instead, to avoid accidentally
causing stack overflows for input with very large CFGs.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D31681
Modified:
llvm/trunk/include/llvm/CodeGen/ExecutionDepsFix.h
llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp
Modified: llvm/trunk/include/llvm/CodeGen/ExecutionDepsFix.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ExecutionDepsFix.h?rev=299569&r1=299568&r2=299569&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/ExecutionDepsFix.h (original)
+++ llvm/trunk/include/llvm/CodeGen/ExecutionDepsFix.h Wed Apr 5 12:42:56 2017
@@ -205,7 +205,6 @@ private:
void leaveBasicBlock(MachineBasicBlock*);
bool isBlockDone(MachineBasicBlock *);
void processBasicBlock(MachineBasicBlock *MBB, bool PrimaryPass);
- void updateSuccessors(MachineBasicBlock *MBB, bool PrimaryPass);
bool visitInstr(MachineInstr *);
void processDefs(MachineInstr *, bool breakDependency, bool Kill);
void visitSoftInstr(MachineInstr*, unsigned mask);
Modified: llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp?rev=299569&r1=299568&r2=299569&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp (original)
+++ llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp Wed Apr 5 12:42:56 2017
@@ -616,26 +616,6 @@ bool ExecutionDepsFix::isBlockDone(Machi
MBBInfos[MBB].IncomingProcessed == MBB->pred_size();
}
-void ExecutionDepsFix::updateSuccessors(MachineBasicBlock *MBB, bool Primary) {
- bool Done = isBlockDone(MBB);
- for (auto *Succ : MBB->successors()) {
- if (!isBlockDone(Succ)) {
- if (Primary) {
- MBBInfos[Succ].IncomingProcessed++;
- }
- if (Done) {
- 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);
- }
- }
- }
-}
-
bool ExecutionDepsFix::runOnMachineFunction(MachineFunction &mf) {
if (skipFunction(*mf.getFunction()))
return false;
@@ -708,6 +688,7 @@ bool ExecutionDepsFix::runOnMachineFunct
MachineBasicBlock *Entry = &*MF->begin();
ReversePostOrderTraversal<MachineBasicBlock*> RPOT(Entry);
+ SmallVector<MachineBasicBlock *, 4> Workqueue;
for (ReversePostOrderTraversal<MachineBasicBlock*>::rpo_iterator
MBBI = RPOT.begin(), MBBE = RPOT.end(); MBBI != MBBE; ++MBBI) {
MachineBasicBlock *MBB = *MBBI;
@@ -715,8 +696,28 @@ bool ExecutionDepsFix::runOnMachineFunct
// processing this block's predecessors.
MBBInfos[MBB].PrimaryCompleted = true;
MBBInfos[MBB].PrimaryIncoming = MBBInfos[MBB].IncomingProcessed;
- processBasicBlock(MBB, true);
- updateSuccessors(MBB, true);
+ bool Primary = true;
+ Workqueue.push_back(MBB);
+ while (!Workqueue.empty()) {
+ MachineBasicBlock *ActiveMBB = &*Workqueue.back();
+ Workqueue.pop_back();
+ processBasicBlock(ActiveMBB, Primary);
+ bool Done = isBlockDone(ActiveMBB);
+ for (auto *Succ : ActiveMBB->successors()) {
+ if (!isBlockDone(Succ)) {
+ if (Primary) {
+ MBBInfos[Succ].IncomingProcessed++;
+ }
+ if (Done) {
+ MBBInfos[Succ].IncomingCompleted++;
+ }
+ if (isBlockDone(Succ)) {
+ Workqueue.push_back(Succ);
+ }
+ }
+ }
+ Primary = false;
+ }
}
// We need to go through again and finalize any blocks that are not done yet.
More information about the llvm-commits
mailing list