29 #define DEBUG_TYPE "x86-indirect-branch-tracking" 33 cl::desc(
"Enable X86 indirect branch tracking pass."));
35 STATISTIC(NumEndBranchAdded,
"Number of ENDBR instructions added");
43 return "X86 Indirect Branch Tracking";
55 unsigned int EndbrOpcode;
69 return new X86IndirectBranchTrackingPass();
73 assert(
TII &&
"Target instruction info was not initialized");
74 assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
75 "Unexpected Endbr opcode");
80 if (
MI == MBB.
end() || EndbrOpcode !=
MI->getOpcode()) {
89 bool X86IndirectBranchTrackingPass::runOnMachineFunction(
MachineFunction &MF) {
102 EndbrOpcode = SubTarget.
is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
110 auto MBB = MF.
begin();
111 Changed |= addENDBR(*MBB);
118 Changed |= addENDBR(MBB);
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
bool hasLocalLinkage() const
This class represents lattice values for constants.
const X86InstrInfo * getInstrInfo() const override
STATISTIC(NumFunctions, "Total number of functions")
MachineModuleInfo & getMMI() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
static cl::opt< bool > IndirectBranchTracking("x86-indirect-branch-tracking", cl::init(false), cl::Hidden, cl::desc("Enable X86 indirect branch tracking pass."))
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
FunctionPass class - This class is used to implement most global optimizations.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
FunctionPass * createX86IndirectBranchTrackingPass()
This pass inserts ENDBR instructions before indirect jump/call destinations as part of CET IBT mechan...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const Module * getModule() const
bool hasAddressTaken(const User **=nullptr) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
bool doesNoCfCheck() const
Determine if the function should not perform indirect branch tracking.