LLVM 20.0.0git
|
This class assists in inserting MI thunk functions into the module and rewriting the existing machine functions to call these thunks. More...
#include "llvm/CodeGen/IndirectThunks.h"
Public Member Functions | |
void | init (Module &M) |
bool | run (MachineModuleInfo &MMI, MachineFunction &MF) |
Protected Member Functions | |
void | createThunkFunction (MachineModuleInfo &MMI, StringRef Name, bool Comdat=true, StringRef TargetAttrs="") |
Create an empty thunk function. | |
void | doInitialization (Module &M) |
Initializes thunk inserter. | |
const char * | getThunkPrefix () |
Returns common prefix for thunk function's names. | |
bool | mayUseThunk (const MachineFunction &MF) |
Checks if MF may use thunks (true - maybe, false - definitely not). | |
InsertedThunksTy | insertThunks (MachineModuleInfo &MMI, MachineFunction &MF, InsertedThunksTy ExistingThunks) |
Rewrites the function if necessary, returns the set of thunks added. | |
void | populateThunk (MachineFunction &MF) |
Populate the thunk function with instructions. | |
This class assists in inserting MI thunk functions into the module and rewriting the existing machine functions to call these thunks.
One of the common cases is implementing security mitigations that involve replacing some machine code patterns with calls to special thunk functions.
Inserting a module pass late in the codegen pipeline may increase memory usage, as it serializes the transformations and forces preceding passes to produce machine code for all functions before running the module pass. For that reason, ThunkInserter can be driven by a MachineFunctionPass by passing one MachineFunction at a time to its run(MMI, MF)
method. Then, the derived class should
Note that if some other pass is responsible for rewriting the functions, the insertThunks method may simply create all possible thunks at once, probably postponed until the first occurrence of possibly affected MF.
Alternatively, insertThunks method can rewrite MF by itself and only insert the thunks being called. In that case InsertedThunks variable can be used to track which thunks were already inserted.
In any case, the thunk function has to be inserted on behalf of some other function and then populated on its own "iteration" later - this is because MachineFunctionPass will see the newly created functions, but they first have to go through the preceding passes from the same pass manager, possibly even through the instruction selector.
Definition at line 61 of file IndirectThunks.h.
|
protected |
Create an empty thunk function.
The new function will eventually be passed to populateThunk. If multiple thunks are created, populateThunk can distinguish them by their names.
Definition at line 119 of file IndirectThunks.h.
References assert(), B, llvm::Function::Create(), llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateRetVoid(), F, llvm::FunctionType::get(), llvm::MachineModuleInfo::getModule(), llvm::MachineModuleInfo::getOrCreateMachineFunction(), llvm::MachineFunction::getProperties(), llvm::Type::getVoidTy(), llvm::GlobalValue::HiddenVisibility, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::LinkOnceODRLinkage, Name, llvm::MachineFunctionProperties::NoVRegs, and llvm::MachineFunctionProperties::set().
|
inlineprotected |
Initializes thunk inserter.
Definition at line 87 of file IndirectThunks.h.
|
protected |
Returns common prefix for thunk function's names.
|
inline |
Definition at line 110 of file IndirectThunks.h.
|
protected |
Rewrites the function if necessary, returns the set of thunks added.
|
protected |
Checks if MF may use thunks (true - maybe, false - definitely not).
|
protected |
Populate the thunk function with instructions.
If multiple thunks are created, the content that must be inserted in the thunk function body should be derived from the MF's name.
Depending on the preceding passes in the pass manager, by the time populateThunk is called, MF may have a few target-specific instructions (such as a single MBB containing the return instruction).
bool llvm::ThunkInserter< Derived, InsertedThunksTy >::run | ( | MachineModuleInfo & | MMI, |
MachineFunction & | MF | ||
) |
Definition at line 165 of file IndirectThunks.h.
References llvm::MachineFunction::getName(), and llvm::StringRef::starts_with().