forked from OSchip/llvm-project
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 llvm-svn: 332101
This commit is contained in:
parent
6e1f7bf316
commit
82105e2a7d
|
@ -151,7 +151,6 @@ void CFIInstrInserter::calculateCFAInfo(MachineFunction &MF) {
|
||||||
// information.
|
// information.
|
||||||
for (MachineBasicBlock &MBB : MF) {
|
for (MachineBasicBlock &MBB : MF) {
|
||||||
if (MBBVector[MBB.getNumber()].Processed) continue;
|
if (MBBVector[MBB.getNumber()].Processed) continue;
|
||||||
calculateOutgoingCFAInfo(MBBVector[MBB.getNumber()]);
|
|
||||||
updateSuccCFAInfo(MBBVector[MBB.getNumber()]);
|
updateSuccCFAInfo(MBBVector[MBB.getNumber()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,14 +221,25 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
|
void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
|
||||||
for (MachineBasicBlock *Succ : MBBInfo.MBB->successors()) {
|
SmallVector<MachineBasicBlock *, 4> Stack;
|
||||||
MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
|
Stack.push_back(MBBInfo.MBB);
|
||||||
if (SuccInfo.Processed) continue;
|
|
||||||
SuccInfo.IncomingCFAOffset = MBBInfo.OutgoingCFAOffset;
|
do {
|
||||||
SuccInfo.IncomingCFARegister = MBBInfo.OutgoingCFARegister;
|
MachineBasicBlock *Current = Stack.pop_back_val();
|
||||||
calculateOutgoingCFAInfo(SuccInfo);
|
MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()];
|
||||||
updateSuccCFAInfo(SuccInfo);
|
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) {
|
bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
|
||||||
|
@ -282,17 +292,18 @@ bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
|
||||||
return InsertedCFIInstr;
|
return InsertedCFIInstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFIInstrInserter::report(const MBBCFAInfo &Pred,
|
void CFIInstrInserter::report(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ) {
|
||||||
const MBBCFAInfo &Succ) {
|
|
||||||
errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
|
errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
|
||||||
"***\n";
|
"***\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";
|
<< " 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";
|
<< " 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";
|
<< " 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";
|
<< " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
...
|
Loading…
Reference in New Issue