44 #define DEBUG_TYPE "jit" 46 STATISTIC(NumInitBytes,
"Number of bytes of global vars initialized");
47 STATISTIC(NumGlobals ,
"Number of global vars initialized");
50 std::unique_ptr<Module> M, std::string *ErrorStr,
51 std::shared_ptr<MCJITMemoryManager> MemMgr,
52 std::shared_ptr<LegacyJITSymbolResolver>
Resolver,
53 std::unique_ptr<TargetMachine>
TM) =
nullptr;
56 std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MemMgr,
57 std::shared_ptr<LegacyJITSymbolResolver>
Resolver,
58 std::unique_ptr<TargetMachine>
TM) =
nullptr;
60 ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
61 std::string *ErrorStr) =
nullptr;
63 void JITEventListener::anchor() {}
65 void ObjectCache::anchor() {}
67 void ExecutionEngine::Init(std::unique_ptr<Module> M) {
68 CompilingLazily =
false;
69 GVCompilationDisabled =
false;
70 SymbolSearchingDisabled =
false;
77 VerifyModules =
false;
80 assert(M &&
"Module is null?");
81 Modules.push_back(std::move(M));
85 : DL(M->getDataLayout()), LazyFunctionCreator(nullptr) {
101 class GVMemoryBlock final :
public CallbackVH {
103 :
CallbackVH(const_cast<GlobalVariable*>(GV)) {}
111 void *RawMemory = ::operator
new(
113 new(RawMemory) GVMemoryBlock(GV);
114 return static_cast<char*
>(RawMemory) +
sizeof(GVMemoryBlock);
117 void deleted()
override {
121 this->~GVMemoryBlock();
122 ::operator
delete(
this);
132 llvm_unreachable(
"ExecutionEngine subclass doesn't implement addObjectFile.");
137 llvm_unreachable(
"ExecutionEngine subclass doesn't implement addObjectFile.");
158 for (
unsigned i = 0, e =
Modules.size(); i != e; ++i) {
167 for (
unsigned i = 0, e =
Modules.size(); i != e; ++i) {
181 if (I == GlobalAddressMap.end())
184 GlobalAddressReverseMap.erase(I->second);
186 GlobalAddressMap.erase(I);
204 return FullName.
str();
215 assert(!Name.
empty() &&
"Empty GlobalMapping symbol name!");
217 LLVM_DEBUG(
dbgs() <<
"JIT: Map \'" << Name <<
"\' to [" << Addr <<
"]\n";);
218 uint64_t &CurVal = EEState.getGlobalAddressMap()[
Name];
219 assert((!CurVal || !Addr) &&
"GlobalMapping already established!");
223 if (!EEState.getGlobalAddressReverseMap().empty()) {
224 std::string &V = EEState.getGlobalAddressReverseMap()[CurVal];
226 "GlobalMapping already established!");
234 EEState.getGlobalAddressMap().clear();
235 EEState.getGlobalAddressReverseMap().clear();
255 EEState.getGlobalAddressMap();
259 return EEState.RemoveMapping(Name);
261 uint64_t &CurVal = Map[
Name];
262 uint64_t OldVal = CurVal;
264 if (CurVal && !EEState.getGlobalAddressReverseMap().empty())
265 EEState.getGlobalAddressReverseMap().
erase(CurVal);
269 if (!EEState.getGlobalAddressReverseMap().empty()) {
270 std::string &V = EEState.getGlobalAddressReverseMap()[CurVal];
272 "GlobalMapping already established!");
282 EEState.getGlobalAddressMap().find(S);
283 if (I != EEState.getGlobalAddressMap().end())
305 if (EEState.getGlobalAddressReverseMap().empty()) {
307 I = EEState.getGlobalAddressMap().begin(),
308 E = EEState.getGlobalAddressMap().end();
I !=
E; ++
I) {
310 uint64_t Addr =
I->second;
311 EEState.getGlobalAddressReverseMap().insert(std::make_pair(
316 std::map<uint64_t, std::string>::iterator
I =
317 EEState.getGlobalAddressReverseMap().find((uint64_t) Addr);
319 if (I != EEState.getGlobalAddressReverseMap().end()) {
321 for (
unsigned i = 0, e =
Modules.size(); i != e; ++i)
330 std::unique_ptr<char[]> Array;
331 std::vector<std::unique_ptr<char[]>> Values;
336 const std::vector<std::string> &InputArgv);
340 const std::vector<std::string> &InputArgv) {
342 Values.reserve(InputArgv.size());
344 Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
346 LLVM_DEBUG(
dbgs() <<
"JIT: ARGV = " << (
void *)Array.get() <<
"\n");
349 for (
unsigned i = 0; i != InputArgv.size(); ++i) {
350 unsigned Size = InputArgv[i].size()+1;
351 auto Dest = make_unique<char[]>(
Size);
352 LLVM_DEBUG(
dbgs() <<
"JIT: ARGV[" << i <<
"] = " << (
void *)Dest.get()
361 Values.push_back(std::move(Dest));
373 StringRef Name(isDtors ?
"llvm.global_dtors" :
"llvm.global_ctors");
387 for (
unsigned i = 0, e = InitList->
getNumOperands(); i != e; ++i) {
398 FP = CE->getOperand(0);
401 if (
Function *
F = dyn_cast<Function>(FP))
412 for (std::unique_ptr<Module> &M :
Modules)
420 for (
unsigned i = 0; i < PtrSize; ++i)
421 if (*(i + (uint8_t*)Loc))
428 const std::vector<std::string> &argv,
429 const char *
const * envp) {
430 std::vector<GenericValue> GVArgs;
455 GVArgs.push_back(GVArgc);
460 "argv[0] was null after CreateArgv");
462 std::vector<std::string> EnvVars;
463 for (
unsigned i = 0; envp[i]; ++i)
464 EnvVars.emplace_back(envp[i]);
477 : M(
std::move(M)), WhichEngine(EngineKind::
Either), ErrorStr(nullptr),
479 UseOrcMCJITReplacement(
false) {
483 VerifyModules =
true;
485 VerifyModules =
false;
492 std::unique_ptr<RTDyldMemoryManager> mcjmm) {
493 auto SharedMM = std::shared_ptr<RTDyldMemoryManager>(std::move(mcjmm));
501 MemMgr = std::shared_ptr<MCJITMemoryManager>(std::move(MM));
507 Resolver = std::shared_ptr<LegacyJITSymbolResolver>(std::move(SR));
512 std::unique_ptr<TargetMachine> TheTM(TM);
527 *ErrorStr =
"Cannot create an interpreter with a memory manager.";
536 errs() <<
"WARNING: This target JIT is not designed for the host" 537 <<
" you are running. If bad things happen, please choose" 538 <<
" a different -march switch.\n";
549 std::move(
Resolver), std::move(TheTM));
563 *ErrorStr =
"Interpreter has not been linked in.";
569 *ErrorStr =
"JIT has not been linked in.";
576 if (
Function *
F = const_cast<Function*>(dyn_cast<Function>(GV)))
577 return getPointerToFunction(
F);
580 if (
void*
P = getPointerToGlobalIfAvailable(GV))
585 const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
586 EmitGlobalVariable(GVar);
590 return getPointerToGlobalIfAvailable(GV);
597 if (isa<UndefValue>(C)) {
613 unsigned int elemNum = STy->getNumElements();
615 for (
unsigned int i = 0; i < elemNum; ++i) {
616 Type *ElemTy = STy->getElementType(i);
631 Type *ElemTy = VTy->getElementType();
632 unsigned int elemNum = VTy->getNumElements();
634 if (ElemTy->isIntegerTy())
635 for (
unsigned int i = 0; i < elemNum; ++i)
637 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
644 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
646 switch (CE->getOpcode()) {
647 case Instruction::GetElementPtr: {
651 cast<GEPOperator>(CE)->accumulateConstantOffset(DL,
Offset);
657 case Instruction::Trunc: {
663 case Instruction::ZExt: {
669 case Instruction::SExt: {
675 case Instruction::FPTrunc: {
681 case Instruction::FPExt:{
687 case Instruction::UIToFP: {
689 if (CE->getType()->isFloatTy())
691 else if (CE->getType()->isDoubleTy())
693 else if (CE->getType()->isX86_FP80Ty()) {
702 case Instruction::SIToFP: {
704 if (CE->getType()->isFloatTy())
706 else if (CE->getType()->isDoubleTy())
708 else if (CE->getType()->isX86_FP80Ty()) {
717 case Instruction::FPToUI:
718 case Instruction::FPToSI: {
730 CE->getOpcode()==Instruction::FPToSI,
736 case Instruction::PtrToInt: {
739 assert(PtrWidth <= 64 &&
"Bad pointer width");
741 uint32_t IntWidth = DL.getTypeSizeInBits(CE->getType());
745 case Instruction::IntToPtr: {
747 uint32_t PtrWidth = DL.getTypeSizeInBits(CE->getType());
753 case Instruction::BitCast: {
755 Type* DestTy = CE->getType();
780 case Instruction::FAdd:
781 case Instruction::Sub:
782 case Instruction::FSub:
783 case Instruction::Mul:
784 case Instruction::FMul:
785 case Instruction::UDiv:
786 case Instruction::SDiv:
787 case Instruction::URem:
788 case Instruction::SRem:
789 case Instruction::And:
790 case Instruction::Or:
791 case Instruction::Xor: {
795 switch (CE->getOperand(0)->getType()->getTypeID()) {
798 switch (CE->getOpcode()) {
801 case Instruction::Sub: GV.IntVal = LHS.
IntVal - RHS.
IntVal;
break;
802 case Instruction::Mul: GV.IntVal = LHS.
IntVal * RHS.
IntVal;
break;
807 case Instruction::And: GV.IntVal = LHS.
IntVal & RHS.
IntVal;
break;
808 case Instruction::Or: GV.IntVal = LHS.
IntVal | RHS.
IntVal;
break;
809 case Instruction::Xor: GV.IntVal = LHS.
IntVal ^ RHS.
IntVal;
break;
813 switch (CE->getOpcode()) {
815 case Instruction::FAdd:
817 case Instruction::FSub:
819 case Instruction::FMul:
821 case Instruction::FDiv:
823 case Instruction::FRem:
828 switch (CE->getOpcode()) {
830 case Instruction::FAdd:
832 case Instruction::FSub:
834 case Instruction::FMul:
836 case Instruction::FDiv:
838 case Instruction::FRem:
845 const fltSemantics &Sem = CE->getOperand(0)->getType()->getFltSemantics();
847 switch (CE->getOpcode()) {
849 case Instruction::FAdd:
853 case Instruction::FSub:
858 case Instruction::FMul:
863 case Instruction::FDiv:
868 case Instruction::FRem:
884 OS <<
"ConstantExpr not handled: " << *CE;
892 Result.FloatVal = cast<ConstantFP>(
C)->getValueAPF().convertToFloat();
895 Result.DoubleVal = cast<ConstantFP>(
C)->getValueAPF().convertToDouble();
900 Result.IntVal = cast <ConstantFP>(
C)->getValueAPF().bitcastToAPInt();
903 Result.IntVal = cast<ConstantInt>(
C)->getValue();
906 while (
auto *A = dyn_cast<GlobalAlias>(C)) {
909 if (isa<ConstantPointerNull>(C))
910 Result.PointerVal =
nullptr;
911 else if (
const Function *
F = dyn_cast<Function>(C))
912 Result =
PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(
F)));
914 Result =
PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
928 }
else if (CV || CAZ) {
936 Result.AggregateVal.resize(elemNum);
942 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
947 for (
unsigned i = 0; i < elemNum; ++i)
948 if (!isa<UndefValue>(CV->getOperand(i)))
949 Result.AggregateVal[i].FloatVal = cast<ConstantFP>(
950 CV->getOperand(i))->getValueAPF().convertToFloat();
954 for (
unsigned i = 0; i < elemNum; ++i)
964 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
969 for (
unsigned i = 0; i < elemNum; ++i)
970 if (!isa<UndefValue>(CV->getOperand(i)))
971 Result.AggregateVal[i].DoubleVal = cast<ConstantFP>(
972 CV->getOperand(i))->getValueAPF().convertToDouble();
976 for (
unsigned i = 0; i < elemNum; ++i)
986 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
991 for (
unsigned i = 0; i < elemNum; ++i)
992 if (!isa<UndefValue>(CV->getOperand(i)))
993 Result.AggregateVal[i].IntVal = cast<ConstantInt>(
994 CV->getOperand(i))->getValue();
996 Result.AggregateVal[i].IntVal =
997 APInt(CV->getOperand(i)->getType()->getPrimitiveSizeInBits(), 0);
1002 for (
unsigned i = 0; i < elemNum; ++i)
1003 Result.AggregateVal[i].IntVal =
APInt(
1016 OS <<
"ERROR: Constant unimplemented for type: " << *C->
getType();
1026 unsigned StoreBytes) {
1028 const uint8_t *Src = (
const uint8_t *)IntVal.
getRawData();
1033 memcpy(Dst, Src, StoreBytes);
1038 while (StoreBytes >
sizeof(uint64_t)) {
1039 StoreBytes -=
sizeof(uint64_t);
1041 memcpy(Dst + StoreBytes, Src,
sizeof(uint64_t));
1042 Src +=
sizeof(uint64_t);
1045 memcpy(Dst, Src +
sizeof(uint64_t) - StoreBytes, StoreBytes);
1051 const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
1055 dbgs() <<
"Cannot store value of type " << *Ty <<
"!\n";
1072 memset(&(Ptr->PointerVal), 0, StoreBytes);
1077 for (
unsigned i = 0; i < Val.
AggregateVal.size(); ++i) {
1078 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
1080 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
1082 if (cast<VectorType>(Ty)->getElementType()->isIntegerTy()) {
1083 unsigned numOfBytes =(Val.
AggregateVal[i].IntVal.getBitWidth()+7)/8;
1085 (uint8_t*)Ptr + numOfBytes*i, numOfBytes);
1093 std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
1100 uint8_t *Dst =
reinterpret_cast<uint8_t *
>(
1101 const_cast<uint64_t *
>(IntVal.
getRawData()));
1106 memcpy(Dst, Src, LoadBytes);
1112 while (LoadBytes >
sizeof(uint64_t)) {
1113 LoadBytes -=
sizeof(uint64_t);
1115 memcpy(Dst, Src + LoadBytes,
sizeof(uint64_t));
1116 Dst +=
sizeof(uint64_t);
1119 memcpy(Dst +
sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
1128 const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty);
1154 auto *VT = cast<VectorType>(Ty);
1155 Type *ElemT = VT->getElementType();
1156 const unsigned numElems = VT->getNumElements();
1157 if (ElemT->isFloatTy()) {
1159 for (
unsigned i = 0; i < numElems; ++i)
1162 if (ElemT->isDoubleTy()) {
1164 for (
unsigned i = 0; i < numElems; ++i)
1167 if (ElemT->isIntegerTy()) {
1169 const unsigned elemBitWidth = cast<IntegerType>(ElemT)->
getBitWidth();
1172 for (
unsigned i = 0; i < numElems; ++i)
1174 (uint8_t*)Ptr+((elemBitWidth+7)/8)*i, (elemBitWidth+7)/8);
1181 OS <<
"Cannot load value of type " << *Ty <<
"!";
1189 if (isa<UndefValue>(Init))
1193 unsigned ElementSize =
1194 getDataLayout().getTypeAllocSize(
CP->getType()->getElementType());
1195 for (
unsigned i = 0, e =
CP->getNumOperands(); i != e; ++i)
1196 InitializeMemory(
CP->getOperand(i), (
char*)Addr+i*ElementSize);
1200 if (isa<ConstantAggregateZero>(Init)) {
1201 memset(Addr, 0, (
size_t)getDataLayout().getTypeAllocSize(Init->
getType()));
1205 if (
const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
1206 unsigned ElementSize =
1207 getDataLayout().getTypeAllocSize(CPA->getType()->getElementType());
1208 for (
unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
1209 InitializeMemory(CPA->getOperand(i), (
char*)Addr+i*ElementSize);
1213 if (
const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
1215 getDataLayout().getStructLayout(cast<StructType>(CPS->getType()));
1216 for (
unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
1222 dyn_cast<ConstantDataSequential>(Init)) {
1246 std::map<std::pair<std::string, Type*>,
1249 if (Modules.size() != 1) {
1250 for (
unsigned m = 0, e = Modules.size(); m != e; ++m) {
1252 for (
const auto &GV : M.
globals()) {
1253 if (GV.hasLocalLinkage() || GV.isDeclaration() ||
1254 GV.hasAppendingLinkage() || !GV.hasName())
1258 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())];
1279 std::vector<const GlobalValue*> NonCanonicalGlobals;
1280 for (
unsigned m = 0, e = Modules.size(); m != e; ++m) {
1282 for (
const auto &GV : M.
globals()) {
1284 if (!LinkedGlobalsMap.empty()) {
1286 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())]) {
1288 if (GVEntry != &GV) {
1289 NonCanonicalGlobals.push_back(&GV);
1295 if (!GV.isDeclaration()) {
1296 addGlobalMapping(&GV, getMemoryForGV(&GV));
1302 addGlobalMapping(&GV, SymAddr);
1312 if (!NonCanonicalGlobals.empty()) {
1313 for (
unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
1317 void *Ptr = getPointerToGlobalIfAvailable(CGV);
1318 assert(Ptr &&
"Canonical global wasn't codegen'd!");
1319 addGlobalMapping(GV, Ptr);
1325 for (
const auto &GV : M.
globals()) {
1326 if (!GV.isDeclaration()) {
1327 if (!LinkedGlobalsMap.empty()) {
1329 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())])
1333 EmitGlobalVariable(&GV);
1343 void *GA = getPointerToGlobalIfAvailable(GV);
1347 GA = getMemoryForGV(GV);
1352 addGlobalMapping(GV, GA);
1360 size_t GVSize = (size_t)getDataLayout().getTypeAllocSize(ElTy);
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
A parsed version of the target data layout string in and methods for querying it. ...
const_iterator end(StringRef path)
Get end iterator over path.
std::vector< GenericValue > AggregateVal
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
bool hasLocalLinkage() const
uint64_t getZExtValue() const
Get zero extended value.
APInt sext(unsigned width) const
Sign extend to a new width.
std::string getMangledName(const GlobalValue *GV)
getMangledName - Get mangled name.
void clearAllGlobalMappings()
clearAllGlobalMappings - Clear all global mappings and start over again, for use in dynamic compilati...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
static ExecutionEngine *(* MCJITCtor)(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< LegacyJITSymbolResolver > SR, std::unique_ptr< TargetMachine > TM)
Type * getParamType(unsigned i) const
Parameter type accessors.
int runFunctionAsMain(Function *Fn, const std::vector< std::string > &argv, const char *const *envp)
runFunctionAsMain - This is a helper function which wraps runFunction to handle the common task of st...
A Module instance is used to store all the information related to an LLVM module. ...
virtual bool removeModule(Module *M)
removeModule - Removes a Module from the list of modules, but does not free the module's memory...
2: 32-bit floating point type
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
void * getPointerToGlobalIfAvailable(StringRef S)
getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has a...
sys::Mutex lock
lock - This lock protects the ExecutionEngine and MCJIT classes.
uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr)
updateGlobalMapping - Replace an existing mapping for GV with a new address.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
APInt zext(unsigned width) const
Zero extend to a new width.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
virtual GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues)=0
runFunction - Execute the specified function with the specified arguments, and return the result...
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
A raw_ostream that writes to an SmallVector or SmallString.
void EmitGlobalVariable(const GlobalVariable *GV)
static bool getConstantValue(SDValue N, uint32_t &Out)
APInt trunc(unsigned width) const
Truncate to new width.
STATISTIC(NumFunctions, "Total number of functions")
4: 80-bit floating point type (X87)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
bool hasExternalWeakLinkage() const
const DataLayout & getDataLayout() const
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
unsigned getBitWidth() const
Return the number of bits in the APInt.
iterator_range< global_object_iterator > global_objects()
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
void dump() const
Support for debugging, callable in GDB: V->dump()
opStatus divide(const APFloat &RHS, roundingMode RM)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
virtual void runStaticConstructorsDestructors(bool isDtors)
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...
static APInt doubleToBits(double V)
Converts a double to APInt bits.
TypeID getTypeID() const
Return the type id for the type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
void * getPointerToGlobal(const GlobalValue *GV)
getPointerToGlobal - This returns the address of the specified global value.
void InitializeMemory(const Constant *Init, void *Addr)
Class to represent struct types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
EngineBuilder()
Default constructor for EngineBuilder.
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
uint64_t getNumElements() const
virtual void addModule(std::unique_ptr< Module > M)
Add a Module to the list of modules that we can JIT from.
All zero aggregate value.
StringRef str() const
Explicit conversion to StringRef.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
bool hasExternalLinkage() const
static const bool IsLittleEndianHost
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes)
LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting from Src into IntVal...
virtual char * getMemoryForGV(const GlobalVariable *GV)
getMemoryforGV - Allocate memory for a global variable.
void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, Type *Ty)
FIXME: document.
static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc)
isTargetNullPtr - Return whether the target pointer stored at Loc is null.
EngineBuilder & setSymbolResolver(std::unique_ptr< LegacyJITSymbolResolver > SR)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
opStatus subtract(const APFloat &RHS, roundingMode RM)
GenericValue getConstantValue(const Constant *C)
Converts a Constant* into a GenericValue, including handling of ConstantExpr values.
void emitGlobals()
EmitGlobals - Emit all of the global variables to memory, storing their addresses into GlobalAddress...
uint64_t RemoveMapping(StringRef Name)
Erase an entry from the mapping table.
void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, Type *Ty)
StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
Type * getElementType() const
Return the element type of the array/vector.
Value * getOperand(unsigned i) const
11: Arbitrary bit width integers
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
EngineBuilder & setMemoryManager(std::unique_ptr< MCJITMemoryManager > MM)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
virtual void addObjectFile(std::unique_ptr< object::ObjectFile > O)
addObjectFile - Add an ObjectFile to the execution engine.
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
opStatus multiply(const APFloat &RHS, roundingMode RM)
6: 128-bit floating point type (two 64-bits, PowerPC)
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
Constant Vector Declarations.
static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst, unsigned StoreBytes)
StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst with the integer held in In...
const Target & getTarget() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void clearGlobalMappingsFromModule(Module *M)
clearGlobalMappingsFromModule - Clear all global mappings that came from a particular module...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static ExecutionEngine *(* InterpCtor)(std::unique_ptr< Module > M, std::string *ErrorStr)
virtual Function * FindFunctionNamed(StringRef FnName)
FindFunctionNamed - Search all of the active modules to find the function that defines FnName...
#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 * GVTOP(const GenericValue &GV)
unsigned getNumOperands() const
ExecutionEngine(DataLayout DL)
16: SIMD 'packed' format, or other vector type
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Module.h This file contains the declarations for the Module class.
bool isAggregateType() const
Return true if the type is an aggregate type.
Type * getReturnType() const
StringRef str()
Return a StringRef for the vector contents.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
void setVerifyModules(bool Verify)
Enable/Disable IR module verification.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Class to represent vector types.
virtual void addArchive(object::OwningBinary< object::Archive > A)
addArchive - Add an Archive to the execution engine.
GenericValue PTOGV(void *P)
Class for arbitrary precision integers.
ConstantArray - Constant Array Declarations.
static ExecutionEngine *(* OrcMCJITReplacementCtor)(std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< LegacyJITSymbolResolver > SR, std::unique_ptr< TargetMachine > TM)
opStatus mod(const APFloat &RHS)
SmallVector< std::unique_ptr< Module >, 1 > Modules
The list of Modules that we are JIT'ing from.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
virtual ~ExecutionEngine()
opStatus add(const APFloat &RHS, roundingMode RM)
ExecutionEngine * create()
void addGlobalMapping(const GlobalValue *GV, void *Addr)
addGlobalMapping - Tell the execution engine that the specified global is at the specified location...
uint64_t getElementOffset(unsigned Idx) const
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
StringRef getName() const
Return a constant reference to the value's name.
uint64_t getAddressToGlobalIfAvailable(StringRef S)
getAddressToGlobalIfAvailable - This returns the address of the specified global symbol.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
const GlobalValue * getGlobalValueAtAddress(void *Addr)
getGlobalValueAtAddress - Return the LLVM global value object that starts at the specified address...
Builder class for ExecutionEngines.
EngineBuilder & setMCJITMemoryManager(std::unique_ptr< RTDyldMemoryManager > mcjmm)
setMCJITMemoryManager - Sets the MCJIT memory manager to use.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
float bitsToFloat() const
Converts APInt bits to a double.
3: 64-bit floating point type
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionCreator LazyFunctionCreator
LazyFunctionCreator - If an unknown function is needed, this function pointer is invoked to create it...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
bool hasJIT() const
hasJIT - Check if this targets supports the just-in-time compilation.
Primary interface to the complete machine description for the target machine.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Type * getElementType() const
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
iterator_range< global_iterator > globals()
Value handle with callbacks on RAUW and destruction.
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
unsigned getNumElements() const
Return the number of elements in the array or vector.
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
OutputIt copy(R &&Range, OutputIt Out)
static APInt floatToBits(float V)
Converts a float to APInt bits.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
double bitsToDouble() const
Converts APInt bits to a double.
double signedRoundToDouble() const
Converts this signed APInt to a double value.
PointerType * getType() const
Global values are always pointers.
virtual GlobalVariable * FindGlobalVariableNamed(StringRef Name, bool AllowInternal=false)
FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines N...
5: 128-bit floating point type (112-bit mantissa)