Make ExecutionEngine owning a DataLayout

Summary:
This change is part of a series of commits dedicated to have a single
DataLayout during compilation by using always the one owned by the
module.

The ExecutionEngine will act as an exception and will be unsafe to
be reused across context. We don't enforce this rule but undefined
behavior can occurs if the user tries to do it.

Reviewers: lhames

Subscribers: echristo, llvm-commits, rafael, yaron.keren

Differential Revision: http://reviews.llvm.org/D11110

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242387 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini
2015-07-16 06:17:14 +00:00
parent 9c5961b7ba
commit eaeb380a9f
9 changed files with 61 additions and 55 deletions

View File

@@ -104,7 +104,12 @@ class ExecutionEngine {
ExecutionEngineState EEState;
/// The target data for the platform for which execution is being performed.
const DataLayout *DL;
///
/// Note: the DataLayout is LLVMContext specific because it has an
/// internal cache based on type pointers. It makes unsafe to reuse the
/// ExecutionEngine across context, we don't enforce this rule but undefined
/// behavior can occurs if the user tries to do it.
const DataLayout DL;
/// Whether lazy JIT compilation is enabled.
bool CompilingLazily;
@@ -126,8 +131,6 @@ protected:
/// optimize for the case where there is only one module.
SmallVector<std::unique_ptr<Module>, 1> Modules;
void setDataLayout(const DataLayout *Val) { DL = Val; }
/// getMemoryforGV - Allocate memory for a global variable.
virtual char *getMemoryForGV(const GlobalVariable *GV);
@@ -194,7 +197,7 @@ public:
//===--------------------------------------------------------------------===//
const DataLayout *getDataLayout() const { return DL; }
const DataLayout &getDataLayout() const { return DL; }
/// removeModule - Remove a Module from the list of modules. Returns true if
/// M is found.
@@ -478,8 +481,8 @@ public:
}
protected:
ExecutionEngine() {}
explicit ExecutionEngine(std::unique_ptr<Module> M);
ExecutionEngine(const DataLayout DL) : DL(std::move(DL)){};
explicit ExecutionEngine(const DataLayout DL, std::unique_ptr<Module> M);
void emitGlobals();