Commit 567e560d by Nicolas Capens Committed by Nicolas Capens

Eliminate duplicate LLVM contexts

The LLVMContext object is used for caching LLVM types, eliminating duplicate constants, and things like handling diagnostics information. Previously we created one for the JITBuilder as well as the JITRoutine. While having multiple ones is mostly benign from a correctness point of view, it adds unnecessary overhead. This change reuses the context created for the JITBuilder object (which is used during IR construction), for the JITRoutine (which uses it for actual compilation). Bug: b/177024837 Change-Id: Iefbbd7fbeb53e67ab41914fad471dd94d9755311 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51568 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 0985120b
......@@ -627,13 +627,13 @@ class JITRoutine : public rr::Routine
llvm::orc::RTDyldObjectLinkingLayer objectLayer;
llvm::orc::IRCompileLayer compileLayer;
llvm::orc::MangleAndInterner mangle;
llvm::orc::ThreadSafeContext ctx;
llvm::orc::JITDylib &dylib;
std::vector<const void *> addresses;
public:
JITRoutine(
std::unique_ptr<llvm::Module> module,
std::unique_ptr<llvm::LLVMContext> context,
const char *name,
llvm::Function **funcs,
size_t count,
......@@ -645,11 +645,9 @@ public:
})
, compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel())))
, mangle(session, JITGlobals::get()->getDataLayout())
, ctx(std::make_unique<llvm::LLVMContext>())
, dylib(Unwrap(session.createJITDylib("<routine>")))
, addresses(count)
{
#ifdef ENABLE_RR_DEBUG_INFO
// TODO(b/165000222): Update this on next LLVM roll.
// https://github.com/llvm/llvm-project/commit/98f2bb4461072347dcca7d2b1b9571b3a6525801
......@@ -698,7 +696,7 @@ public:
// after this point.
funcs = nullptr;
llvm::cantFail(compileLayer.add(dylib, llvm::orc::ThreadSafeModule(std::move(module), ctx)));
llvm::cantFail(compileLayer.add(dylib, llvm::orc::ThreadSafeModule(std::move(module), std::move(context))));
// Resolve the function addresses.
for(size_t i = 0; i < count; i++)
......@@ -736,8 +734,9 @@ namespace rr {
JITBuilder::JITBuilder(const rr::Config &config)
: config(config)
, module(new llvm::Module("", context))
, builder(new llvm::IRBuilder<>(context))
, context(new llvm::LLVMContext())
, module(new llvm::Module("", *context))
, builder(new llvm::IRBuilder<>(*context))
{
module->setTargetTriple(LLVM_DEFAULT_TARGET_TRIPLE);
module->setDataLayout(JITGlobals::get()->getDataLayout());
......@@ -787,7 +786,7 @@ void JITBuilder::optimize(const rr::Config &cfg)
std::shared_ptr<rr::Routine> JITBuilder::acquireRoutine(const char *name, llvm::Function **funcs, size_t count, const rr::Config &cfg)
{
ASSERT(module);
return std::make_shared<JITRoutine>(std::move(module), name, funcs, count, cfg);
return std::make_shared<JITRoutine>(std::move(module), std::move(context), name, funcs, count, cfg);
}
} // namespace rr
......@@ -95,7 +95,7 @@ public:
std::shared_ptr<rr::Routine> acquireRoutine(const char *name, llvm::Function **funcs, size_t count, const rr::Config &cfg);
const Config config;
llvm::LLVMContext context;
std::unique_ptr<llvm::LLVMContext> context;
std::unique_ptr<llvm::Module> module;
std::unique_ptr<llvm::IRBuilder<>> builder;
llvm::Function *function = nullptr;
......
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