22#define DEBUG_TYPE "orc"
34 CompileFunction Compile)
37 Name(std::move(Name)), Compile(std::move(Compile)) {}
42 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
55 CompileFunction Compile;
64void IndirectStubsManager::anchor() {}
68 if (
auto TrampolineAddr = TP->getTrampoline()) {
70 ES.
intern(std::string(
"cc") + std::to_string(++NextCallbackId));
72 std::lock_guard<std::mutex> Lock(CCMgrMutex);
73 AddrToSymbol[*TrampolineAddr] = CallbackName;
75 CallbacksJD.
define(std::make_unique<CompileCallbackMaterializationUnit>(
76 std::move(CallbackName), std::move(Compile))));
77 return *TrampolineAddr;
79 return TrampolineAddr.takeError();
87 std::unique_lock<std::mutex> Lock(CCMgrMutex);
88 auto I = AddrToSymbol.find(TrampolineAddr);
93 if (
I == AddrToSymbol.end()) {
96 make_error<StringError>(
"No compile callback for trampoline at " +
97 formatv(
"{0:x}", TrampolineAddr),
99 return ErrorHandlerAddress;
108 return Sym->getAddress();
114 return ErrorHandlerAddress;
121 switch (
T.getArch()) {
123 return make_error<StringError>(
124 std::string(
"No callback manager available for ") +
T.str(),
129 return CCMgrT::Create(ES, ErrorHandlerAddress);
134 return CCMgrT::Create(ES, ErrorHandlerAddress);
139 return CCMgrT::Create(ES, ErrorHandlerAddress);
144 return CCMgrT::Create(ES, ErrorHandlerAddress);
148 return CCMgrT::Create(ES, ErrorHandlerAddress);
154 return CCMgrT::Create(ES, ErrorHandlerAddress);
159 return CCMgrT::Create(ES, ErrorHandlerAddress);
165 return CCMgrT::Create(ES, ErrorHandlerAddress);
168 return CCMgrT::Create(ES, ErrorHandlerAddress);
175std::function<std::unique_ptr<IndirectStubsManager>()>
177 switch (
T.getArch()) {
180 return std::make_unique<
187 return std::make_unique<
193 return std::make_unique<
199 return std::make_unique<
205 return std::make_unique<
211 return std::make_unique<
218 return std::make_unique<
224 return std::make_unique<
231 return std::make_unique<
236 return std::make_unique<
255 Initializer,
Name,
nullptr,
262 assert(
F.isDeclaration() &&
"Can't turn a definition into a stub.");
263 assert(
F.getParent() &&
"Function isn't in a module.");
268 std::vector<Value*> CallArgs;
269 for (
auto &
A :
F.args())
270 CallArgs.push_back(&
A);
273 Call->setAttributes(
F.getAttributes());
274 if (
F.getReturnType()->isVoidTy())
281 std::vector<GlobalValue *> PromotedGlobals;
283 for (
auto &GV : M.global_values()) {
284 bool Promoted =
true;
288 GV.setName(
"__orc_anon." +
Twine(NextId++));
289 else if (GV.getName().starts_with(
"\01L"))
290 GV.setName(
"__" + GV.getName().substr(1) +
"." +
Twine(NextId++));
291 else if (GV.hasLocalLinkage())
292 GV.setName(
"__orc_lcl." + GV.getName() +
"." +
Twine(NextId++));
296 if (GV.hasLocalLinkage()) {
304 PromotedGlobals.push_back(&GV);
307 return PromotedGlobals;
314 F.getLinkage(),
F.getName(), &Dst);
320 for (
auto ArgI =
F.arg_begin(), ArgE =
F.arg_end(); ArgI != ArgE;
322 (*VMap)[&*ArgI] = &*NewArgI;
336 (*VMap)[&GV] = NewGV;
346 NewA->copyAttributesFrom(&OrigA);
364 auto &
B =
Sym.getBlock();
365 assert(!
B.isZeroFill() &&
"expected content block");
366 auto SymAddress =
Sym.getAddress();
367 auto SymStartInBlock =
368 (
const uint8_t *)
B.getContent().data() +
Sym.getOffset();
369 auto SymSize =
Sym.getSize() ?
Sym.getSize() :
B.getSize() -
Sym.getOffset();
375 for (
auto &E :
B.edges()) {
376 if (E.isRelocation())
377 ExistingRelocations.
insert(E.getOffset());
384 uint64_t InstrStart = SymAddress.getValue() +
I;
386 Instr, InstrSize,
Content.drop_front(
I), InstrStart, CommentStream);
388 LLVM_DEBUG(
dbgs() <<
"Aborting due to disassembly failure at address "
390 return make_error<StringError>(
391 formatv(
"failed to disassemble at address {0:x16}", InstrStart),
400 if (!PCRelAddr || *PCRelAddr != SymAddress.getValue())
403 auto RelocOffInInstr =
405 if (!RelocOffInInstr || InstrSize - *RelocOffInInstr != 4) {
412 SymAddress +
Sym.getOffset();
413 if (ExistingRelocations.
contains(RelocOffInBlock))
416 LLVM_DEBUG(
dbgs() <<
"Adding delta32 self-relocation at " << InstrStart);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
This class represents a function call, abstracting a target machine's calling convention.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Class to represent function types.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
const Constant * getAliasee() const
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...
LinkageTypes getLinkage() const
ThreadLocalMode getThreadLocalMode() const
PointerType * getType() const
Global values are always pointers.
@ HiddenVisibility
The GV is hidden.
@ ExternalLinkage
Externally visible function.
Type * getValueType() const
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An instruction for reading from memory.
Superclass for all disassemblers.
const MCSubtargetInfo & getSubtargetInfo() const
DecodeStatus
Ternary decode status.
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
Instances of this class represent a single low-level machine instruction.
virtual std::optional< uint64_t > getMemoryOperandRelocationOffset(const MCInst &Inst, uint64_t Size) const
Given an instruction with a memory operand that could require relocation, returns the offset within t...
virtual std::optional< uint64_t > evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr, uint64_t Size) const
Given an instruction tries to get the address of a memory operand.
A Module instance is used to store all the information related to an LLVM module.
Class to represent pointers.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Implements a dense probed hash-table based set with some number of buckets stored inline.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Represents an address in the executor process.
ExecutorAddr executeCompileCallback(ExecutorAddr TrampolineAddr)
Execute the callback for the given trampoline id.
Expected< ExecutorAddr > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
std::function< ExecutorAddr()> CompileFunction
Represents a JIT'd dynamic library.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
IndirectStubsManager implementation for the host architecture, e.g.
Manage compile callbacks for in-process JITs.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
virtual StringRef getName() const =0
Return the name of this materialization unit.
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
Pointer to a pooled string representing a symbol name.
virtual ~TrampolinePool()
A raw_ostream that discards all output.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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...
Constant * createIRTypedAddress(FunctionType &FT, ExecutorAddr Addr)
Build a function pointer of FunctionType with the given constant address.
Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddress)
Create a local compile callback manager.
void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, jitlink::LinkGraph &G, MCDisassembler &Disassembler, MCInstrAnalysis &MIA)
Introduce relocations to Sym in its own definition if there are any pointers formed via PC-relative a...
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
std::function< std::unique_ptr< IndirectStubsManager >()> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indirect stubs manager builder.
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new 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.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.