46#define DEBUG_TYPE "x86-retpoline-thunks"
62 return (STI.useRetpolineIndirectCalls() ||
63 STI.useRetpolineIndirectBranches()) &&
64 !STI.useRetpolineExternalThunk();
77 bool ExistingThunks) {
105class X86IndirectThunksLegacy
110 X86IndirectThunksLegacy() : ThunkInserterPass(ID) {}
112 StringRef getPassName()
const override {
return "X86 Indirect Thunks"; }
119 bool ExistingThunks) {
136 "Should only have an r11 thunk on 64-bit targets");
202 const unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32;
203 const unsigned RetOpc = Is64Bit ? X86::RET64 : X86::RET32;
205 Entry->addLiveIn(ThunkReg);
211 Entry->addSuccessor(CaptureSpec);
232 const unsigned MovOpc = Is64Bit ? X86::MOV64mr : X86::MOV32mr;
242 return new X86IndirectThunksLegacy();
245char X86IndirectThunksLegacy::ID = 0;
257 .getCachedResult<MachineModuleAnalysis>(
259 assert(MMI &&
"MachineModuleAnalysis must be available");
261 if (!RetpolineInserter || !LVIInserter) {
263 RetpolineInserter = std::make_unique<RetpolineThunkInserter>();
264 RetpolineInserter->init(M);
265 LVIInserter = std::make_unique<LVIThunkInserter>();
266 LVIInserter->init(M);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Contains a base ThunkInserter class that simplifies injection of MI thunks as well as a default imple...
static constexpr MCPhysReg SPReg
Target-Independent Code Generator Pass Configuration Options pass.
static const char ECXRetpolineName[]
static const char RetpolineNamePrefix[]
static const char EDIRetpolineName[]
static const char LVIThunkNamePrefix[]
static const char EDXRetpolineName[]
static const char EAXRetpolineName[]
static const char R11LVIThunkName[]
static const char R11RetpolineName[]
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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...
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setAlignment(Align A)
Set alignment of the basic block.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
void setMachineBlockAddressTaken()
Set this block to indicate that its address is used as something other than the target of a terminato...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void push_back(MachineBasicBlock *MBB)
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
LLVM_ABI void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
MachineModuleInfo & getMMI()
This class contains meta information specific to a module.
const TargetMachine & getTarget() const
A Module instance is used to store all the information related to an LLVM module.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
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.
Wrapper class representing virtual and physical registers.
Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
const Triple & getTargetTriple() const
Basic implementation of MachineFunctionPass wrapping one or more ThunkInserters passed as type parame...
This class assists in inserting MI thunk functions into the module and rewriting the existing machine...
void createThunkFunction(MachineModuleInfo &MMI, StringRef Name, bool Comdat=true, StringRef TargetAttrs="")
bool isX86_64() const
Tests whether the target is x86 (64-bit).
This pass creates the thunks for the retpoline feature.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
FunctionPass * createX86IndirectThunksLegacyPass()
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, Register Reg, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset],...
const char * getThunkPrefix()
void populateThunk(MachineFunction &MF)
bool insertThunks(MachineModuleInfo &MMI, MachineFunction &MF, bool ExistingThunks)
bool mayUseThunk(const MachineFunction &MF)
const char * getThunkPrefix()
bool insertThunks(MachineModuleInfo &MMI, MachineFunction &MF, bool ExistingThunks)
void populateThunk(MachineFunction &MF)
bool mayUseThunk(const MachineFunction &MF)
This struct is a compact representation of a valid (non-zero power of two) alignment.