Go to the documentation of this file.
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;
109 .setErrorStr(&
Error);
114 *OutError = strdup(
Error.c_str());
124 .setErrorStr(&
Error);
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);
201 .setTargetOptions(targetOptions);
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)
250 *Result =
unwrap(EE)->runFunction(unwrap<Function>(
F), ArgVec);
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);
313 assert(OutError &&
"OutError must be non-null");
314 auto *ExecEngine =
unwrap(EE);
315 if (ExecEngine->hasError()) {
316 *OutError = strdup(ExecEngine->getErrorMessage().c_str());
317 ExecEngine->clearErrorMessage();
327 struct SimpleBindingMMFunctions {
336 SimpleBindingMemoryManager(
const SimpleBindingMMFunctions& Functions,
338 ~SimpleBindingMemoryManager()
override;
340 uint8_t *allocateCodeSection(uintptr_t
Size,
unsigned Alignment,
344 uint8_t *allocateDataSection(uintptr_t
Size,
unsigned Alignment,
346 bool isReadOnly)
override;
348 bool finalizeMemory(std::string *ErrMsg)
override;
351 SimpleBindingMMFunctions Functions;
355 SimpleBindingMemoryManager::SimpleBindingMemoryManager(
356 const SimpleBindingMMFunctions& Functions,
358 : Functions(Functions), Opaque(Opaque) {
359 assert(Functions.AllocateCodeSection &&
360 "No AllocateCodeSection function provided!");
361 assert(Functions.AllocateDataSection &&
362 "No AllocateDataSection function provided!");
363 assert(Functions.FinalizeMemory &&
364 "No FinalizeMemory function provided!");
365 assert(Functions.Destroy &&
366 "No Destroy function provided!");
369 SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
370 Functions.Destroy(Opaque);
373 uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
374 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
376 return Functions.AllocateCodeSection(Opaque,
Size, Alignment, SectionID,
380 uint8_t *SimpleBindingMemoryManager::allocateDataSection(
381 uintptr_t
Size,
unsigned Alignment,
unsigned SectionID,
383 return Functions.AllocateDataSection(Opaque,
Size, Alignment, SectionID,
388 bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
389 char *errMsgCString =
nullptr;
390 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
392 "Did not expect an error message if FinalizeMemory succeeded");
395 *ErrMsg = errMsgCString;
410 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
415 functions.AllocateCodeSection = AllocateCodeSection;
416 functions.AllocateDataSection = AllocateDataSection;
417 functions.FinalizeMemory = FinalizeMemory;
419 return wrap(
new SimpleBindingMemoryManager(
functions, Opaque));
429 #if !LLVM_USE_INTEL_JITEVENTS
436 #if !LLVM_USE_OPROFILE
void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions)
amdgpu propagate attributes Late propagate attributes from kernels to functions
@ FloatTyID
32-bit floating point type
static LLVMTargetMachineRef wrap(const TargetMachine *P)
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
@ DoubleTyID
64-bit floating point type
This class represents lattice values for constants.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal)
uint8_t *(* LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName)
LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
int64_t getSExtValue() const
Get sign extended value.
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, unsigned OptLevel, char **OutError)
void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE)
Builder class for ExecutionEngines.
double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
void * LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
struct LLVMOpaqueTargetData * LLVMTargetDataRef
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name)
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
Create a simple custom MCJIT memory manager.
@ LLVMCodeModelJITDefault
int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned ArgC, const char *const *ArgV, const char *const *EnvP)
Attribute unwrap(LLVMAttributeRef Attr)
uint64_t getZExtValue() const
Get zero extended value.
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void)
LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError)
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
LLVMBool NoFramePointerElim
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
LLVMMCJITMemoryManagerRef MCJMM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Primary interface to the complete machine description for the target machine.
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
void * LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
uint8_t *(* LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName, LLVMBool IsReadOnly)
A Module instance is used to store all the information related to an LLVM module.
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
Class for arbitrary precision integers.
LLVMAttributeRef wrap(Attribute Attr)
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Mod
The access may modify the value stored in memory.
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M)
void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE)
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef, LLVMBool IsSigned)
Lightweight error class with error context and mandatory checking.
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError)
static char getTypeID(Type *Ty)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE, char **OutError)
Returns true on error, false on success.
LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned NumArgs, LLVMGenericValueRef *Args)
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.
unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
LLVMTargetMachineRef LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE)
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
LLVM Value Representation.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
struct LLVMOpaqueGenericValue * LLVMGenericValueRef