82#define DEBUG_TYPE "cfi-fixup"
87 "Insert CFI remember/restore state instructions",
false,
false)
91 return MI.getOpcode() == TargetOpcode::CFI_INSTRUCTION &&
97 return MI.getOpcode() == TargetOpcode::CFI_INSTRUCTION &&
112 PrologueEnd = std::next(
MI.getIterator());
132 if (PrologueBlock ==
nullptr)
137 bool StrongNoFrameOnEntry : 1;
138 bool HasFrameOnEntry : 1;
139 bool HasFrameOnExit : 1;
142 BlockInfo[0].Reachable =
true;
143 BlockInfo[0].StrongNoFrameOnEntry =
true;
152 bool HasPrologue =
MBB == PrologueBlock;
153 bool HasEpilogue =
false;
155 if (
Info.HasFrameOnEntry || HasPrologue)
161 Info.HasFrameOnExit = (
Info.HasFrameOnEntry || HasPrologue) && !HasEpilogue;
165 BlockFlags &SuccInfo = BlockInfo[Succ->getNumber()];
166 SuccInfo.Reachable =
true;
167 SuccInfo.StrongNoFrameOnEntry |=
168 Info.StrongNoFrameOnEntry && !HasPrologue;
169 SuccInfo.HasFrameOnEntry =
Info.HasFrameOnExit;
186 "Inconsistent notion of \"prologue block\"");
192 bool HasFrame = BlockInfo[PrologueBlock->
getNumber()].HasFrameOnExit;
193 while (CurrBB != MF.
end()) {
194 const BlockFlags &
Info = BlockInfo[CurrBB->getNumber()];
195 if (!
Info.Reachable) {
201 if (!
Info.StrongNoFrameOnEntry) {
202 for (
auto *Pred : CurrBB->predecessors()) {
203 BlockFlags &PredInfo = BlockInfo[Pred->getNumber()];
204 assert((!PredInfo.Reachable ||
205 Info.HasFrameOnEntry == PredInfo.HasFrameOnExit) &&
206 "Inconsistent call frame state");
210 if (!
Info.StrongNoFrameOnEntry &&
Info.HasFrameOnEntry && !HasFrame) {
218 TII.get(TargetOpcode::CFI_INSTRUCTION))
223 TII.get(TargetOpcode::CFI_INSTRUCTION))
226 InsertMBB = &*CurrBB;
228 }
else if ((
Info.StrongNoFrameOnEntry || !
Info.HasFrameOnEntry) &&
235 HasFrame =
Info.HasFrameOnExit;
static bool isPrologueCFIInstruction(const MachineInstr &MI)
static MachineBasicBlock * findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd)
static bool containsEpilogue(const MachineBasicBlock &MBB)
Contains definition of the base CFIFixup pass.
Analysis containing CSE Info
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the SmallBitVector class.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
FunctionPass class - This class is used to implement most global optimizations.
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
iterator_range< succ_iterator > successors()
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
Representation of each machine instruction.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Information about stack frame layout on the target.
virtual void resetCFIToInitialState(MachineBasicBlock &MBB) const
Emit CFI instructions that recreate the state of the unwind information upon fucntion entry.
virtual bool enableCFIFixup(MachineFunction &MF) const
Returns true if we may need to fix the unwind information for the function.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
FunctionPass * createCFIFixup()
Creates CFI Fixup pass.