43 #define DEBUG_TYPE "jit" 45 STATISTIC(NumInitBytes,
"Number of bytes of global vars initialized");
46 STATISTIC(NumGlobals ,
"Number of global vars initialized");
49 std::unique_ptr<Module> M, std::string *ErrorStr,
50 std::shared_ptr<MCJITMemoryManager> MemMgr,
51 std::shared_ptr<LegacyJITSymbolResolver>
Resolver,
52 std::unique_ptr<TargetMachine>
TM) =
nullptr;
55 std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MemMgr,
56 std::shared_ptr<LegacyJITSymbolResolver>
Resolver,
57 std::unique_ptr<TargetMachine>
TM) =
nullptr;
59 ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
60 std::string *ErrorStr) =
nullptr;
62 void JITEventListener::anchor() {}
64 void ObjectCache::anchor() {}
66 void ExecutionEngine::Init(std::unique_ptr<Module> M) {
67 CompilingLazily =
false;
68 GVCompilationDisabled =
false;
69 SymbolSearchingDisabled =
false;
76 VerifyModules =
false;
79 assert(M &&
"Module is null?");
80 Modules.push_back(std::move(M));
84 : DL(M->getDataLayout()), LazyFunctionCreator(nullptr) {
100 class GVMemoryBlock final :
public CallbackVH {
102 :
CallbackVH(const_cast<GlobalVariable*>(GV)) {}
110 void *RawMemory = ::operator
new(
112 new(RawMemory) GVMemoryBlock(GV);
113 return static_cast<char*
>(RawMemory) +
sizeof(GVMemoryBlock);
116 void deleted()
override {
120 this->~GVMemoryBlock();
121 ::operator
delete(
this);
131 llvm_unreachable(
"ExecutionEngine subclass doesn't implement addObjectFile.");
136 llvm_unreachable(
"ExecutionEngine subclass doesn't implement addObjectFile.");
157 for (
unsigned i = 0,
e =
Modules.size(); i !=
e; ++i) {
166 for (
unsigned i = 0,
e =
Modules.size(); i !=
e; ++i) {
180 if (I == GlobalAddressMap.end())
183 GlobalAddressReverseMap.erase(I->second);
185 GlobalAddressMap.erase(I);
194 std::lock_guard<sys::Mutex> locked(
lock);
203 return FullName.
str();
207 std::lock_guard<sys::Mutex> locked(
lock);
212 std::lock_guard<sys::Mutex> locked(
lock);
214 assert(!Name.
empty() &&
"Empty GlobalMapping symbol name!");
216 LLVM_DEBUG(
dbgs() <<
"JIT: Map \'" << Name <<
"\' to [" << Addr <<
"]\n";);
217 uint64_t &CurVal = EEState.getGlobalAddressMap()[
Name];
218 assert((!CurVal || !Addr) &&
"GlobalMapping already established!");
222 if (!EEState.getGlobalAddressReverseMap().empty()) {
223 std::string &V = EEState.getGlobalAddressReverseMap()[CurVal];
225 "GlobalMapping already established!");
231 std::lock_guard<sys::Mutex> locked(
lock);
233 EEState.getGlobalAddressMap().clear();
234 EEState.getGlobalAddressReverseMap().clear();
238 std::lock_guard<sys::Mutex> locked(
lock);
246 std::lock_guard<sys::Mutex> locked(
lock);
251 std::lock_guard<sys::Mutex> locked(
lock);
254 EEState.getGlobalAddressMap();
258 return EEState.RemoveMapping(Name);
260 uint64_t &CurVal = Map[
Name];
261 uint64_t OldVal = CurVal;
263 if (CurVal && !EEState.getGlobalAddressReverseMap().empty())
264 EEState.getGlobalAddressReverseMap().
erase(CurVal);
268 if (!EEState.getGlobalAddressReverseMap().empty()) {
269 std::string &V = EEState.getGlobalAddressReverseMap()[CurVal];
271 "GlobalMapping already established!");
278 std::lock_guard<sys::Mutex> locked(
lock);
281 EEState.getGlobalAddressMap().find(S);
282 if (I != EEState.getGlobalAddressMap().end())
289 std::lock_guard<sys::Mutex> locked(
lock);
296 std::lock_guard<sys::Mutex> locked(
lock);
301 std::lock_guard<sys::Mutex> locked(
lock);
304 if (EEState.getGlobalAddressReverseMap().empty()) {
306 I = EEState.getGlobalAddressMap().begin(),
307 E = EEState.getGlobalAddressMap().end();
I !=
E; ++
I) {
309 uint64_t Addr =
I->second;
310 EEState.getGlobalAddressReverseMap().insert(std::make_pair(
315 std::map<uint64_t, std::string>::iterator
I =
316 EEState.getGlobalAddressReverseMap().find((uint64_t) Addr);
318 if (I != EEState.getGlobalAddressReverseMap().end()) {
320 for (
unsigned i = 0,
e =
Modules.size(); i !=
e; ++i)
329 std::unique_ptr<char[]> Array;
330 std::vector<std::unique_ptr<char[]>> Values;
335 const std::vector<std::string> &InputArgv);
339 const std::vector<std::string> &InputArgv) {
341 Values.reserve(InputArgv.size());
343 Array = std::make_unique<char[]>((InputArgv.size()+1)*PtrSize);
345 LLVM_DEBUG(
dbgs() <<
"JIT: ARGV = " << (
void *)Array.get() <<
"\n");
348 for (
unsigned i = 0; i != InputArgv.size(); ++i) {
349 unsigned Size = InputArgv[i].size()+1;
350 auto Dest = std::make_unique<char[]>(
Size);
351 LLVM_DEBUG(
dbgs() <<
"JIT: ARGV[" << i <<
"] = " << (
void *)Dest.get()
360 Values.push_back(std::move(Dest));
372 StringRef Name(isDtors ?
"llvm.global_dtors" :
"llvm.global_ctors");
397 FP = CE->getOperand(0);
400 if (
Function *
F = dyn_cast<Function>(FP))
411 for (std::unique_ptr<Module> &M :
Modules)
419 for (
unsigned i = 0; i < PtrSize; ++i)
420 if (*(i + (uint8_t*)Loc))
427 const std::vector<std::string> &argv,
428 const char *
const * envp) {
429 std::vector<GenericValue> GVArgs;
454 GVArgs.push_back(GVArgc);
459 "argv[0] was null after CreateArgv");
461 std::vector<std::string> EnvVars;
462 for (
unsigned i = 0; envp[i]; ++i)
463 EnvVars.emplace_back(envp[i]);
476 : M(
std::move(M)), WhichEngine(EngineKind::
Either), ErrorStr(nullptr),
478 UseOrcMCJITReplacement(
false) {
482 VerifyModules =
true;
484 VerifyModules =
false;
491 std::unique_ptr<RTDyldMemoryManager> mcjmm) {
492 auto SharedMM = std::shared_ptr<RTDyldMemoryManager>(std::move(mcjmm));
500 MemMgr = std::shared_ptr<MCJITMemoryManager>(std::move(MM));
506 Resolver = std::shared_ptr<LegacyJITSymbolResolver>(std::move(SR));
511 std::unique_ptr<TargetMachine> TheTM(TM);
526 *ErrorStr =
"Cannot create an interpreter with a memory manager.";
535 errs() <<
"WARNING: This target JIT is not designed for the host" 536 <<
" you are running. If bad things happen, please choose" 537 <<
" a different -march switch.\n";
548 std::move(
Resolver), std::move(TheTM));
562 *ErrorStr =
"Interpreter has not been linked in.";
568 *ErrorStr =
"JIT has not been linked in.";
575 if (
Function *
F = const_cast<Function*>(dyn_cast<Function>(GV)))
576 return getPointerToFunction(
F);
578 std::lock_guard<sys::Mutex> locked(lock);
579 if (
void*
P = getPointerToGlobalIfAvailable(GV))
584 const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
585 EmitGlobalVariable(GVar);
589 return getPointerToGlobalIfAvailable(GV);
596 if (isa<UndefValue>(C)) {
612 unsigned int elemNum = STy->getNumElements();
614 for (
unsigned int i = 0; i < elemNum; ++i) {
615 Type *ElemTy = STy->getElementType(i);
629 auto* VTy = cast<VectorType>(C->
getType());
630 Type *ElemTy = VTy->getElementType();
631 unsigned int elemNum = VTy->getNumElements();
633 if (ElemTy->isIntegerTy())
634 for (
unsigned int i = 0; i < elemNum; ++i)
636 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
643 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
645 switch (CE->getOpcode()) {
646 case Instruction::GetElementPtr: {
650 cast<GEPOperator>(CE)->accumulateConstantOffset(DL,
Offset);
656 case Instruction::Trunc: {
662 case Instruction::ZExt: {
668 case Instruction::SExt: {
674 case Instruction::FPTrunc: {
680 case Instruction::FPExt:{
686 case Instruction::UIToFP: {
688 if (CE->getType()->isFloatTy())
690 else if (CE->getType()->isDoubleTy())
692 else if (CE->getType()->isX86_FP80Ty()) {
701 case Instruction::SIToFP: {
703 if (CE->getType()->isFloatTy())
705 else if (CE->getType()->isDoubleTy())
707 else if (CE->getType()->isX86_FP80Ty()) {
716 case Instruction::FPToUI:
717 case Instruction::FPToSI: {
729 CE->getOpcode()==Instruction::FPToSI,
735 case Instruction::PtrToInt: {
738 assert(PtrWidth <= 64 &&
"Bad pointer width");
740 uint32_t IntWidth = DL.getTypeSizeInBits(CE->getType());
744 case Instruction::IntToPtr: {
746 uint32_t PtrWidth = DL.getTypeSizeInBits(CE->getType());
752 case Instruction::BitCast: {
754 Type* DestTy = CE->getType();
779 case Instruction::FAdd:
780 case Instruction::Sub:
781 case Instruction::FSub:
782 case Instruction::Mul:
783 case Instruction::FMul:
784 case Instruction::UDiv:
785 case Instruction::SDiv:
786 case Instruction::URem:
787 case Instruction::SRem:
788 case Instruction::And:
789 case Instruction::Or:
790 case Instruction::Xor: {
794 switch (CE->getOperand(0)->getType()->getTypeID()) {
797 switch (CE->getOpcode()) {
800 case Instruction::Sub: GV.IntVal = LHS.
IntVal - RHS.
IntVal;
break;
801 case Instruction::Mul: GV.IntVal = LHS.
IntVal * RHS.
IntVal;
break;
806 case Instruction::And: GV.IntVal = LHS.
IntVal & RHS.
IntVal;
break;
807 case Instruction::Or: GV.IntVal = LHS.
IntVal | RHS.
IntVal;
break;
808 case Instruction::Xor: GV.IntVal = LHS.
IntVal ^ RHS.
IntVal;
break;
812 switch (CE->getOpcode()) {
814 case Instruction::FAdd:
816 case Instruction::FSub:
818 case Instruction::FMul:
820 case Instruction::FDiv:
822 case Instruction::FRem:
827 switch (CE->getOpcode()) {
829 case Instruction::FAdd:
831 case Instruction::FSub:
833 case Instruction::FMul:
835 case Instruction::FDiv:
837 case Instruction::FRem:
844 const fltSemantics &Sem = CE->getOperand(0)->getType()->getFltSemantics();
846 switch (CE->getOpcode()) {
848 case Instruction::FAdd:
852 case Instruction::FSub:
857 case Instruction::FMul:
862 case Instruction::FDiv:
867 case Instruction::FRem:
883 OS <<
"ConstantExpr not handled: " << *CE;
891 Result.FloatVal = cast<ConstantFP>(
C)->getValueAPF().convertToFloat();
894 Result.DoubleVal = cast<ConstantFP>(
C)->getValueAPF().convertToDouble();
899 Result.IntVal = cast <ConstantFP>(
C)->getValueAPF().bitcastToAPInt();
902 Result.IntVal = cast<ConstantInt>(
C)->getValue();
905 while (
auto *A = dyn_cast<GlobalAlias>(C)) {
908 if (isa<ConstantPointerNull>(C))
909 Result.PointerVal =
nullptr;
910 else if (
const Function *
F = dyn_cast<Function>(C))
911 Result =
PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(
F)));
913 Result =
PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
927 }
else if (CV || CAZ) {
928 auto* VTy = cast<VectorType>(C->
getType());
929 elemNum = VTy->getNumElements();
930 ElemTy = VTy->getElementType();
935 Result.AggregateVal.resize(elemNum);
941 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
946 for (
unsigned i = 0; i < elemNum; ++i)
947 if (!isa<UndefValue>(CV->getOperand(i)))
948 Result.AggregateVal[i].FloatVal = cast<ConstantFP>(
949 CV->getOperand(i))->getValueAPF().convertToFloat();
953 for (
unsigned i = 0; i < elemNum; ++i)
963 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
968 for (
unsigned i = 0; i < elemNum; ++i)
969 if (!isa<UndefValue>(CV->getOperand(i)))
970 Result.AggregateVal[i].DoubleVal = cast<ConstantFP>(
971 CV->getOperand(i))->getValueAPF().convertToDouble();
975 for (
unsigned i = 0; i < elemNum; ++i)
985 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
990 for (
unsigned i = 0; i < elemNum; ++i)
991 if (!isa<UndefValue>(CV->getOperand(i)))
992 Result.AggregateVal[i].IntVal = cast<ConstantInt>(
993 CV->getOperand(i))->getValue();
995 Result.AggregateVal[i].IntVal =
996 APInt(CV->getOperand(i)->getType()->getPrimitiveSizeInBits(), 0);
1001 for (
unsigned i = 0; i < elemNum; ++i)
1002 Result.AggregateVal[i].IntVal =
APInt(
1015 OS <<
"ERROR: Constant unimplemented for type: " << *C->
getType();
1024 const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
1028 dbgs() <<
"Cannot store value of type " << *Ty <<
"!\n";
1045 memset(&(Ptr->PointerVal), 0, StoreBytes);
1050 for (
unsigned i = 0; i < Val.
AggregateVal.size(); ++i) {
1051 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
1053 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
1055 if (cast<VectorType>(Ty)->getElementType()->isIntegerTy()) {
1056 unsigned numOfBytes =(Val.
AggregateVal[i].IntVal.getBitWidth()+7)/8;
1058 (uint8_t*)Ptr + numOfBytes*i, numOfBytes);
1066 std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
1074 const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty);
1100 auto *VT = cast<VectorType>(Ty);
1101 Type *ElemT = VT->getElementType();
1102 const unsigned numElems = VT->getNumElements();
1103 if (ElemT->isFloatTy()) {
1105 for (
unsigned i = 0; i < numElems; ++i)
1108 if (ElemT->isDoubleTy()) {
1110 for (
unsigned i = 0; i < numElems; ++i)
1113 if (ElemT->isIntegerTy()) {
1115 const unsigned elemBitWidth = cast<IntegerType>(ElemT)->
getBitWidth();
1118 for (
unsigned i = 0; i < numElems; ++i)
1120 (uint8_t*)Ptr+((elemBitWidth+7)/8)*i, (elemBitWidth+7)/8);
1127 OS <<
"Cannot load value of type " << *Ty <<
"!";
1135 if (isa<UndefValue>(Init))
1139 unsigned ElementSize =
1140 getDataLayout().getTypeAllocSize(
CP->getType()->getElementType());
1141 for (
unsigned i = 0,
e =
CP->getNumOperands(); i !=
e; ++i)
1142 InitializeMemory(
CP->getOperand(i), (
char*)Addr+i*ElementSize);
1146 if (isa<ConstantAggregateZero>(Init)) {
1147 memset(Addr, 0, (
size_t)getDataLayout().getTypeAllocSize(Init->
getType()));
1151 if (
const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
1152 unsigned ElementSize =
1153 getDataLayout().getTypeAllocSize(CPA->getType()->getElementType());
1154 for (
unsigned i = 0,
e = CPA->getNumOperands(); i !=
e; ++i)
1155 InitializeMemory(CPA->getOperand(i), (
char*)Addr+i*ElementSize);
1159 if (
const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
1161 getDataLayout().getStructLayout(cast<StructType>(CPS->getType()));
1162 for (
unsigned i = 0,
e = CPS->getNumOperands(); i !=
e; ++i)
1168 dyn_cast<ConstantDataSequential>(Init)) {
1171 memcpy(Addr, Data.
data(), Data.
size());
1192 std::map<std::pair<std::string, Type*>,
1195 if (Modules.size() != 1) {
1196 for (
unsigned m = 0,
e = Modules.size(); m !=
e; ++m) {
1198 for (
const auto &GV : M.
globals()) {
1199 if (GV.hasLocalLinkage() || GV.isDeclaration() ||
1200 GV.hasAppendingLinkage() || !GV.hasName())
1204 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())];
1225 std::vector<const GlobalValue*> NonCanonicalGlobals;
1226 for (
unsigned m = 0,
e = Modules.size(); m !=
e; ++m) {
1228 for (
const auto &GV : M.
globals()) {
1230 if (!LinkedGlobalsMap.empty()) {
1232 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())]) {
1234 if (GVEntry != &GV) {
1235 NonCanonicalGlobals.push_back(&GV);
1241 if (!GV.isDeclaration()) {
1242 addGlobalMapping(&GV, getMemoryForGV(&GV));
1248 addGlobalMapping(&GV, SymAddr);
1258 if (!NonCanonicalGlobals.empty()) {
1259 for (
unsigned i = 0,
e = NonCanonicalGlobals.size(); i !=
e; ++i) {
1263 void *Ptr = getPointerToGlobalIfAvailable(CGV);
1264 assert(Ptr &&
"Canonical global wasn't codegen'd!");
1265 addGlobalMapping(GV, Ptr);
1271 for (
const auto &GV : M.
globals()) {
1272 if (!GV.isDeclaration()) {
1273 if (!LinkedGlobalsMap.empty()) {
1275 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())])
1279 EmitGlobalVariable(&GV);
1289 void *GA = getPointerToGlobalIfAvailable(GV);
1293 GA = getMemoryForGV(GV);
1298 addGlobalMapping(GV, GA);
1306 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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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.
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)
APInt trunc(unsigned width) const
Truncate to new width.
STATISTIC(NumFunctions, "Total number of functions")
4: 80-bit floating point type (X87)
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.
unsigned getBitWidth() const
Return the number of bits in the APInt.
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...
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.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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...
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 size_t size() const
size - Get the string size.
opStatus subtract(const APFloat &RHS, roundingMode RM)
GenericValue getConstantValue(const Constant *C)
Converts a Constant* into a GenericValue, including handling of ConstantExpr values.
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...
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.
void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes)
LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting from Src into IntVal...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
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.
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.
virtual ~ExecutionEngine()
opStatus add(const APFloat &RHS, roundingMode RM)
ExecutionEngine * create()
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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 float.
3: 64-bit floating point type
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionCreator LazyFunctionCreator
LazyFunctionCreator - If an unknown function is needed, this function pointer is invoked to create it...
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.
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
iterator_range< global_iterator > globals()
iterator_range< global_object_iterator > global_objects()
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)