[PATCH] D46671: Use iteration instead of recursion in CFIInserter
Sanjoy Das via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 10 10:33:19 PDT 2018
sanjoy updated this revision to Diff 146153.
sanjoy added a comment.
- fix bug + test case
Repository:
rL LLVM
https://reviews.llvm.org/D46671
Files:
lib/CodeGen/CFIInstrInserter.cpp
test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir
Index: test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir
===================================================================
--- /dev/null
+++ test/CodeGen/X86/cfi-inserter-cfg-with-merge.mir
@@ -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
+...
Index: lib/CodeGen/CFIInstrInserter.cpp
===================================================================
--- lib/CodeGen/CFIInstrInserter.cpp
+++ lib/CodeGen/CFIInstrInserter.cpp
@@ -151,7 +151,6 @@
// information.
for (MachineBasicBlock &MBB : MF) {
if (MBBVector[MBB.getNumber()].Processed) continue;
- calculateOutgoingCFAInfo(MBBVector[MBB.getNumber()]);
updateSuccCFAInfo(MBBVector[MBB.getNumber()]);
}
}
@@ -222,14 +221,23 @@
}
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()];
+ SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
+ SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
+ Stack.push_back(Succ);
+ }
+ } while (!Stack.empty());
}
bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
@@ -282,17 +290,16 @@
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()
<< " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n";
- errs() << "Pred: " << Pred.MBB->getName()
+ errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
<< " 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";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46671.146153.patch
Type: text/x-patch
Size: 3251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180510/c87e6872/attachment.bin>
More information about the llvm-commits
mailing list