[PATCH] D111151: [CodeGen][Outliner] Fix CFICount calculations
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 5 07:00:13 PDT 2021
alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: AndrewLitteken, paquette, thegameg.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added subscribers: pengfei, hiraditya, kristof.beyls.
alexander-shaposhnikov requested review of this revision.
Herald added a project: LLVM.
getFrameInstructions returns a vector cfi instructions in the function's prologue, not in the entire function, see e.g.
https://llvm.org/doxygen/MachineFunction_8h_source.html#l01006
This diff introduces a helper method getCFIInstructionCount and adjusts the calculations in X86InstrInfo / AArch64InstrInfo accordingly.
Test plan: make check-all
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111151
Files:
llvm/include/llvm/CodeGen/MachineFunction.h
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
@@ -9127,13 +9127,8 @@
MachineBasicBlock::iterator MBBI = RepeatedSequenceLocs[0].front();
for (unsigned Loc = RepeatedSequenceLocs[0].getStartIdx();
Loc < RepeatedSequenceLocs[0].getEndIdx() + 1; Loc++) {
- const std::vector<MCCFIInstruction> &CFIInstructions =
- RepeatedSequenceLocs[0].getMF()->getFrameInstructions();
- if (MBBI->isCFIInstruction()) {
- unsigned CFIIndex = MBBI->getOperand(0).getCFIIndex();
- MCCFIInstruction CFI = CFIInstructions[CFIIndex];
+ if (MBBI->isCFIInstruction())
CFICount++;
- }
MBBI++;
}
@@ -9142,13 +9137,11 @@
// since if we outline one of the CFI instructions in a function, we have to
// outline them all for correctness. If we do not, the address offsets will be
// incorrect between the two sections of the program.
- for (outliner::Candidate &C : RepeatedSequenceLocs) {
- std::vector<MCCFIInstruction> CFIInstructions =
- C.getMF()->getFrameInstructions();
-
- if (CFICount > 0 && CFICount != CFIInstructions.size())
- return outliner::OutlinedFunction();
- }
+ if (CFICount > 0 &&
+ any_of(RepeatedSequenceLocs, [CFICount](const outliner::Candidate &C) {
+ return C.getMF()->getCFIInstructionCount() != CFICount;
+ }))
+ return outliner::OutlinedFunction();
// FIXME: Use real size in bytes for call and ret instructions.
if (RepeatedSequenceLocs[0].back()->isTerminator()) {
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -6573,13 +6573,8 @@
MachineBasicBlock::iterator MBBI = RepeatedSequenceLocs[0].front();
for (unsigned Loc = RepeatedSequenceLocs[0].getStartIdx();
Loc < RepeatedSequenceLocs[0].getEndIdx() + 1; Loc++) {
- const std::vector<MCCFIInstruction> &CFIInstructions =
- RepeatedSequenceLocs[0].getMF()->getFrameInstructions();
- if (MBBI->isCFIInstruction()) {
- unsigned CFIIndex = MBBI->getOperand(0).getCFIIndex();
- MCCFIInstruction CFI = CFIInstructions[CFIIndex];
+ if (MBBI->isCFIInstruction())
CFICount++;
- }
MBBI++;
}
@@ -6588,13 +6583,11 @@
// since if we outline one of the CFI instructions in a function, we have to
// outline them all for correctness. If we do not, the address offsets will be
// incorrect between the two sections of the program.
- for (outliner::Candidate &C : RepeatedSequenceLocs) {
- std::vector<MCCFIInstruction> CFIInstructions =
- C.getMF()->getFrameInstructions();
-
- if (CFICount > 0 && CFICount != CFIInstructions.size())
- return outliner::OutlinedFunction();
- }
+ if (CFICount > 0 &&
+ any_of(RepeatedSequenceLocs, [CFICount](const outliner::Candidate &C) {
+ return C.getMF()->getCFIInstructionCount() != CFICount;
+ }))
+ return outliner::OutlinedFunction();
// Returns true if an instructions is safe to fix up, false otherwise.
auto IsSafeToFixup = [this, &TRI](MachineInstr &MI) {
Index: llvm/include/llvm/CodeGen/MachineFunction.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineFunction.h
+++ llvm/include/llvm/CodeGen/MachineFunction.h
@@ -855,6 +855,16 @@
return InstrCount;
}
+ /// Return the number of CFI \p MachineInstrs in this \p MachineFunction.
+ unsigned getCFIInstructionCount() const {
+ unsigned CFIInstrCount = 0;
+ for (const MachineBasicBlock &MBB : BasicBlocks)
+ CFIInstrCount += count_if(MBB, [](const MachineInstr &MI) {
+ return MI.isCFIInstruction();
+ });
+ return CFIInstrCount;
+ }
+
//===--------------------------------------------------------------------===//
// Internal functions used to automatically number MachineBasicBlocks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111151.377202.patch
Type: text/x-patch
Size: 4079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211005/451e16a3/attachment.bin>
More information about the llvm-commits
mailing list