Commit 58d987a0 by Nicolas Capens Committed by Nicolas Capens

Reduce the mangler object lifetime

It's only used for mangling the names of our generated functions during Routine construction, so don't hang on to it for the entire lifetime of the routine. Also, don't set Function attributes during routine compilation, set them at creation. Bug: b/177024837 Change-Id: I974b10430bced5d59f51e54426f7ee0aa8c96ca2 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51569 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 567e560d
...@@ -626,7 +626,6 @@ class JITRoutine : public rr::Routine ...@@ -626,7 +626,6 @@ class JITRoutine : public rr::Routine
llvm::orc::ExecutionSession session; llvm::orc::ExecutionSession session;
llvm::orc::RTDyldObjectLinkingLayer objectLayer; llvm::orc::RTDyldObjectLinkingLayer objectLayer;
llvm::orc::IRCompileLayer compileLayer; llvm::orc::IRCompileLayer compileLayer;
llvm::orc::MangleAndInterner mangle;
llvm::orc::JITDylib &dylib; llvm::orc::JITDylib &dylib;
std::vector<const void *> addresses; std::vector<const void *> addresses;
...@@ -644,7 +643,6 @@ public: ...@@ -644,7 +643,6 @@ public:
return std::make_unique<llvm::SectionMemoryManager>(&memoryMapper); return std::make_unique<llvm::SectionMemoryManager>(&memoryMapper);
}) })
, compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel()))) , compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel())))
, mangle(session, JITGlobals::get()->getDataLayout())
, dylib(Unwrap(session.createJITDylib("<routine>"))) , dylib(Unwrap(session.createJITDylib("<routine>")))
, addresses(count) , addresses(count)
{ {
...@@ -673,17 +671,19 @@ public: ...@@ -673,17 +671,19 @@ public:
dylib.addGenerator(std::make_unique<ExternalSymbolGenerator>()); dylib.addGenerator(std::make_unique<ExternalSymbolGenerator>());
llvm::SmallVector<llvm::orc::SymbolStringPtr, 8> names(count); llvm::SmallVector<llvm::orc::SymbolStringPtr, 8> functionNames(count);
llvm::orc::MangleAndInterner mangle(session, JITGlobals::get()->getDataLayout());
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
auto func = funcs[i]; auto func = funcs[i];
func->setLinkage(llvm::GlobalValue::ExternalLinkage);
func->setDoesNotThrow();
if(!func->hasName()) if(!func->hasName())
{ {
func->setName("f" + llvm::Twine(i).str()); func->setName("f" + llvm::Twine(i).str());
} }
names[i] = mangle(func->getName());
functionNames[i] = mangle(func->getName());
} }
#ifdef ENABLE_RR_EMIT_ASM_FILE #ifdef ENABLE_RR_EMIT_ASM_FILE
...@@ -701,7 +701,7 @@ public: ...@@ -701,7 +701,7 @@ public:
// Resolve the function addresses. // Resolve the function addresses.
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
auto symbol = session.lookup({ &dylib }, names[i]); auto symbol = session.lookup({ &dylib }, functionNames[i]);
ASSERT_MSG(symbol, "Failed to lookup address of routine function %d: %s", ASSERT_MSG(symbol, "Failed to lookup address of routine function %d: %s",
(int)i, llvm::toString(symbol.takeError()).c_str()); (int)i, llvm::toString(symbol.takeError()).c_str());
addresses[i] = reinterpret_cast<void *>(static_cast<intptr_t>(symbol->getAddress())); addresses[i] = reinterpret_cast<void *>(static_cast<intptr_t>(symbol->getAddress()));
......
...@@ -488,8 +488,11 @@ static llvm::Function *createFunction(const char *name, llvm::Type *retTy, const ...@@ -488,8 +488,11 @@ static llvm::Function *createFunction(const char *name, llvm::Type *retTy, const
{ {
llvm::FunctionType *functionType = llvm::FunctionType::get(retTy, params, false); llvm::FunctionType *functionType = llvm::FunctionType::get(retTy, params, false);
auto func = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, name, jit->module.get()); auto func = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, name, jit->module.get());
func->setLinkage(llvm::GlobalValue::ExternalLinkage);
func->setDoesNotThrow(); func->setDoesNotThrow();
func->setCallingConv(llvm::CallingConv::C); func->setCallingConv(llvm::CallingConv::C);
if(__has_feature(memory_sanitizer)) if(__has_feature(memory_sanitizer))
{ {
func->addFnAttr(llvm::Attribute::SanitizeMemory); func->addFnAttr(llvm::Attribute::SanitizeMemory);
......
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