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
llvm::orc::ExecutionSession session;
llvm::orc::RTDyldObjectLinkingLayer objectLayer;
llvm::orc::IRCompileLayer compileLayer;
llvm::orc::MangleAndInterner mangle;
llvm::orc::JITDylib &dylib;
std::vector<const void *> addresses;
......@@ -644,7 +643,6 @@ public:
return std::make_unique<llvm::SectionMemoryManager>(&memoryMapper);
})
, 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>")))
, addresses(count)
{
......@@ -673,17 +671,19 @@ public:
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++)
{
auto func = funcs[i];
func->setLinkage(llvm::GlobalValue::ExternalLinkage);
func->setDoesNotThrow();
if(!func->hasName())
{
func->setName("f" + llvm::Twine(i).str());
}
names[i] = mangle(func->getName());
functionNames[i] = mangle(func->getName());
}
#ifdef ENABLE_RR_EMIT_ASM_FILE
......@@ -701,7 +701,7 @@ public:
// Resolve the function addresses.
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",
(int)i, llvm::toString(symbol.takeError()).c_str());
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
{
llvm::FunctionType *functionType = llvm::FunctionType::get(retTy, params, false);
auto func = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, name, jit->module.get());
func->setLinkage(llvm::GlobalValue::ExternalLinkage);
func->setDoesNotThrow();
func->setCallingConv(llvm::CallingConv::C);
if(__has_feature(memory_sanitizer))
{
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