56 static const size_t SkipLeafInstructions = 3;
90 auto MBBI = MBB.
begin();
105 BuildMI(MBB, MBBI, DL, TII->
get(X86::MOV64rm)).addDef(OffsetReg), X86::GS,
118 .addDef(FreeRegister),
146 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
159 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
186 BuildMI(MBB, MI, DL, TII->
get(X86::JNE_1)).addMBB(&TrapBB);
204 bool HasReturn =
false;
205 for (
auto &MBB : Fn) {
233 MCPhysReg LeafFuncRegister = X86::NoRegister;
234 if (!Fn.getFrameInfo().adjustsStack()) {
235 size_t InstructionCount = 0;
236 std::bitset<X86::NUM_TARGET_REGS> UsedRegs;
237 for (
auto &MBB : Fn) {
238 for (
auto &LiveIn : MBB.liveins())
239 UsedRegs.set(LiveIn.PhysReg);
240 for (
auto &
MI : MBB) {
241 if (!
MI.isDebugValue() && !
MI.isCFIInstruction() && !
MI.isLabel())
243 for (
auto &
Op :
MI.operands())
244 if (
Op.isReg() &&
Op.isDef())
245 UsedRegs.set(
Op.getReg());
249 if (InstructionCount <= SkipLeafInstructions)
252 std::bitset<X86::NUM_TARGET_REGS> CalleeSavedRegs;
253 const MCPhysReg *CSRegs = Fn.getRegInfo().getCalleeSavedRegs();
254 for (
size_t i = 0; CSRegs[i]; i++)
255 CalleeSavedRegs.set(CSRegs[i]);
258 for (
auto &
Reg : X86::GR64_NOSPRegClass.getRegisters()) {
261 if (CalleeSavedRegs.test(
Reg))
266 if ((Used = UsedRegs.test(*SR)))
270 LeafFuncRegister =
Reg;
276 const bool LeafFuncOptimization = LeafFuncRegister != X86::NoRegister;
277 if (LeafFuncOptimization)
279 for (
auto I = ++Fn.begin(),
E = Fn.end();
I !=
E; ++
I)
280 I->addLiveIn(LeafFuncRegister);
287 if (LeafFuncOptimization)
293 for (
auto &MBB : Fn) {
300 Trap = Fn.CreateMachineBasicBlock();
305 if (LeafFuncOptimization)
321 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)
This class represents lattice values for constants.
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.