summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineOutliner.cpp
diff options
context:
space:
mode:
authorEli Friedman <efriedma@quicinc.com>2022-06-10 13:37:49 -0700
committerEli Friedman <efriedma@quicinc.com>2022-06-10 13:37:49 -0700
commit0ff51d5dde29dfd9bc5064e32d47345bab7a5034 (patch)
tree6b903bacab5025406aaad1a4704d40095456cbde /llvm/lib/CodeGen/MachineOutliner.cpp
parentfbaa8b9ae5f3c6637be7d4dae6adaab4be811625 (diff)
Fix interaction of CFI instructions with MachineOutliner.
1. When checking if a candidate contains a CFI instruction, actually iterate over all of the instructions, instead of stopping halfway through. 2. Make sure copied CFI directives refer to the correct instruction. Fixes https://github.com/llvm/llvm-project/issues/55842 Differential Revision: https://reviews.llvm.org/D126930
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineOutliner.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 7ab69968b607..5da68abc8f6a 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -665,17 +665,20 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
++I) {
if (I->isDebugInstr())
continue;
- MachineInstr *NewMI = MF.CloneMachineInstr(&*I);
+
+ // Don't keep debug information for outlined instructions.
+ auto DL = DebugLoc();
if (I->isCFIInstruction()) {
- unsigned CFIIndex = NewMI->getOperand(0).getCFIIndex();
+ unsigned CFIIndex = I->getOperand(0).getCFIIndex();
MCCFIInstruction CFI = Instrs[CFIIndex];
- (void)MF.addFrameInst(CFI);
+ BuildMI(MBB, MBB.end(), DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
+ .addCFIIndex(MF.addFrameInst(CFI));
+ } else {
+ MachineInstr *NewMI = MF.CloneMachineInstr(&*I);
+ NewMI->dropMemRefs(MF);
+ NewMI->setDebugLoc(DL);
+ MBB.insert(MBB.end(), NewMI);
}
- NewMI->dropMemRefs(MF);
-
- // Don't keep debug information for outlined instructions.
- NewMI->setDebugLoc(DebugLoc());
- MBB.insert(MBB.end(), NewMI);
}
// Set normal properties for a late MachineFunction.