39 #define DEBUG_TYPE "x86-retpoline-thunks" 55 StringRef getPassName()
const override {
return "X86 Retpoline Thunks"; }
57 bool doInitialization(
Module &M)
override;
83 return new X86RetpolineThunks();
88 bool X86RetpolineThunks::doInitialization(
Module &M) {
89 InsertedThunks =
false;
98 TII = STI->getInstrInfo();
101 MMI = &getAnalysis<MachineModuleInfo>();
118 if ((!STI->useRetpolineIndirectCalls() &&
119 !STI->useRetpolineIndirectBranches()) ||
120 STI->useRetpolineExternalThunk())
128 createThunkFunction(M, R11ThunkName);
132 createThunkFunction(M,
Name);
133 InsertedThunks =
true;
140 "Should only have an r11 thunk on 64-bit targets");
152 populateThunk(MF, X86::R11);
198 "Created a thunk with an unexpected prefix!");
232 const unsigned MovOpc = Is64Bit ? X86::MOV64mr : X86::MOV32mr;
233 const unsigned SPReg = Is64Bit ? X86::RSP :
X86::ESP;
247 while (MF.
size() > 1)
256 const unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32;
257 const unsigned RetOpc = Is64Bit ? X86::RETQ : X86::RETL;
284 insertRegReturnAddrClobber(*CallTarget, Reg);
void setVisibility(VisibilityTypes V)
static const char EAXThunkName[]
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
static const char EDXThunkName[]
const MachineFunctionProperties & getProperties() const
Get the function properties.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
void setAlignment(unsigned Align)
Set alignment of the basic block.
AnalysisUsage & addRequired()
static const char ECXThunkName[]
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
LLVMContext & getContext() const
Get the global data context.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void setComdat(Comdat *C)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MCContext & getContext() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Same, but only replaced by something equivalent.
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static const char EDIThunkName[]
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This is an important class for using LLVM in a threaded context.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, unsigned Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset]...
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
const MachineBasicBlock & front() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
Module.h This file contains the declarations for the Module class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
MachineFunctionProperties & set(Property P)
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
FunctionPass * createX86RetpolineThunksPass()
This pass creates the thunks for the retpoline feature.
void erase(iterator MBBI)
void addAttributes(unsigned i, const AttrBuilder &Attrs)
adds the attributes to the list of attributes.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char R11ThunkName[]
void insert(iterator MBBI, MachineBasicBlock *MBB)
void push_back(MachineBasicBlock *MBB)
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
This class contains meta information specific to a module.
static const char ThunkNamePrefix[]