16#ifndef LLVM_CODEGEN_INDIRECTTHUNKS_H
17#define LLVM_CODEGEN_INDIRECTTHUNKS_H
60template <
typename Derived,
typename InsertedThunksTy =
bool>
62 Derived &getDerived() {
return *
static_cast<Derived *
>(
this); }
68 InsertedThunksTy InsertedThunks;
97 InsertedThunksTy ExistingThunks);
111 InsertedThunks = InsertedThunksTy{};
112 getDerived().doInitialization(M);
118template <
typename Derived,
typename InsertedThunksTy>
122 assert(
Name.starts_with(getDerived().getThunkPrefix()) &&
123 "Created a thunk with an unexpected prefix!");
134 F->setComdat(M.getOrInsertComdat(
Name));
140 B.addAttribute(llvm::Attribute::NoUnwind);
141 B.addAttribute(llvm::Attribute::Naked);
142 if (TargetAttrs !=
"")
143 B.addAttribute(
"target-features", TargetAttrs);
164template <
typename Derived,
typename InsertedThunksTy>
170 if (!getDerived().mayUseThunk(MF))
177 InsertedThunks |= getDerived().insertThunks(MMI, MF, InsertedThunks);
182 getDerived().populateThunk(MF);
188template <
typename... Inserters>
191 std::tuple<Inserters...>
TIs;
202 auto &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
203 return runTIs(MMI, MF,
TIs);
207 template <
typename... ThunkInserterT>
208 static void initTIs(
Module &M,
209 std::tuple<ThunkInserterT...> &ThunkInserters) {
210 (..., std::get<ThunkInserterT>(ThunkInserters).init(M));
213 template <
typename... ThunkInserterT>
214 static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
215 std::tuple<ThunkInserterT...> &ThunkInserters) {
216 return (0 | ... | std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF));
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ HiddenVisibility
The GV is hidden.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This is an important class for using LLVM in a threaded context.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
MachineFunctionProperties & set(Property P)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const MachineFunctionProperties & getProperties() const
Get the function properties.
This class contains meta information specific to a module.
const Module * getModule() const
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
A Module instance is used to store all the information related to an LLVM module.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Basic implementation of MachineFunctionPass wrapping one or more ThunkInserters passed as type parame...
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
std::tuple< Inserters... > TIs
ThunkInserterPass(char &ID)
This class assists in inserting MI thunk functions into the module and rewriting the existing machine...
bool mayUseThunk(const MachineFunction &MF)
Checks if MF may use thunks (true - maybe, false - definitely not).
void createThunkFunction(MachineModuleInfo &MMI, StringRef Name, bool Comdat=true, StringRef TargetAttrs="")
Create an empty thunk function.
InsertedThunksTy insertThunks(MachineModuleInfo &MMI, MachineFunction &MF, InsertedThunksTy ExistingThunks)
Rewrites the function if necessary, returns the set of thunks added.
bool run(MachineModuleInfo &MMI, MachineFunction &MF)
void doInitialization(Module &M)
Initializes thunk inserter.
const char * getThunkPrefix()
Returns common prefix for thunk function's names.
void populateThunk(MachineFunction &MF)
Populate the thunk function with instructions.
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getVoidTy(LLVMContext &C)
This is an optimization pass for GlobalISel generic memory operations.