Go to the documentation of this file.
28 CompileFunction Compile)
36 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
49 CompileFunction Compile;
58 void IndirectStubsManager::anchor() {}
62 if (
auto TrampolineAddr = TP->getTrampoline()) {
66 std::lock_guard<std::mutex>
Lock(CCMgrMutex);
67 AddrToSymbol[*TrampolineAddr] = CallbackName;
69 CallbacksJD.define(std::make_unique<CompileCallbackMaterializationUnit>(
71 return *TrampolineAddr;
73 return TrampolineAddr.takeError();
81 std::unique_lock<std::mutex>
Lock(CCMgrMutex);
82 auto I = AddrToSymbol.find(TrampolineAddr);
87 if (
I == AddrToSymbol.end()) {
92 ErrMsgStream <<
"No compile callback for trampoline at "
93 <<
format(
"0x%016" PRIx64, TrampolineAddr);
97 return ErrorHandlerAddress;
106 return Sym->getAddress();
111 ES.reportError(Sym.takeError());
112 return ErrorHandlerAddress;
119 switch (
T.getArch()) {
121 return make_error<StringError>(
122 std::string(
"No callback manager available for ") +
T.str(),
127 return CCMgrT::Create(ES, ErrorHandlerAddress);
132 return CCMgrT::Create(ES, ErrorHandlerAddress);
137 return CCMgrT::Create(ES, ErrorHandlerAddress);
141 return CCMgrT::Create(ES, ErrorHandlerAddress);
147 return CCMgrT::Create(ES, ErrorHandlerAddress);
151 if (
T.getOS() == Triple::OSType::Win32) {
153 return CCMgrT::Create(ES, ErrorHandlerAddress);
156 return CCMgrT::Create(ES, ErrorHandlerAddress);
163 std::function<std::unique_ptr<IndirectStubsManager>()>
165 switch (
T.getArch()) {
168 return std::make_unique<
175 return std::make_unique<
181 return std::make_unique<
187 return std::make_unique<
193 return std::make_unique<
200 return std::make_unique<
205 if (
T.getOS() == Triple::OSType::Win32) {
207 return std::make_unique<
212 return std::make_unique<
232 Initializer,
Name,
nullptr,
239 assert(
F.isDeclaration() &&
"Can't turn a definition into a stub.");
240 assert(
F.getParent() &&
"Function isn't in a module.");
245 std::vector<Value*> CallArgs;
246 for (
auto &A :
F.args())
247 CallArgs.push_back(&A);
248 CallInst *Call =
Builder.CreateCall(
F.getFunctionType(), ImplAddr, CallArgs);
250 Call->setAttributes(
F.getAttributes());
251 if (
F.getReturnType()->isVoidTy())
258 std::vector<GlobalValue *> PromotedGlobals;
260 for (
auto &GV :
M.global_values()) {
261 bool Promoted =
true;
265 GV.setName(
"__orc_anon." +
Twine(NextId++));
266 else if (GV.getName().startswith(
"\01L"))
267 GV.setName(
"__" + GV.getName().substr(1) +
"." +
Twine(NextId++));
268 else if (GV.hasLocalLinkage())
269 GV.setName(
"__orc_lcl." + GV.getName() +
"." +
Twine(NextId++));
273 if (GV.hasLocalLinkage()) {
281 PromotedGlobals.push_back(&GV);
284 return PromotedGlobals;
291 F.getLinkage(),
F.getName(), &Dst);
297 for (
auto ArgI =
F.arg_begin(), ArgE =
F.arg_end(); ArgI != ArgE;
299 (*VMap)[&*ArgI] = &*NewArgI;
310 NewF = cast<Function>(VMap[&OrigF]);
312 assert(VMap[&OrigF] == NewF &&
"Incorrect function mapping in VMap.");
313 assert(NewF &&
"Function mapping missing from VMap.");
315 "moveFunctionBody should only be used to move bodies between "
321 nullptr,
nullptr, Materializer);
333 (*VMap)[&GV] = NewGV;
343 NewGV = cast<GlobalVariable>(VMap[&OrigGV]);
345 assert(VMap[&OrigGV] == NewGV &&
346 "Incorrect global variable mapping in VMap.");
348 "moveGlobalVariableInitializer should only be used to move "
349 "initializers between modules");
352 nullptr, Materializer));
361 NewA->copyAttributesFrom(&OrigA);
371 for (
auto *MF : MFs->operands())
static StringRef getName(Value *V)
A symbol table that supports asynchoronous symbol queries.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Lookup or compute a mapping for a piece of metadata.
Manage compile callbacks for in-process JITs.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
LinkageTypes getLinkage() const
@ HiddenVisibility
The GV is hidden.
A raw_ostream that writes to an std::string.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src, ValueToValueMapTy &VMap)
Clone module flags metadata into the destination module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Pointer to a pooled string representing a symbol name.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Triple - Helper class for working with autoconf configuration names.
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Look up or compute a value in the value map.
Tagged union holding either a T or a Error.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Represents a symbol that has been evaluated to an address already.
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Constant * createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr)
Build a function pointer of FunctionType with the given constant address.
ThreadLocalMode getThreadLocalMode() const
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Create a local compile callback manager.
This is an important base class in LLVM.
Module * getParent()
Get the module that this global value is contained inside of...
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Class to represent pointers.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
A Module instance is used to store all the information related to an LLVM module.
GlobalVariable * createImplPointer(PointerType &PT, Module &M, const Twine &Name, Constant *Initializer)
Create a function pointer with the given type, name, and initializer in the given Module.
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
void moveGlobalVariableInitializer(GlobalVariable &OrigGV, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, GlobalVariable *NewGV=nullptr)
Move global variable GV from its parent module to cloned global declaration in a different module.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
const Constant * getAliasee() const
StringRef getName() const
Return a constant reference to the value's name.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
An instruction for reading from memory.
void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static IntegerType * getInt64Ty(LLVMContext &C)
std::function< JITTargetAddress()> CompileFunction
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
An ExecutionSession represents a running JIT program.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
IndirectStubsManager implementation for the host architecture, e.g.
@ ExternalLinkage
Externally visible function.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
std::string to_string(const T &Value)
PointerType * getType() const
Global values are always pointers.
Type * getValueType() const
This class represents a function call, abstracting a target machine's calling convention.
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
virtual ~TrampolinePool()
Expected< JITTargetAddress > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, Function *NewF=nullptr)
Move the body of function 'F' to a cloned function declaration in a different module (See related clo...
This is a class that can be implemented by clients to materialize Values on demand.
LLVM Value Representation.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Class to represent function types.