|
@@ -61,8 +61,7 @@ ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
|
|
|
|
|
|
void JITEventListener::anchor() {}
|
|
void JITEventListener::anchor() {}
|
|
|
|
|
|
-ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
|
|
|
|
- : LazyFunctionCreator(nullptr) {
|
|
|
|
|
|
+void ExecutionEngine::Init(std::unique_ptr<Module> M) {
|
|
CompilingLazily = false;
|
|
CompilingLazily = false;
|
|
GVCompilationDisabled = false;
|
|
GVCompilationDisabled = false;
|
|
SymbolSearchingDisabled = false;
|
|
SymbolSearchingDisabled = false;
|
|
@@ -79,6 +78,16 @@ ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
|
|
Modules.push_back(std::move(M));
|
|
Modules.push_back(std::move(M));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
|
|
|
|
+ : DL(M->getDataLayout()), LazyFunctionCreator(nullptr) {
|
|
|
|
+ Init(std::move(M));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+ExecutionEngine::ExecutionEngine(DataLayout DL, std::unique_ptr<Module> M)
|
|
|
|
+ : DL(std::move(DL)), LazyFunctionCreator(nullptr) {
|
|
|
|
+ Init(std::move(M));
|
|
|
|
+}
|
|
|
|
+
|
|
ExecutionEngine::~ExecutionEngine() {
|
|
ExecutionEngine::~ExecutionEngine() {
|
|
clearAllGlobalMappings();
|
|
clearAllGlobalMappings();
|
|
}
|
|
}
|
|
@@ -115,7 +124,7 @@ public:
|
|
} // anonymous namespace
|
|
} // anonymous namespace
|
|
|
|
|
|
char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
|
|
char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
|
|
- return GVMemoryBlock::Create(GV, *getDataLayout());
|
|
|
|
|
|
+ return GVMemoryBlock::Create(GV, getDataLayout());
|
|
}
|
|
}
|
|
|
|
|
|
void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) {
|
|
void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) {
|
|
@@ -326,7 +335,7 @@ void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
|
|
const std::vector<std::string> &InputArgv) {
|
|
const std::vector<std::string> &InputArgv) {
|
|
Values.clear(); // Free the old contents.
|
|
Values.clear(); // Free the old contents.
|
|
Values.reserve(InputArgv.size());
|
|
Values.reserve(InputArgv.size());
|
|
- unsigned PtrSize = EE->getDataLayout()->getPointerSize();
|
|
|
|
|
|
+ unsigned PtrSize = EE->getDataLayout().getPointerSize();
|
|
Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
|
|
Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
|
|
|
|
|
|
DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
|
|
DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
|
|
@@ -401,7 +410,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
|
|
#ifndef NDEBUG
|
|
#ifndef NDEBUG
|
|
/// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
|
|
/// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
|
|
static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
|
|
static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
|
|
- unsigned PtrSize = EE->getDataLayout()->getPointerSize();
|
|
|
|
|
|
+ unsigned PtrSize = EE->getDataLayout().getPointerSize();
|
|
for (unsigned i = 0; i < PtrSize; ++i)
|
|
for (unsigned i = 0; i < PtrSize; ++i)
|
|
if (*(i + (uint8_t*)Loc))
|
|
if (*(i + (uint8_t*)Loc))
|
|
return false;
|
|
return false;
|
|
@@ -634,8 +643,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
|
case Instruction::GetElementPtr: {
|
|
case Instruction::GetElementPtr: {
|
|
// Compute the index
|
|
// Compute the index
|
|
GenericValue Result = getConstantValue(Op0);
|
|
GenericValue Result = getConstantValue(Op0);
|
|
- APInt Offset(DL->getPointerSizeInBits(), 0);
|
|
|
|
- cast<GEPOperator>(CE)->accumulateConstantOffset(*DL, Offset);
|
|
|
|
|
|
+ APInt Offset(DL.getPointerSizeInBits(), 0);
|
|
|
|
+ cast<GEPOperator>(CE)->accumulateConstantOffset(DL, Offset);
|
|
|
|
|
|
char* tmp = (char*) Result.PointerVal;
|
|
char* tmp = (char*) Result.PointerVal;
|
|
Result = PTOGV(tmp + Offset.getSExtValue());
|
|
Result = PTOGV(tmp + Offset.getSExtValue());
|
|
@@ -722,16 +731,16 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
|
}
|
|
}
|
|
case Instruction::PtrToInt: {
|
|
case Instruction::PtrToInt: {
|
|
GenericValue GV = getConstantValue(Op0);
|
|
GenericValue GV = getConstantValue(Op0);
|
|
- uint32_t PtrWidth = DL->getTypeSizeInBits(Op0->getType());
|
|
|
|
|
|
+ uint32_t PtrWidth = DL.getTypeSizeInBits(Op0->getType());
|
|
assert(PtrWidth <= 64 && "Bad pointer width");
|
|
assert(PtrWidth <= 64 && "Bad pointer width");
|
|
GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
|
|
GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
|
|
- uint32_t IntWidth = DL->getTypeSizeInBits(CE->getType());
|
|
|
|
|
|
+ uint32_t IntWidth = DL.getTypeSizeInBits(CE->getType());
|
|
GV.IntVal = GV.IntVal.zextOrTrunc(IntWidth);
|
|
GV.IntVal = GV.IntVal.zextOrTrunc(IntWidth);
|
|
return GV;
|
|
return GV;
|
|
}
|
|
}
|
|
case Instruction::IntToPtr: {
|
|
case Instruction::IntToPtr: {
|
|
GenericValue GV = getConstantValue(Op0);
|
|
GenericValue GV = getConstantValue(Op0);
|
|
- uint32_t PtrWidth = DL->getTypeSizeInBits(CE->getType());
|
|
|
|
|
|
+ uint32_t PtrWidth = DL.getTypeSizeInBits(CE->getType());
|
|
GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
|
|
GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
|
|
assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
|
|
assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
|
|
GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
|
|
GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
|
|
@@ -1033,7 +1042,7 @@ static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
|
|
|
|
|
|
void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
|
|
void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
|
|
GenericValue *Ptr, Type *Ty) {
|
|
GenericValue *Ptr, Type *Ty) {
|
|
- const unsigned StoreBytes = getDataLayout()->getTypeStoreSize(Ty);
|
|
|
|
|
|
+ const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
|
|
|
|
|
|
switch (Ty->getTypeID()) {
|
|
switch (Ty->getTypeID()) {
|
|
default:
|
|
default:
|
|
@@ -1073,7 +1082,7 @@ void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (sys::IsLittleEndianHost != getDataLayout()->isLittleEndian())
|
|
|
|
|
|
+ if (sys::IsLittleEndianHost != getDataLayout().isLittleEndian())
|
|
// Host and target are different endian - reverse the stored bytes.
|
|
// Host and target are different endian - reverse the stored bytes.
|
|
std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
|
|
std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
|
|
}
|
|
}
|
|
@@ -1110,7 +1119,7 @@ static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
|
|
void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
|
|
void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
|
|
GenericValue *Ptr,
|
|
GenericValue *Ptr,
|
|
Type *Ty) {
|
|
Type *Ty) {
|
|
- const unsigned LoadBytes = getDataLayout()->getTypeStoreSize(Ty);
|
|
|
|
|
|
+ const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty);
|
|
|
|
|
|
switch (Ty->getTypeID()) {
|
|
switch (Ty->getTypeID()) {
|
|
case Type::IntegerTyID:
|
|
case Type::IntegerTyID:
|
|
@@ -1176,20 +1185,20 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
|
|
|
|
|
|
if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
|
|
if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
|
|
unsigned ElementSize =
|
|
unsigned ElementSize =
|
|
- getDataLayout()->getTypeAllocSize(CP->getType()->getElementType());
|
|
|
|
|
|
+ getDataLayout().getTypeAllocSize(CP->getType()->getElementType());
|
|
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
|
|
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
|
|
InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
|
|
InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if (isa<ConstantAggregateZero>(Init)) {
|
|
if (isa<ConstantAggregateZero>(Init)) {
|
|
- memset(Addr, 0, (size_t)getDataLayout()->getTypeAllocSize(Init->getType()));
|
|
|
|
|
|
+ memset(Addr, 0, (size_t)getDataLayout().getTypeAllocSize(Init->getType()));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
|
|
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
|
|
unsigned ElementSize =
|
|
unsigned ElementSize =
|
|
- getDataLayout()->getTypeAllocSize(CPA->getType()->getElementType());
|
|
|
|
|
|
+ getDataLayout().getTypeAllocSize(CPA->getType()->getElementType());
|
|
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
|
|
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
|
|
InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
|
|
InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
|
|
return;
|
|
return;
|
|
@@ -1197,7 +1206,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
|
|
|
|
|
|
if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
|
|
if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
|
|
const StructLayout *SL =
|
|
const StructLayout *SL =
|
|
- getDataLayout()->getStructLayout(cast<StructType>(CPS->getType()));
|
|
|
|
|
|
+ getDataLayout().getStructLayout(cast<StructType>(CPS->getType()));
|
|
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
|
|
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
|
|
InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
|
|
InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
|
|
return;
|
|
return;
|
|
@@ -1342,7 +1351,7 @@ void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
|
|
InitializeMemory(GV->getInitializer(), GA);
|
|
InitializeMemory(GV->getInitializer(), GA);
|
|
|
|
|
|
Type *ElTy = GV->getType()->getElementType();
|
|
Type *ElTy = GV->getType()->getElementType();
|
|
- size_t GVSize = (size_t)getDataLayout()->getTypeAllocSize(ElTy);
|
|
|
|
|
|
+ size_t GVSize = (size_t)getDataLayout().getTypeAllocSize(ElTy);
|
|
NumInitBytes += (unsigned)GVSize;
|
|
NumInitBytes += (unsigned)GVSize;
|
|
++NumGlobals;
|
|
++NumGlobals;
|
|
}
|
|
}
|