27#define DEBUG_TYPE "jit"
70 return unwrap(GenValRef)->IntVal.getBitWidth();
83 return unwrap(GenVal)->PointerVal;
89 return unwrap(GenVal)->FloatVal;
91 return unwrap(GenVal)->DoubleVal;
114 *OutError = strdup(
Error.c_str());
126 *OutInterp =
wrap(Interp);
129 *OutError = strdup(
Error.c_str());
146 *OutError = strdup(
Error.c_str());
151 size_t SizeOfPassedOptions) {
153 memset(&options, 0,
sizeof(options));
156 memcpy(PassedOptions, &options,
157 std::min(
sizeof(options), SizeOfPassedOptions));
167 if (SizeOfPassedOptions >
sizeof(options)) {
169 "Refusing to use options struct that is larger than my own; assuming "
170 "LLVM library mismatch.");
179 memcpy(&options, PassedOptions, SizeOfPassedOptions);
188 for (
auto &
F : *
Mod) {
189 auto Attrs =
F.getAttributes();
191 Attrs = Attrs.addFnAttribute(
F.getContext(),
"frame-pointer",
Value);
192 F.setAttributes(Attrs);
202 if (std::optional<CodeModel::Model> CM =
unwrap(options.CodeModel, JIT))
206 std::unique_ptr<RTDyldMemoryManager>(
unwrap(options.MCJMM)));
211 *OutError = strdup(
Error.c_str());
220 unwrap(EE)->finalizeObject();
221 unwrap(EE)->runStaticConstructorsDestructors(
false);
225 unwrap(EE)->finalizeObject();
226 unwrap(EE)->runStaticConstructorsDestructors(
true);
230 unsigned ArgC,
const char *
const *ArgV,
231 const char *
const *EnvP) {
232 unwrap(EE)->finalizeObject();
234 std::vector<std::string> ArgVec(ArgV, ArgV + ArgC);
235 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(
F), ArgVec, EnvP);
241 unwrap(EE)->finalizeObject();
243 std::vector<GenericValue> ArgVec;
244 ArgVec.reserve(NumArgs);
245 for (
unsigned I = 0;
I != NumArgs; ++
I)
246 ArgVec.push_back(*
unwrap(Args[
I]));
249 *Result =
unwrap(EE)->runFunction(unwrap<Function>(
F), ArgVec);
257 unwrap(EE)->addModule(std::unique_ptr<Module>(
unwrap(M)));
297 unwrap(EE)->finalizeObject();
299 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(
Global));
303 return unwrap(EE)->getGlobalValueAddress(
Name);
312 assert(OutError &&
"OutError must be non-null");
313 auto *ExecEngine =
unwrap(EE);
314 if (ExecEngine->hasError()) {
315 *OutError = strdup(ExecEngine->getErrorMessage().c_str());
316 ExecEngine->clearErrorMessage();
326struct SimpleBindingMMFunctions {
335 SimpleBindingMemoryManager(
const SimpleBindingMMFunctions& Functions,
337 ~SimpleBindingMemoryManager()
override;
345 bool isReadOnly)
override;
350 SimpleBindingMMFunctions Functions;
354SimpleBindingMemoryManager::SimpleBindingMemoryManager(
355 const SimpleBindingMMFunctions& Functions,
357 : Functions(Functions), Opaque(Opaque) {
358 assert(Functions.AllocateCodeSection &&
359 "No AllocateCodeSection function provided!");
360 assert(Functions.AllocateDataSection &&
361 "No AllocateDataSection function provided!");
362 assert(Functions.FinalizeMemory &&
363 "No FinalizeMemory function provided!");
364 assert(Functions.Destroy &&
365 "No Destroy function provided!");
368SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
369 Functions.Destroy(Opaque);
372uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
373 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
375 return Functions.AllocateCodeSection(Opaque,
Size, Alignment, SectionID,
379uint8_t *SimpleBindingMemoryManager::allocateDataSection(
380 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
382 return Functions.AllocateDataSection(Opaque,
Size, Alignment, SectionID,
387bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
388 char *errMsgCString =
nullptr;
389 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
390 assert((result || !errMsgCString) &&
391 "Did not expect an error message if FinalizeMemory succeeded");
394 *ErrMsg = errMsgCString;
409 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
414 functions.AllocateCodeSection = AllocateCodeSection;
415 functions.AllocateDataSection = AllocateDataSection;
416 functions.FinalizeMemory = FinalizeMemory;
418 return wrap(
new SimpleBindingMemoryManager(
functions, Opaque));
428#if !LLVM_USE_INTEL_JITEVENTS
435#if !LLVM_USE_OPROFILE
Lower uses of LDS variables from non kernel functions
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
static LLVMTargetMachineRef wrap(const TargetMachine *P)
static char getTypeID(Type *Ty)
Module.h This file contains the declarations for the Module class.
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
int64_t getSExtValue() const
Get sign extended value.
Builder class for ExecutionEngines.
EngineBuilder & setTargetOptions(const TargetOptions &Opts)
setTargetOptions - Set the target options that the ExecutionEngine target is using.
EngineBuilder & setMCJITMemoryManager(std::unique_ptr< RTDyldMemoryManager > mcjmm)
setMCJITMemoryManager - Sets the MCJIT memory manager to use.
EngineBuilder & setCodeModel(CodeModel::Model M)
setCodeModel - Set the CodeModel that the ExecutionEngine target data is using.
EngineBuilder & setOptLevel(CodeGenOptLevel l)
setOptLevel - Set the optimization level for the JIT.
EngineBuilder & setErrorStr(std::string *e)
setErrorStr - Set the error string to write to on error.
EngineBuilder & setEngineKind(EngineKind::Kind w)
setEngineKind - Controls whether the user wants the interpreter, the JIT, or whichever engine works.
ExecutionEngine * create()
Lightweight error class with error context and mandatory checking.
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
A Module instance is used to store all the information related to an LLVM module.
virtual uint8_t * allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool IsReadOnly)=0
Allocate a memory block of (at least) the given size suitable for data.
virtual uint8_t * allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName)=0
Allocate a memory block of (at least) the given size suitable for executable code.
virtual bool finalizeMemory(std::string *ErrMsg=nullptr)=0
This method is called when object loading is complete and section page permissions can be applied.
StringRef - Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
@ FloatTyID
32-bit floating point type
@ DoubleTyID
64-bit floating point type
LLVM Value Representation.
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE, char **OutError)
Returns true on error, false on success.
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
Create a simple custom MCJIT memory manager.
void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions)
void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE)
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, unsigned OptLevel, char **OutError)
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned NumArgs, LLVMGenericValueRef *Args)
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
void * LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn)
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name)
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError)
uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name)
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M)
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)
LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void)
struct LLVMOpaqueGenericValue * LLVMGenericValueRef
void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE)
LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions, char **OutError)
Create an MCJIT execution engine for a module, with the given options.
LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N)
uint8_t *(* LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName, LLVMBool IsReadOnly)
unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef, LLVMBool IsSigned)
int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned ArgC, const char *const *ArgV, const char *const *EnvP)
void * LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
uint8_t *(* LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName)
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError)
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal)
LLVMTargetMachineRef LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
struct LLVMOpaqueTargetData * LLVMTargetDataRef
@ LLVMCodeModelJITDefault
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
@ Global
Append to llvm.global_dtors.
Attribute unwrap(LLVMAttributeRef Attr)