[llvm] r332101 - Use iteration instead of recursion in CFIInserter
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri May 11 08:54:46 PDT 2018
Author: sanjoy
Date: Fri May 11 08:54:46 2018
New Revision: 332101
URL: http://llvm.org/viewvc/llvm-project?rev=332101&view=rev
Log:
Use iteration instead of recursion in CFIInserter
Summary: This recursive step can overflow the stack.
Reviewers: djokov, petarj
Subscribers: mcrosier, jlebar, bixia, llvm-commits
Differential Revision: https://reviews.llvm.org/D46671
Added:
llvm/trunk/test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir
Modified:
llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp
Modified: llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp?rev=332101&r1=332100&r2=332101&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp Fri May 11 08:54:46 2018
@@ -151,7 +151,6 @@ void CFIInstrInserter::calculateCFAInfo(
// information.
for (MachineBasicBlock &MBB : MF) {
if (MBBVector[MBB.getNumber()].Processed) continue;
- calculateOutgoingCFAInfo(MBBVector[MBB.getNumber()]);
updateSuccCFAInfo(MBBVector[MBB.getNumber()]);
}
}
@@ -222,14 +221,25 @@ void CFIInstrInserter::calculateOutgoing
}
void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
- for (MachineBasicBlock *Succ : MBBInfo.MBB->successors()) {
- MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
- if (SuccInfo.Processed) continue;
- SuccInfo.IncomingCFAOffset = MBBInfo.OutgoingCFAOffset;
- SuccInfo.IncomingCFARegister = MBBInfo.OutgoingCFARegister;
- calculateOutgoingCFAInfo(SuccInfo);
- updateSuccCFAInfo(SuccInfo);
- }
+ SmallVector<MachineBasicBlock *, 4> Stack;
+ Stack.push_back(MBBInfo.MBB);
+
+ do {
+ MachineBasicBlock *Current = Stack.pop_back_val();
+ MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()];
+ if (CurrentInfo.Processed)
+ continue;
+
+ calculateOutgoingCFAInfo(CurrentInfo);
+ for (auto *Succ : CurrentInfo.MBB->successors()) {
+ MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
+ if (!SuccInfo.Processed) {
+ SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
+ SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
+ Stack.push_back(Succ);
+ }
+ }
+ } while (!Stack.empty());
}
bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
@@ -282,17 +292,18 @@ bool CFIInstrInserter::insertCFIInstrs(M
return InsertedCFIInstr;
}
-void CFIInstrInserter::report(const MBBCFAInfo &Pred,
- const MBBCFAInfo &Succ) {
+void CFIInstrInserter::report(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ) {
errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
"***\n";
- errs() << "Pred: " << Pred.MBB->getName()
+ errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
+ << " in " << Pred.MBB->getParent()->getName()
<< " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n";
- errs() << "Pred: " << Pred.MBB->getName()
+ errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
+ << " in " << Pred.MBB->getParent()->getName()
<< " outgoing CFA Offset:" << Pred.OutgoingCFAOffset << "\n";
- errs() << "Succ: " << Succ.MBB->getName()
+ errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
<< " incoming CFA Reg:" << Succ.IncomingCFARegister << "\n";
- errs() << "Succ: " << Succ.MBB->getName()
+ errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
<< " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n";
}
Added: llvm/trunk/test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir?rev=332101&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir (added)
+++ llvm/trunk/test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir Fri May 11 08:54:46 2018
@@ -0,0 +1,17 @@
+# RUN: llc -o - %s -mtriple=x86_64-- -verify-cfiinstrs -run-pass=cfi-instr-inserter
+
+--- |
+ define void @foo() { ret void }
+...
+---
+name: foo
+body: |
+ bb.0:
+ JE_1 %bb.3, implicit $eflags
+ bb.1:
+ CFI_INSTRUCTION def_cfa_offset 24
+ bb.2:
+ CFI_INSTRUCTION def_cfa_offset 8
+ bb.3:
+ RET 0
+...
More information about the llvm-commits
mailing list