29#define DEBUG_TYPE "kcfi"
30#define KCFI_PASS_NAME "Insert KCFI indirect call checks"
32STATISTIC(NumKCFIChecksAdded,
"Number of indirect call checks added");
56 MachineKCFILegacy() : MachineFunctionPass(ID) {}
59 bool runOnMachineFunction(MachineFunction &MF)
override {
60 return KCFI().run(MF);
64char MachineKCFILegacy::ID = 0;
83 assert(
TII &&
"Target instruction info was not initialized");
84 assert(TLI &&
"Target lowering was not initialized");
88 if (
MBBI->isBundled() && !std::prev(
MBBI)->isBundle())
96 assert(
MBBI->isCall() &&
"Unexpected instruction type");
97 MBBI->setCFIType(*
MBB.getParent(), 0);
101 if (!
MBBI->isBundled())
104 ++NumKCFIChecksAdded;
110 if (!M->getModuleFlag(
"kcfi"))
114 TII = SubTarget.getInstrInfo();
115 TLI = SubTarget.getTargetLowering();
121 MIE =
MBB.instr_end();
123 if (MII->isCall() && MII->getCFIType())
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains the declaration of the MachineKCFI class, which is a Machine Pass that implements ...
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)
This file describes how to lower LLVM code to machine code.
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...
Instructions::iterator instr_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.
Representation of each machine instruction.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI FunctionPass * createKCFIPass()
Lowers KCFI operand bundles for indirect calls.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)