28 #define DEBUG_TYPE "x86-indirect-branch-tracking" 32 cl::desc(
"Enable X86 indirect branch tracking pass."));
34 STATISTIC(NumEndBranchAdded,
"Number of ENDBR instructions added");
42 return "X86 Indirect Branch Tracking";
54 unsigned int EndbrOpcode = 0;
68 return new X86IndirectBranchTrackingPass();
71 bool X86IndirectBranchTrackingPass::addENDBR(
73 assert(
TII &&
"Target instruction info was not initialized");
74 assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
75 "Unexpected Endbr opcode");
79 if (I == MBB.
end() || I->getOpcode() != EndbrOpcode) {
99 bool X86IndirectBranchTrackingPass::runOnMachineFunction(
MachineFunction &MF) {
109 bool Changed =
false;
112 EndbrOpcode = SubTarget.
is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
120 auto MBB = MF.
begin();
121 Changed |= addENDBR(*MBB, MBB->
begin());
124 for (
auto &MBB : MF) {
128 Changed |= addENDBR(MBB, MBB.
begin());
134 Changed |= addENDBR(MBB, std::next(I));
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
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
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...
const GlobalValue * getGlobal() const
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...
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperand class - Representation of each machine instruction operand.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
static bool IsCallReturnTwice(llvm::MachineOperand &MOp)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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.