30#define DEBUG_TYPE "x86-indirect-branch-tracking"
34 cl::desc(
"Enable X86 indirect branch tracking pass."));
36STATISTIC(NumEndBranchAdded,
"Number of ENDBR instructions added");
45 StringRef getPassName()
const override {
46 return "X86 Indirect Branch Tracking";
49 bool runOnMachineFunction(MachineFunction &MF)
override;
60 unsigned EndbrOpcode = SubTarget.is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
62 assert(
TII &&
"Target instruction info was not initialized");
63 assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
64 "Unexpected Endbr opcode");
68 if (
I ==
MBB.end() ||
I->getOpcode() != EndbrOpcode) {
78char X86IndirectBranchTrackingLegacy::ID = 0;
81 "X86 Indirect Branch Tracking",
false,
false)
84 return new X86IndirectBranchTrackingLegacy();
93 AttributeList Attrs = CalleeFn->getAttributes();
94 return Attrs.hasFnAttr(Attribute::ReturnsTwice);
101 if (
F.doesNoCfCheck())
110 return (
F.hasAddressTaken() || !
F.hasLocalLinkage());
117 Metadata *isCFProtectionSupported = M->getModuleFlag(
"cf-protection-branch");
124 bool isJITwithCET = TM->
isJIT();
126 bool isJITwithCET =
false;
140 for (
auto &
MBB : MF) {
143 if (
MBB.isMachineBlockAddressTaken() ||
MBB.isIRBlockAddressTaken())
147 if (
I->isCall() &&
I->getNumOperands() > 0 &&
160 if (
I->isDebugInstr())
164 }
else if (
I->isEHLabel()) {
167 MCSymbol *Sym =
I->getOperand(0).getMCSymbol();
174 }
else if (
MBB.isEHPad()){
186bool X86IndirectBranchTrackingLegacy::runOnMachineFunction(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool needsPrologueENDBR(MachineFunction &MF, const Module *M)
static bool IsCallReturnTwice(llvm::MachineOperand &MOp)
cl::opt< bool > IndirectBranchTracking("x86-indirect-branch-tracking", cl::init(false), cl::Hidden, cl::desc("Enable X86 indirect branch tracking pass."))
static bool runIndirectBranchTracking(MachineFunction &MF)
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
Module * getParent()
Get the module that this global value is contained inside of...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
bool hasCallSiteLandingPad(MCSymbol *Sym)
Return true if the landing pad Eh symbol has an associated call site.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
A Module instance is used to store all the information related to an LLVM module.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
CodeModel::Model getCodeModel() const
Returns the code model.
ExceptionHandling ExceptionModel
What exception model to use.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const X86InstrInfo * getInstrInfo() const override
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ SjLj
setjmp/longjmp based exceptions
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createX86IndirectBranchTrackingLegacyPass()