[PATCH] D126930: Fix interaction of CFI with MachineOutliner.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 15:50:38 PDT 2022
efriedma created this revision.
efriedma added reviewers: paquette, AndrewLitteken, smeenai.
Herald added subscribers: jsji, pengfei, hiraditya.
Herald added a project: All.
efriedma requested review of this revision.
Herald added a project: LLVM.
1. When checking if a candidate contains a CFI instruction, actually iterate over all of the instrucitons, instead of stopping halfway through.
2. Don't emit bogus CFI directives into outlined functions. To get correct unwind info for asynchronous unwind, we need to emit the prologue, and we need to correctly clone the epilogue CFI directives.
Fixes https://github.com/llvm/llvm-project/issues/55842
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126930
Files:
llvm/lib/CodeGen/MachineOutliner.cpp
llvm/lib/CodeGen/MachineVerifier.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/lib/Target/X86/X86InstrInfo.cpp
Index: llvm/lib/Target/X86/X86InstrInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86InstrInfo.cpp
+++ llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -9488,12 +9488,10 @@
// We check to see if CFI Instructions are present, and if they are
// we find the number of CFI Instructions in the candidates.
unsigned CFICount = 0;
- MachineBasicBlock::iterator MBBI = RepeatedSequenceLocs[0].front();
- for (unsigned Loc = RepeatedSequenceLocs[0].getStartIdx();
- Loc < RepeatedSequenceLocs[0].getEndIdx() + 1; Loc++) {
- if (MBBI->isCFIInstruction())
+ for (auto &I : make_range(RepeatedSequenceLocs[0].front(),
+ std::next(RepeatedSequenceLocs[0].back()))) {
+ if (I.isCFIInstruction())
CFICount++;
- MBBI++;
}
// We compare the number of found CFI Instructions to the number of CFI
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -7014,12 +7014,10 @@
// We check to see if CFI Instructions are present, and if they are
// we find the number of CFI Instructions in the candidates.
unsigned CFICount = 0;
- MachineBasicBlock::iterator MBBI = RepeatedSequenceLocs[0].front();
- for (unsigned Loc = RepeatedSequenceLocs[0].getStartIdx();
- Loc < RepeatedSequenceLocs[0].getEndIdx() + 1; Loc++) {
- if (MBBI->isCFIInstruction())
+ for (auto &I : make_range(RepeatedSequenceLocs[0].front(),
+ std::next(RepeatedSequenceLocs[0].back()))) {
+ if (I.isCFIInstruction())
CFICount++;
- MBBI++;
}
// We compare the number of found CFI Instructions to the number of CFI
Index: llvm/lib/CodeGen/MachineVerifier.cpp
===================================================================
--- llvm/lib/CodeGen/MachineVerifier.cpp
+++ llvm/lib/CodeGen/MachineVerifier.cpp
@@ -64,6 +64,7 @@
#include "llvm/InitializePasses.h"
#include "llvm/MC/LaneBitmask.h"
#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCTargetOptions.h"
@@ -2212,6 +2213,11 @@
}
break;
+ case MachineOperand::MO_CFIIndex:
+ if (MO->getCFIIndex() >= MF->getFrameInstructions().size())
+ report("CFI instruction has invalid index", MO, MONum);
+ break;
+
default:
break;
}
Index: llvm/lib/CodeGen/MachineOutliner.cpp
===================================================================
--- llvm/lib/CodeGen/MachineOutliner.cpp
+++ llvm/lib/CodeGen/MachineOutliner.cpp
@@ -658,19 +658,14 @@
// Insert the new function into the module.
MF.insert(MF.begin(), &MBB);
- MachineFunction *OriginalMF = FirstCand.front()->getMF();
- const std::vector<MCCFIInstruction> &Instrs =
- OriginalMF->getFrameInstructions();
for (auto I = FirstCand.front(), E = std::next(FirstCand.back()); I != E;
++I) {
if (I->isDebugInstr())
continue;
+ // FIXME: Try to emit correct CFI for asynchronous unwind.
+ if (I->isCFIInstruction())
+ continue;
MachineInstr *NewMI = MF.CloneMachineInstr(&*I);
- if (I->isCFIInstruction()) {
- unsigned CFIIndex = NewMI->getOperand(0).getCFIIndex();
- MCCFIInstruction CFI = Instrs[CFIIndex];
- (void)MF.addFrameInst(CFI);
- }
NewMI->dropMemRefs(MF);
// Don't keep debug information for outlined instructions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126930.433910.patch
Type: text/x-patch
Size: 3553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/a740b135/attachment.bin>
More information about the llvm-commits
mailing list