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();
192 "frame-pointer",
Value);
207 std::unique_ptr<RTDyldMemoryManager>(
unwrap(options.
MCJMM)));
212 *OutError = strdup(Error.c_str());
221 unwrap(EE)->finalizeObject();
222 unwrap(EE)->runStaticConstructorsDestructors(
false);
226 unwrap(EE)->finalizeObject();
227 unwrap(EE)->runStaticConstructorsDestructors(
true);
231 unsigned ArgC,
const char *
const *ArgV,
232 const char *
const *EnvP) {
233 unwrap(EE)->finalizeObject();
235 std::vector<std::string> ArgVec(ArgV, ArgV + ArgC);
236 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
242 unwrap(EE)->finalizeObject();
244 std::vector<GenericValue> ArgVec;
245 ArgVec.reserve(NumArgs);
246 for (
unsigned I = 0;
I != NumArgs; ++
I)
247 ArgVec.push_back(*
unwrap(Args[
I]));
250 *Result =
unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
258 unwrap(EE)->addModule(std::unique_ptr<Module>(
unwrap(M)));
264 unwrap(EE)->removeModule(Mod);
294 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
298 unwrap(EE)->finalizeObject();
300 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
304 return unwrap(EE)->getGlobalValueAddress(Name);
308 return unwrap(EE)->getFunctionAddress(Name);
315 struct SimpleBindingMMFunctions {
324 SimpleBindingMemoryManager(
const SimpleBindingMMFunctions& Functions,
326 ~SimpleBindingMemoryManager()
override;
328 uint8_t *allocateCodeSection(uintptr_t
Size,
unsigned Alignment,
332 uint8_t *allocateDataSection(uintptr_t Size,
unsigned Alignment,
333 unsigned SectionID,
StringRef SectionName,
334 bool isReadOnly)
override;
336 bool finalizeMemory(std::string *ErrMsg)
override;
339 SimpleBindingMMFunctions Functions;
343 SimpleBindingMemoryManager::SimpleBindingMemoryManager(
344 const SimpleBindingMMFunctions& Functions,
346 : Functions(Functions), Opaque(Opaque) {
347 assert(Functions.AllocateCodeSection &&
348 "No AllocateCodeSection function provided!");
349 assert(Functions.AllocateDataSection &&
350 "No AllocateDataSection function provided!");
351 assert(Functions.FinalizeMemory &&
352 "No FinalizeMemory function provided!");
353 assert(Functions.Destroy &&
354 "No Destroy function provided!");
357 SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
358 Functions.Destroy(Opaque);
361 uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
362 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
364 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
365 SectionName.
str().c_str());
368 uint8_t *SimpleBindingMemoryManager::allocateDataSection(
369 uintptr_t Size,
unsigned Alignment,
unsigned SectionID,
370 StringRef SectionName,
bool isReadOnly) {
371 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
372 SectionName.
str().c_str(),
376 bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
377 char *errMsgCString =
nullptr;
378 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
379 assert((result || !errMsgCString) &&
380 "Did not expect an error message if FinalizeMemory succeeded");
383 *ErrMsg = errMsgCString;
398 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
403 functions.AllocateCodeSection = AllocateCodeSection;
404 functions.AllocateDataSection = AllocateDataSection;
405 functions.FinalizeMemory = FinalizeMemory;
406 functions.Destroy = Destroy;
407 return wrap(
new SimpleBindingMemoryManager(functions, Opaque));
417 #if !LLVM_USE_INTEL_JITEVENTS 424 #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
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Attribute unwrap(LLVMAttributeRef Attr)
LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
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)
amdgpu propagate attributes Late propagate attributes from kernels to functions
LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
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)