28 #define DEBUG_TYPE "jit" 71 return unwrap(GenValRef)->IntVal.getBitWidth();
84 return unwrap(GenVal)->PointerVal;
90 return unwrap(GenVal)->FloatVal;
92 return unwrap(GenVal)->DoubleVal;
115 *OutError = strdup(Error.c_str());
127 *OutInterp =
wrap(Interp);
130 *OutError = strdup(Error.c_str());
147 *OutError = strdup(Error.c_str());
152 size_t SizeOfPassedOptions) {
154 memset(&options, 0,
sizeof(options));
157 memcpy(PassedOptions, &options,
158 std::min(
sizeof(options), SizeOfPassedOptions));
168 if (SizeOfPassedOptions >
sizeof(options)) {
170 "Refusing to use options struct that is larger than my own; assuming " 171 "LLVM library mismatch.");
180 memcpy(&options, PassedOptions, SizeOfPassedOptions);
189 for (
auto &
F : *Mod) {
190 auto Attrs =
F.getAttributes();
193 "no-frame-pointer-elim", Value);
208 std::unique_ptr<RTDyldMemoryManager>(
unwrap(options.
MCJMM)));
213 *OutError = strdup(Error.c_str());
222 unwrap(EE)->finalizeObject();
223 unwrap(EE)->runStaticConstructorsDestructors(
false);
227 unwrap(EE)->finalizeObject();
228 unwrap(EE)->runStaticConstructorsDestructors(
true);
232 unsigned ArgC,
const char *
const *ArgV,
233 const char *
const *EnvP) {
234 unwrap(EE)->finalizeObject();
236 std::vector<std::string> ArgVec(ArgV, ArgV + ArgC);
237 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
243 unwrap(EE)->finalizeObject();
245 std::vector<GenericValue> ArgVec;
246 ArgVec.reserve(NumArgs);
247 for (
unsigned I = 0;
I != NumArgs; ++
I)
248 ArgVec.push_back(*
unwrap(Args[
I]));
251 *Result =
unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
259 unwrap(EE)->addModule(std::unique_ptr<Module>(
unwrap(M)));
265 unwrap(EE)->removeModule(Mod);
295 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
299 unwrap(EE)->finalizeObject();
301 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
305 return unwrap(EE)->getGlobalValueAddress(Name);
309 return unwrap(EE)->getFunctionAddress(Name);
316 struct SimpleBindingMMFunctions {
325 SimpleBindingMemoryManager(
const SimpleBindingMMFunctions& Functions,
327 ~SimpleBindingMemoryManager()
override;
329 uint8_t *allocateCodeSection(uintptr_t
Size,
unsigned Alignment,
333 uint8_t *allocateDataSection(uintptr_t Size,
unsigned Alignment,
334 unsigned SectionID,
StringRef SectionName,
335 bool isReadOnly)
override;
337 bool finalizeMemory(std::string *ErrMsg)
override;
340 SimpleBindingMMFunctions Functions;
344 SimpleBindingMemoryManager::SimpleBindingMemoryManager(
345 const SimpleBindingMMFunctions& Functions,
347 : Functions(Functions), Opaque(Opaque) {
348 assert(Functions.AllocateCodeSection &&
349 "No AllocateCodeSection function provided!");
350 assert(Functions.AllocateDataSection &&
351 "No AllocateDataSection function provided!");
352 assert(Functions.FinalizeMemory &&
353 "No FinalizeMemory function provided!");
354 assert(Functions.Destroy &&
355 "No Destroy function provided!");
358 SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
359 Functions.Destroy(Opaque);
362 uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
363 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
365 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
366 SectionName.
str().c_str());
369 uint8_t *SimpleBindingMemoryManager::allocateDataSection(
370 uintptr_t Size,
unsigned Alignment,
unsigned SectionID,
371 StringRef SectionName,
bool isReadOnly) {
372 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
373 SectionName.
str().c_str(),
377 bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
378 char *errMsgCString =
nullptr;
379 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
380 assert((result || !errMsgCString) &&
381 "Did not expect an error message if FinalizeMemory succeeded");
384 *ErrMsg = errMsgCString;
399 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
404 functions.AllocateCodeSection = AllocateCodeSection;
405 functions.AllocateDataSection = AllocateDataSection;
406 functions.FinalizeMemory = FinalizeMemory;
407 functions.Destroy = Destroy;
408 return wrap(
new SimpleBindingMemoryManager(functions, Opaque));
418 #if !LLVM_USE_INTEL_JITEVENTS 425 #if !LLVM_USE_OPROFILE static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
uint8_t *(* LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName)
LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N)
uint64_t getZExtValue() const
Get zero extended value.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions)
This class represents lattice values for constants.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
LLVMMCJITMemoryManagerRef MCJMM
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE)
void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal)
void * LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn)
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, unsigned OptLevel, char **OutError)
double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
struct LLVMOpaqueTargetData * LLVMTargetDataRef
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Attribute unwrap(LLVMAttributeRef Attr)
LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
always Inliner for always_inline functions
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
int64_t getSExtValue() const
Get sign extended value.
uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name)
EngineBuilder & setCodeModel(CodeModel::Model M)
setCodeModel - Set the CodeModel that the ExecutionEngine target data is using.
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
Create a simple custom MCJIT memory manager.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void)
int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned ArgC, const char *const *ArgV, const char *const *EnvP)
EngineBuilder & setEngineKind(EngineKind::Kind w)
setEngineKind - Controls whether the user wants the interpreter, the JIT, or whichever engine works...
LLVMBool NoFramePointerElim
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError)
EngineBuilder & setErrorStr(std::string *e)
setErrorStr - Set the error string to write to on error.
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
void * LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
EngineBuilder & setTargetOptions(const TargetOptions &Opts)
setTargetOptions - Set the target options that the ExecutionEngine target is using.
Module.h This file contains the declarations for the Module class.
uint8_t *(* LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName, LLVMBool IsReadOnly)
The access may modify the value stored in memory.
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError)
Class for arbitrary precision integers.
static char getTypeID(Type *Ty)
ExecutionEngine * create()
void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE)
LLVMAttributeRef wrap(Attribute Attr)
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M)
uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name)
unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef, LLVMBool IsSigned)
LLVMTargetMachineRef LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE)
LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned NumArgs, LLVMGenericValueRef *Args)
Builder class for ExecutionEngines.
EngineBuilder & setMCJITMemoryManager(std::unique_ptr< RTDyldMemoryManager > mcjmm)
setMCJITMemoryManager - Sets the MCJIT memory manager to use.
unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
3: 64-bit floating point type
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
LLVM Value Representation.
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
Lightweight error class with error context and mandatory checking.
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
struct LLVMOpaqueGenericValue * LLVMGenericValueRef
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
EngineBuilder & setOptLevel(CodeGenOpt::Level l)
setOptLevel - Set the optimization level for the JIT.
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)