60 static const size_t SkipLeafInstructions = 3;
94 auto MBBI = MBB.
begin();
109 BuildMI(MBB, MBBI, DL, TII->
get(X86::MOV64rm)).addDef(OffsetReg), X86::GS,
122 .addDef(FreeRegister),
150 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
163 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
190 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
208 bool HasReturn =
false;
209 for (
auto &MBB : Fn) {
237 MCPhysReg LeafFuncRegister = X86::NoRegister;
238 if (!Fn.getFrameInfo().adjustsStack()) {
239 size_t InstructionCount = 0;
240 std::bitset<X86::NUM_TARGET_REGS> UsedRegs;
241 for (
auto &MBB : Fn) {
242 for (
auto &LiveIn : MBB.liveins())
243 UsedRegs.set(LiveIn.PhysReg);
244 for (
auto &
MI : MBB) {
245 if (!
MI.isDebugValue() && !
MI.isCFIInstruction() && !
MI.isLabel())
247 for (
auto &
Op :
MI.operands())
248 if (
Op.isReg() &&
Op.isDef())
249 UsedRegs.set(
Op.getReg());
253 if (InstructionCount <= SkipLeafInstructions)
256 std::bitset<X86::NUM_TARGET_REGS> CalleeSavedRegs;
257 const MCPhysReg *CSRegs = Fn.getRegInfo().getCalleeSavedRegs();
258 for (
size_t i = 0; CSRegs[i]; i++)
259 CalleeSavedRegs.set(CSRegs[i]);
262 for (
auto &
Reg : X86::GR64_NOSPRegClass.getRegisters()) {
265 if (CalleeSavedRegs.test(
Reg))
270 if ((Used = UsedRegs.test(*SR)))
274 LeafFuncRegister =
Reg;
280 const bool LeafFuncOptimization = LeafFuncRegister != X86::NoRegister;
281 if (LeafFuncOptimization)
283 for (
auto I = ++Fn.begin(),
E = Fn.end();
I !=
E; ++
I)
284 I->addLiveIn(LeafFuncRegister);
291 if (LeafFuncOptimization)
297 for (
auto &MBB : Fn) {
304 Trap = Fn.CreateMachineBasicBlock();
309 if (LeafFuncOptimization)
325 return new ShadowCallStack();
bool hasRegisterImplicitUseOperand(unsigned Reg) const
Returns true if the MachineInstr has an implicit-use operand of exactly the given register (not consi...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isCall(QueryType Type=AnyInBundle) const
static void addProlog(MachineFunction &Fn, const TargetInstrInfo *TII, MachineBasicBlock &MBB, const DebugLoc &DL)
Compute iterated dominance frontiers using a linear time algorithm.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
MachineOperand * findRegisterUseOperand(unsigned Reg, bool isKill=false, const TargetRegisterInfo *TRI=nullptr)
Wrapper for findRegisterUseOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
MachineInstr & instr_back()
static const MachineInstrBuilder & addSegmentedMem(const MachineInstrBuilder &MIB, MCPhysReg Seg, MCPhysReg Reg, int Offset=0)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
unsigned const TargetRegisterInfo * TRI
static void addEpilogLeaf(const TargetInstrInfo *TII, MachineBasicBlock &MBB, MachineInstr &MI, MachineBasicBlock &TrapBB, MCPhysReg FreeRegister)
FunctionPass * createShadowCallStackPass()
This pass instruments the function prolog to save the return address to a 'shadow call stack' and the...
INITIALIZE_PASS(ShadowCallStack, "shadow-call-stack", "Shadow Call Stack", false, false) FunctionPass *llvm
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
MachineBasicBlock * getFallThrough()
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
bool isReturn(QueryType Type=AnyInBundle) const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
TRAP - Trapping instruction.
FunctionPass class - This class is used to implement most global optimizations.
static void addEpilog(const TargetInstrInfo *TII, MachineBasicBlock &MBB, MachineInstr &MI, MachineBasicBlock &TrapBB)
static void addPrologLeaf(MachineFunction &Fn, const TargetInstrInfo *TII, MachineBasicBlock &MBB, const DebugLoc &DL, MCPhysReg FreeRegister)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
MCSubRegIterator enumerates all sub-registers of Reg.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
Representation of each machine instruction.
static const MachineInstrBuilder & addDirectMem(const MachineInstrBuilder &MIB, unsigned Reg)
addDirectMem - This function is used to add a direct memory reference to the current instruction – t...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static void addEpilogOnlyR10(const TargetInstrInfo *TII, MachineBasicBlock &MBB, MachineInstr &MI, MachineBasicBlock &TrapBB)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
void initializeShadowCallStackPass(PassRegistry &)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...