Commit 7ccdeedd by Ben Clayton

LLVMJIT: Remove the TargetMachine cache.

TargetMachine have internal fields mutated during compilation. In order to support concurrent implementation, each compile needs a new TargetMachine. Bug: b/153803432 Change-Id: I1a46d8e0193e6176c777d82ce10008afca91ec94 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/44013Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com>
parent cd95ac35
...@@ -75,41 +75,6 @@ extern "C" signed __aeabi_idivmod(); ...@@ -75,41 +75,6 @@ extern "C" signed __aeabi_idivmod();
namespace { namespace {
// Cache provides a simple, thread-safe key-value store.
template<typename KEY, typename VALUE>
class Cache
{
public:
Cache() = default;
Cache(const Cache &other);
VALUE getOrCreate(KEY key, std::function<VALUE()> create);
private:
mutable std::mutex mutex; // mutable required for copy constructor.
std::unordered_map<KEY, VALUE> map;
};
template<typename KEY, typename VALUE>
Cache<KEY, VALUE>::Cache(const Cache &other)
{
std::unique_lock<std::mutex> lock(other.mutex);
map = other.map;
}
template<typename KEY, typename VALUE>
VALUE Cache<KEY, VALUE>::getOrCreate(KEY key, std::function<VALUE()> create)
{
std::unique_lock<std::mutex> lock(mutex);
auto it = map.find(key);
if(it != map.end())
{
return it->second;
}
auto value = create();
map.emplace(key, value);
return value;
}
// JITGlobals is a singleton that holds all the immutable machine specific // JITGlobals is a singleton that holds all the immutable machine specific
// information for the host device. // information for the host device.
class JITGlobals class JITGlobals
...@@ -125,7 +90,7 @@ public: ...@@ -125,7 +90,7 @@ public:
const llvm::TargetOptions targetOptions; const llvm::TargetOptions targetOptions;
const llvm::DataLayout dataLayout; const llvm::DataLayout dataLayout;
TargetMachineSPtr getTargetMachine(rr::Optimization::Level optlevel); TargetMachineSPtr createTargetMachine(rr::Optimization::Level optlevel);
private: private:
static JITGlobals create(); static JITGlobals create();
...@@ -136,8 +101,6 @@ private: ...@@ -136,8 +101,6 @@ private:
const llvm::TargetOptions &targetOptions, const llvm::TargetOptions &targetOptions,
const llvm::DataLayout &dataLayout); const llvm::DataLayout &dataLayout);
JITGlobals(const JITGlobals &) = default; JITGlobals(const JITGlobals &) = default;
Cache<rr::Optimization::Level, TargetMachineSPtr> targetMachines;
}; };
JITGlobals *JITGlobals::get() JITGlobals *JITGlobals::get()
...@@ -146,7 +109,7 @@ JITGlobals *JITGlobals::get() ...@@ -146,7 +109,7 @@ JITGlobals *JITGlobals::get()
return &instance; return &instance;
} }
JITGlobals::TargetMachineSPtr JITGlobals::getTargetMachine(rr::Optimization::Level optlevel) JITGlobals::TargetMachineSPtr JITGlobals::createTargetMachine(rr::Optimization::Level optlevel)
{ {
#ifdef ENABLE_RR_DEBUG_INFO #ifdef ENABLE_RR_DEBUG_INFO
auto llvmOptLevel = toLLVM(rr::Optimization::Level::None); auto llvmOptLevel = toLLVM(rr::Optimization::Level::None);
...@@ -154,15 +117,13 @@ JITGlobals::TargetMachineSPtr JITGlobals::getTargetMachine(rr::Optimization::Lev ...@@ -154,15 +117,13 @@ JITGlobals::TargetMachineSPtr JITGlobals::getTargetMachine(rr::Optimization::Lev
auto llvmOptLevel = toLLVM(optlevel); auto llvmOptLevel = toLLVM(optlevel);
#endif // ENABLE_RR_DEBUG_INFO #endif // ENABLE_RR_DEBUG_INFO
return targetMachines.getOrCreate(optlevel, [&]() { return TargetMachineSPtr(llvm::EngineBuilder()
return TargetMachineSPtr(llvm::EngineBuilder() .setOptLevel(llvmOptLevel)
.setOptLevel(llvmOptLevel) .setMCPU(mcpu)
.setMCPU(mcpu) .setMArch(march)
.setMArch(march) .setMAttrs(mattrs)
.setMAttrs(mattrs) .setTargetOptions(targetOptions)
.setTargetOptions(targetOptions) .selectTarget());
.selectTarget());
});
} }
JITGlobals JITGlobals::create() JITGlobals JITGlobals::create()
...@@ -618,7 +579,7 @@ public: ...@@ -618,7 +579,7 @@ public:
return; return;
} }
})) }))
, targetMachine(JITGlobals::get()->getTargetMachine(config.getOptimization().getLevel())) , targetMachine(JITGlobals::get()->createTargetMachine(config.getOptimization().getLevel()))
, compileLayer(objLayer, llvm::orc::SimpleCompiler(*targetMachine)) , compileLayer(objLayer, llvm::orc::SimpleCompiler(*targetMachine))
, objLayer( , objLayer(
session, session,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment