33 Name(std::move(
Name)), Compile(std::move(Compile)) {}
50 CompileFunction Compile;
58 void IndirectStubsManager::anchor() {}
59 void TrampolinePool::anchor() {}
63 if (
auto TrampolineAddr = TP->getTrampoline()) {
67 std::lock_guard<std::mutex>
Lock(CCMgrMutex);
68 AddrToSymbol[*TrampolineAddr] = CallbackName;
70 llvm::make_unique<CompileCallbackMaterializationUnit>(
71 std::move(CallbackName), std::move(Compile),
72 ES.allocateVModule())));
73 return *TrampolineAddr;
75 return TrampolineAddr.takeError();
83 std::unique_lock<std::mutex>
Lock(CCMgrMutex);
84 auto I = AddrToSymbol.find(TrampolineAddr);
89 if (
I == AddrToSymbol.end()) {
94 ErrMsgStream <<
"No compile callback for trampoline at " 95 <<
format(
"0x%016" PRIx64, TrampolineAddr);
99 return ErrorHandlerAddress;
105 return Sym->getAddress();
110 ES.reportError(Sym.takeError());
111 return ErrorHandlerAddress;
120 return make_error<StringError>(
121 std::string(
"No callback manager available for ") + T.
str(),
125 return CCMgrT::Create(ES, ErrorHandlerAddress);
130 return CCMgrT::Create(ES, ErrorHandlerAddress);
135 return CCMgrT::Create(ES, ErrorHandlerAddress);
139 return CCMgrT::Create(ES, ErrorHandlerAddress);
145 return CCMgrT::Create(ES, ErrorHandlerAddress);
149 if ( T.
getOS() == Triple::OSType::Win32 ) {
151 return CCMgrT::Create(ES, ErrorHandlerAddress);
154 return CCMgrT::Create(ES, ErrorHandlerAddress);
161 std::function<std::unique_ptr<IndirectStubsManager>()>
202 if (T.
getOS() == Triple::OSType::Win32) {
229 Initializer, Name,
nullptr,
241 LoadInst *ImplAddr = Builder.CreateLoad(&ImplPointer);
242 std::vector<Value*> CallArgs;
243 for (
auto &A : F.
args())
244 CallArgs.push_back(&A);
245 CallInst *Call = Builder.CreateCall(ImplAddr, CallArgs);
249 Builder.CreateRetVoid();
251 Builder.CreateRet(Call);
255 std::vector<GlobalValue *> PromotedGlobals;
258 bool Promoted =
true;
262 GV.setName(
"__orc_anon." +
Twine(NextId++));
263 else if (GV.getName().startswith(
"\01L"))
264 GV.setName(
"__" + GV.getName().substr(1) +
"." +
Twine(NextId++));
265 else if (GV.hasLocalLinkage())
266 GV.setName(
"__orc_lcl." + GV.getName() +
"." +
Twine(NextId++));
270 if (GV.hasLocalLinkage()) {
278 PromotedGlobals.push_back(&GV);
281 return PromotedGlobals;
296 (*VMap)[&*ArgI] = &*NewArgI;
307 NewF = cast<Function>(VMap[&OrigF]);
309 assert(VMap[&OrigF] == NewF &&
"Incorrect function mapping in VMap.");
310 assert(NewF &&
"Function mapping missing from VMap.");
312 "moveFunctionBody should only be used to move bodies between " 317 "",
nullptr,
nullptr, Materializer);
329 (*VMap)[&GV] = NewGV;
339 NewGV = cast<GlobalVariable>(VMap[&OrigGV]);
341 assert(VMap[&OrigGV] == NewGV &&
342 "Incorrect global variable mapping in VMap.");
344 "moveGlobalVariableInitializer should only be used to move " 345 "initializers between modules");
348 nullptr, Materializer));
367 for (
auto *MF : MFs->operands())
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
ThreadLocalMode getThreadLocalMode() const
IndirectStubsManager implementation for the host architecture, e.g.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void emit()
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
This class represents lattice values for constants.
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
A Module instance is used to store all the information related to an LLVM module. ...
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src, ValueToValueMapTy &VMap)
Clone module flags metadata into the destination module.
This class represents a function call, abstracting a target machine's calling convention.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Externally visible function.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Manage compile callbacks for in-process JITs.
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
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.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, 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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void copyAttributesFrom(const GlobalValue *Src)
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
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...
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static StringRef getName(Value *V)
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...
Tagged union holding either a T or a Error.
void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Class to represent function types.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
AttributeList getAttributes() const
Return the attribute list for this Function.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
LinkageTypes getLinkage() const
const std::string & str() const
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
Class to represent pointers.
Pointer to a pooled string representing a symbol name.
bool isVoidTy() const
Return true if this is 'void'.
This is a class that can be implemented by clients to materialize Values on demand.
Type * getReturnType() const
Returns the type of the ret val.
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
LLVM Basic Block Representation.
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
This is an important base class in LLVM.
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void setTailCall(bool isTC=true)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Triple - Helper class for working with autoconf configuration names.
Constant * createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr)
Build a function pointer of FunctionType with the given constant address.
std::function< JITTargetAddress()> CompileFunction
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
void resolve(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Create a local compile callback manager.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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< JITTargetAddress > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
An ExecutionSession represents a running JIT program.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Represents a symbol that has been evaluated to an address already.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
StringRef getName() const
Return a constant reference to the value's name.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Type * getValueType() const
const std::string to_string(const T &Value)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool hasInitializer() const
Definitions have initializers, declarations don't.
StringRef - Represent a constant reference to a string, i.e.
iterator_range< global_value_iterator > global_values()
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...
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...
PointerType * getType() const
Global values are always pointers.
iterator_range< arg_iterator > args()
A symbol table that supports asynchoronous symbol queries.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
const Constant * getAliasee() const