30#define DEBUG_TYPE "x86-indirect-branch-tracking"
32STATISTIC(NumEndBranchAdded,
"Number of ENDBR instructions added");
41 StringRef getPassName()
const override {
42 return "X86 Indirect Branch Tracking";
56 unsigned EndbrOpcode = SubTarget.is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
58 assert(
TII &&
"Target instruction info was not initialized");
59 assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
60 "Unexpected Endbr opcode");
64 if (
I ==
MBB.end() ||
I->getOpcode() != EndbrOpcode) {
74char X86IndirectBranchTrackingLegacy::ID = 0;
77 "X86 Indirect Branch Tracking",
false,
false)
80 return new X86IndirectBranchTrackingLegacy();
90 return Attrs.hasFnAttr(Attribute::ReturnsTwice);
97 if (
F.doesNoCfCheck())
106 return (
F.hasAddressTaken() || !
F.hasLocalLinkage());
113 Metadata *isCFProtectionSupported = M->getModuleFlag(
"cf-protection-branch");
120 bool isJITwithCET = TM->
isJIT();
122 bool isJITwithCET =
false;
124 if (!isCFProtectionSupported && !TM->
getCLOpts().indirect_branch_tracking &&
137 for (
auto &
MBB : MF) {
140 if (
MBB.isMachineBlockAddressTaken() ||
MBB.isIRBlockAddressTaken())
144 if (
I->isCall() &&
I->getNumOperands() > 0 &&
157 if (
I->isDebugInstr())
161 }
else if (
I->isEHLabel()) {
164 MCSymbol *Sym =
I->getOperand(0).getMCSymbol();
171 }
else if (
MBB.isEHPad()){
183bool 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)
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
const X86Options & getCLOpts() const
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createX86IndirectBranchTrackingLegacyPass()
@ SjLj
setjmp/longjmp based exceptions