43#define DEBUG_TYPE "x86-retpoline-thunks"
56struct RetpolineThunkInserter :
ThunkInserter<RetpolineThunkInserter> {
60 return (STI.useRetpolineIndirectCalls() ||
61 STI.useRetpolineIndirectBranches()) &&
62 !STI.useRetpolineExternalThunk();
75 bool ExistingThunks) {
101class X86IndirectThunks
108 StringRef getPassName()
const override {
return "X86 Indirect Thunks"; }
115 bool ExistingThunks) {
123 createThunkFunction(MMI, Name);
127void RetpolineThunkInserter::populateThunk(MachineFunction &MF) {
132 "Should only have an r11 thunk on 64-bit targets");
185 const TargetInstrInfo *
TII = MF.
getSubtarget<X86Subtarget>().getInstrInfo();
190 MachineBasicBlock *CaptureSpec =
192 MachineBasicBlock *CallTarget =
198 const unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32;
199 const unsigned RetOpc = Is64Bit ? X86::RET64 : X86::RET32;
201 Entry->addLiveIn(ThunkReg);
207 Entry->addSuccessor(CaptureSpec);
228 const unsigned MovOpc = Is64Bit ? X86::MOV64mr : X86::MOV32mr;
239 return new X86IndirectThunks();
242char X86IndirectThunks::ID = 0;
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...
Promote Memory to Register
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[]
FunctionPass class - This class is used to implement most global optimizations.
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
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
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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.
This class contains meta information specific to a module.
const TargetMachine & getTarget() const
StringRef - 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...
ArchType getArch() const
Get the parsed architecture type of this triple.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
FunctionPass * createX86IndirectThunksPass()
This pass creates the thunks for the retpoline feature.
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, Register Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset],...