Skip to content

Commit 8c3b4f2

Browse files
author
Michael Kuperstein
committed
Revert "Make ExecutionEngine owning a DataLayout"
Reverting to fix buildbot breakage. This reverts commit r242387. llvm-svn: 242394
1 parent 7d54fab commit 8c3b4f2

File tree

9 files changed

+55
-61
lines changed

9 files changed

+55
-61
lines changed

llvm/include/llvm/ExecutionEngine/ExecutionEngine.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ class ExecutionEngine {
104104
ExecutionEngineState EEState;
105105

106106
/// The target data for the platform for which execution is being performed.
107-
///
108-
/// Note: the DataLayout is LLVMContext specific because it has an
109-
/// internal cache based on type pointers. It makes unsafe to reuse the
110-
/// ExecutionEngine across context, we don't enforce this rule but undefined
111-
/// behavior can occurs if the user tries to do it.
112-
const DataLayout DL;
107+
const DataLayout *DL;
113108

114109
/// Whether lazy JIT compilation is enabled.
115110
bool CompilingLazily;
@@ -131,6 +126,8 @@ class ExecutionEngine {
131126
/// optimize for the case where there is only one module.
132127
SmallVector<std::unique_ptr<Module>, 1> Modules;
133128

129+
void setDataLayout(const DataLayout *Val) { DL = Val; }
130+
134131
/// getMemoryforGV - Allocate memory for a global variable.
135132
virtual char *getMemoryForGV(const GlobalVariable *GV);
136133

@@ -197,7 +194,7 @@ class ExecutionEngine {
197194

198195
//===--------------------------------------------------------------------===//
199196

200-
const DataLayout &getDataLayout() const { return DL; }
197+
const DataLayout *getDataLayout() const { return DL; }
201198

202199
/// removeModule - Remove a Module from the list of modules. Returns true if
203200
/// M is found.
@@ -481,8 +478,8 @@ class ExecutionEngine {
481478
}
482479

483480
protected:
484-
ExecutionEngine(const DataLayout DL) : DL(std::move(DL)){};
485-
explicit ExecutionEngine(const DataLayout DL, std::unique_ptr<Module> M);
481+
ExecutionEngine() {}
482+
explicit ExecutionEngine(std::unique_ptr<Module> M);
486483

487484
void emitGlobals();
488485

llvm/lib/ExecutionEngine/ExecutionEngine.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
6161

6262
void JITEventListener::anchor() {}
6363

64-
ExecutionEngine::ExecutionEngine(const DataLayout DL, std::unique_ptr<Module> M)
65-
: DL(std::move(DL)), LazyFunctionCreator(nullptr) {
64+
ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
65+
: LazyFunctionCreator(nullptr) {
6666
CompilingLazily = false;
6767
GVCompilationDisabled = false;
6868
SymbolSearchingDisabled = false;
@@ -115,7 +115,7 @@ class GVMemoryBlock : public CallbackVH {
115115
} // anonymous namespace
116116

117117
char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
118-
return GVMemoryBlock::Create(GV, getDataLayout());
118+
return GVMemoryBlock::Create(GV, *getDataLayout());
119119
}
120120

121121
void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) {
@@ -326,7 +326,7 @@ void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
326326
const std::vector<std::string> &InputArgv) {
327327
Values.clear(); // Free the old contents.
328328
Values.reserve(InputArgv.size());
329-
unsigned PtrSize = EE->getDataLayout().getPointerSize();
329+
unsigned PtrSize = EE->getDataLayout()->getPointerSize();
330330
Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
331331

332332
DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
@@ -401,7 +401,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
401401
#ifndef NDEBUG
402402
/// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
403403
static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
404-
unsigned PtrSize = EE->getDataLayout().getPointerSize();
404+
unsigned PtrSize = EE->getDataLayout()->getPointerSize();
405405
for (unsigned i = 0; i < PtrSize; ++i)
406406
if (*(i + (uint8_t*)Loc))
407407
return false;
@@ -634,8 +634,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
634634
case Instruction::GetElementPtr: {
635635
// Compute the index
636636
GenericValue Result = getConstantValue(Op0);
637-
APInt Offset(DL.getPointerSizeInBits(), 0);
638-
cast<GEPOperator>(CE)->accumulateConstantOffset(DL, Offset);
637+
APInt Offset(DL->getPointerSizeInBits(), 0);
638+
cast<GEPOperator>(CE)->accumulateConstantOffset(*DL, Offset);
639639

640640
char* tmp = (char*) Result.PointerVal;
641641
Result = PTOGV(tmp + Offset.getSExtValue());
@@ -722,16 +722,16 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
722722
}
723723
case Instruction::PtrToInt: {
724724
GenericValue GV = getConstantValue(Op0);
725-
uint32_t PtrWidth = DL.getTypeSizeInBits(Op0->getType());
725+
uint32_t PtrWidth = DL->getTypeSizeInBits(Op0->getType());
726726
assert(PtrWidth <= 64 && "Bad pointer width");
727727
GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
728-
uint32_t IntWidth = DL.getTypeSizeInBits(CE->getType());
728+
uint32_t IntWidth = DL->getTypeSizeInBits(CE->getType());
729729
GV.IntVal = GV.IntVal.zextOrTrunc(IntWidth);
730730
return GV;
731731
}
732732
case Instruction::IntToPtr: {
733733
GenericValue GV = getConstantValue(Op0);
734-
uint32_t PtrWidth = DL.getTypeSizeInBits(CE->getType());
734+
uint32_t PtrWidth = DL->getTypeSizeInBits(CE->getType());
735735
GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
736736
assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
737737
GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
@@ -1033,7 +1033,7 @@ static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
10331033

10341034
void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
10351035
GenericValue *Ptr, Type *Ty) {
1036-
const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
1036+
const unsigned StoreBytes = getDataLayout()->getTypeStoreSize(Ty);
10371037

10381038
switch (Ty->getTypeID()) {
10391039
default:
@@ -1073,7 +1073,7 @@ void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
10731073
break;
10741074
}
10751075

1076-
if (sys::IsLittleEndianHost != getDataLayout().isLittleEndian())
1076+
if (sys::IsLittleEndianHost != getDataLayout()->isLittleEndian())
10771077
// Host and target are different endian - reverse the stored bytes.
10781078
std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
10791079
}
@@ -1110,7 +1110,7 @@ static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
11101110
void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
11111111
GenericValue *Ptr,
11121112
Type *Ty) {
1113-
const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty);
1113+
const unsigned LoadBytes = getDataLayout()->getTypeStoreSize(Ty);
11141114

11151115
switch (Ty->getTypeID()) {
11161116
case Type::IntegerTyID:
@@ -1176,28 +1176,28 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
11761176

11771177
if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
11781178
unsigned ElementSize =
1179-
getDataLayout().getTypeAllocSize(CP->getType()->getElementType());
1179+
getDataLayout()->getTypeAllocSize(CP->getType()->getElementType());
11801180
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
11811181
InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
11821182
return;
11831183
}
11841184

11851185
if (isa<ConstantAggregateZero>(Init)) {
1186-
memset(Addr, 0, (size_t)getDataLayout().getTypeAllocSize(Init->getType()));
1186+
memset(Addr, 0, (size_t)getDataLayout()->getTypeAllocSize(Init->getType()));
11871187
return;
11881188
}
11891189

11901190
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
11911191
unsigned ElementSize =
1192-
getDataLayout().getTypeAllocSize(CPA->getType()->getElementType());
1192+
getDataLayout()->getTypeAllocSize(CPA->getType()->getElementType());
11931193
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
11941194
InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
11951195
return;
11961196
}
11971197

11981198
if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
11991199
const StructLayout *SL =
1200-
getDataLayout().getStructLayout(cast<StructType>(CPS->getType()));
1200+
getDataLayout()->getStructLayout(cast<StructType>(CPS->getType()));
12011201
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
12021202
InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
12031203
return;
@@ -1342,7 +1342,7 @@ void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
13421342
InitializeMemory(GV->getInitializer(), GA);
13431343

13441344
Type *ElTy = GV->getType()->getElementType();
1345-
size_t GVSize = (size_t)getDataLayout().getTypeAllocSize(ElTy);
1345+
size_t GVSize = (size_t)getDataLayout()->getTypeAllocSize(ElTy);
13461346
NumInitBytes += (unsigned)GVSize;
13471347
++NumGlobals;
13481348
}

llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
318318
}
319319

320320
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
321-
return wrap(&unwrap(EE)->getDataLayout());
321+
return wrap(unwrap(EE)->getDataLayout());
322322
}
323323

324324
LLVMTargetMachineRef

llvm/lib/ExecutionEngine/Interpreter/Execution.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ void Interpreter::visitAllocaInst(AllocaInst &I) {
968968
unsigned NumElements =
969969
getOperandValue(I.getOperand(0), SF).IntVal.getZExtValue();
970970

971-
unsigned TypeSize = (size_t)getDataLayout().getTypeAllocSize(Ty);
971+
unsigned TypeSize = (size_t)TD.getTypeAllocSize(Ty);
972972

973973
// Avoid malloc-ing zero bytes, use max()...
974974
unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
@@ -1000,7 +1000,7 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
10001000

10011001
for (; I != E; ++I) {
10021002
if (StructType *STy = dyn_cast<StructType>(*I)) {
1003-
const StructLayout *SLO = getDataLayout().getStructLayout(STy);
1003+
const StructLayout *SLO = TD.getStructLayout(STy);
10041004

10051005
const ConstantInt *CPU = cast<ConstantInt>(I.getOperand());
10061006
unsigned Index = unsigned(CPU->getZExtValue());
@@ -1020,7 +1020,7 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
10201020
assert(BitWidth == 64 && "Invalid index type for getelementptr");
10211021
Idx = (int64_t)IdxGV.IntVal.getZExtValue();
10221022
}
1023-
Total += getDataLayout().getTypeAllocSize(ST->getElementType()) * Idx;
1023+
Total += TD.getTypeAllocSize(ST->getElementType())*Idx;
10241024
}
10251025
}
10261026

@@ -1477,7 +1477,7 @@ GenericValue Interpreter::executeIntToPtrInst(Value *SrcVal, Type *DstTy,
14771477
GenericValue Dest, Src = getOperandValue(SrcVal, SF);
14781478
assert(DstTy->isPointerTy() && "Invalid PtrToInt instruction");
14791479

1480-
uint32_t PtrSize = getDataLayout().getPointerSizeInBits();
1480+
uint32_t PtrSize = TD.getPointerSizeInBits();
14811481
if (PtrSize != Src.IntVal.getBitWidth())
14821482
Src.IntVal = Src.IntVal.zextOrTrunc(PtrSize);
14831483

@@ -1497,7 +1497,7 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, Type *DstTy,
14971497
(DstTy->getTypeID() == Type::VectorTyID)) {
14981498
// vector src bitcast to vector dst or vector src bitcast to scalar dst or
14991499
// scalar src bitcast to vector dst
1500-
bool isLittleEndian = getDataLayout().isLittleEndian();
1500+
bool isLittleEndian = TD.isLittleEndian();
15011501
GenericValue TempDst, TempSrc, SrcVec;
15021502
const Type *SrcElemTy;
15031503
const Type *DstElemTy;

llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static GenericValue lle_X_sprintf(FunctionType *FT,
368368
case 'x': case 'X':
369369
if (HowLong >= 1) {
370370
if (HowLong == 1 &&
371-
TheInterpreter->getDataLayout().getPointerSizeInBits() == 64 &&
371+
TheInterpreter->getDataLayout()->getPointerSizeInBits() == 64 &&
372372
sizeof(long) < sizeof(int64_t)) {
373373
// Make sure we use %lld with a 64 bit argument because we might be
374374
// compiling LLI on a 32 bit compiler.

llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ ExecutionEngine *Interpreter::create(std::unique_ptr<Module> M,
4949
// Interpreter ctor - Initialize stuff
5050
//
5151
Interpreter::Interpreter(std::unique_ptr<Module> M)
52-
: ExecutionEngine(M->getDataLayout(), std::move(M)) {
52+
: ExecutionEngine(std::move(M)), TD(Modules.back().get()) {
5353

5454
memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped));
55+
setDataLayout(&TD);
5556
// Initialize the "backend"
5657
initializeExecutionEngine();
5758
initializeExternalFunctions();
5859
emitGlobals();
5960

60-
IL = new IntrinsicLowering(getDataLayout());
61+
IL = new IntrinsicLowering(TD);
6162
}
6263

6364
Interpreter::~Interpreter() {

llvm/lib/ExecutionEngine/Interpreter/Interpreter.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct ExecutionContext {
9595
//
9696
class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
9797
GenericValue ExitValue; // The return value of the called function
98+
DataLayout TD;
9899
IntrinsicLowering *IL;
99100

100101
// The runtime stack of executing code. The top of the stack is the current

llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ MCJIT::createJIT(std::unique_ptr<Module> M,
6565
std::move(Resolver));
6666
}
6767

68-
MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> TM,
68+
MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
6969
std::shared_ptr<MCJITMemoryManager> MemMgr,
7070
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver)
71-
: ExecutionEngine(*TM->getDataLayout(), std::move(M)), TM(std::move(TM)),
72-
Ctx(nullptr), MemMgr(std::move(MemMgr)),
73-
Resolver(*this, std::move(Resolver)), Dyld(*this->MemMgr, this->Resolver),
74-
ObjCache(nullptr) {
71+
: ExecutionEngine(std::move(M)), TM(std::move(tm)), Ctx(nullptr),
72+
MemMgr(std::move(MemMgr)), Resolver(*this, std::move(Resolver)),
73+
Dyld(*this->MemMgr, this->Resolver), ObjCache(nullptr) {
7574
// FIXME: We are managing our modules, so we do not want the base class
7675
// ExecutionEngine to manage them as well. To avoid double destruction
7776
// of the first (and only) module added in ExecutionEngine constructor
@@ -86,6 +85,7 @@ MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> TM,
8685
Modules.clear();
8786

8887
OwnedModules.addModule(std::move(First));
88+
setDataLayout(TM->getDataLayout());
8989
RegisterJITEventListener(JITEventListener::createGDBRegistrationListener());
9090
}
9191

@@ -193,11 +193,7 @@ void MCJIT::generateCodeForModule(Module *M) {
193193
if (ObjCache)
194194
ObjectToLoad = ObjCache->getObject(M);
195195

196-
if (M->getDataLayout().isDefault()) {
197-
M->setDataLayout(getDataLayout());
198-
} else {
199-
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
200-
}
196+
M->setDataLayout(*TM->getDataLayout());
201197

202198
// If the cache did not contain a suitable object, compile the object
203199
if (!ObjectToLoad) {
@@ -269,7 +265,7 @@ void MCJIT::finalizeModule(Module *M) {
269265

270266
RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {
271267
SmallString<128> FullName;
272-
Mangler::getNameWithPrefix(FullName, Name, getDataLayout());
268+
Mangler::getNameWithPrefix(FullName, Name, *TM->getDataLayout());
273269
return Dyld.getSymbol(FullName);
274270
}
275271

llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h

+13-14
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,25 @@ class OrcMCJITReplacement : public ExecutionEngine {
137137
}
138138

139139
OrcMCJITReplacement(
140-
std::shared_ptr<MCJITMemoryManager> MemMgr,
141-
std::shared_ptr<RuntimeDyld::SymbolResolver> ClientResolver,
142-
std::unique_ptr<TargetMachine> TM)
143-
: ExecutionEngine(*TM->getDataLayout()), TM(std::move(TM)),
144-
MemMgr(*this, std::move(MemMgr)), Resolver(*this),
145-
ClientResolver(std::move(ClientResolver)), NotifyObjectLoaded(*this),
146-
NotifyFinalized(*this),
140+
std::shared_ptr<MCJITMemoryManager> MemMgr,
141+
std::shared_ptr<RuntimeDyld::SymbolResolver> ClientResolver,
142+
std::unique_ptr<TargetMachine> TM)
143+
: TM(std::move(TM)), MemMgr(*this, std::move(MemMgr)),
144+
Resolver(*this), ClientResolver(std::move(ClientResolver)),
145+
NotifyObjectLoaded(*this), NotifyFinalized(*this),
147146
ObjectLayer(NotifyObjectLoaded, NotifyFinalized),
148147
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
149-
LazyEmitLayer(CompileLayer) {}
148+
LazyEmitLayer(CompileLayer) {
149+
setDataLayout(this->TM->getDataLayout());
150+
}
150151

151152
void addModule(std::unique_ptr<Module> M) override {
152153

153154
// If this module doesn't have a DataLayout attached then attach the
154155
// default.
155-
if (M->getDataLayout().isDefault()) {
156-
M->setDataLayout(getDataLayout());
157-
} else {
158-
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
159-
}
156+
if (M->getDataLayout().isDefault())
157+
M->setDataLayout(*getDataLayout());
158+
160159
Modules.push_back(std::move(M));
161160
std::vector<Module *> Ms;
162161
Ms.push_back(&*Modules.back());
@@ -311,7 +310,7 @@ class OrcMCJITReplacement : public ExecutionEngine {
311310
std::string MangledName;
312311
{
313312
raw_string_ostream MangledNameStream(MangledName);
314-
Mang.getNameWithPrefix(MangledNameStream, Name, getDataLayout());
313+
Mang.getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
315314
}
316315
return MangledName;
317316
}

0 commit comments

Comments
 (0)