Skip to content

Commit c8e7938

Browse files
committed
LLVMCompilerContext: Only lookup functions with external linkage
1 parent ce875ee commit c8e7938

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/dev/engine/internal/llvm/llvmcompilercontext.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void LLVMCompilerContext::initJit()
5858

5959
// Optimize
6060
const auto &functions = m_module->getFunctionList();
61-
std::vector<std::string> functionNames;
61+
std::vector<std::string> lookupNames;
6262

6363
llvm::PassBuilder passBuilder;
6464
llvm::LoopAnalysisManager loopAnalysisManager;
@@ -84,17 +84,19 @@ void LLVMCompilerContext::initJit()
8484
// Run the O3 pipeline for specific functions
8585
for (llvm::Function &func : m_module->functions()) {
8686
if (!func.isDeclaration()) {
87-
functionNames.push_back(func.getName().str());
88-
89-
if (func.hasExternalLinkage() && !func.hasFnAttribute(llvm::Attribute::OptimizeNone)) {
87+
if (func.hasExternalLinkage()) {
88+
lookupNames.push_back(func.getName().str());
89+
90+
if (func.hasFnAttribute(llvm::Attribute::OptimizeNone)) {
91+
// Remove this attribute to avoid JIT hangs
92+
// TODO: Optimize all functions, maybe it doesn't take so long
93+
func.removeFnAttr(llvm::Attribute::OptimizeNone);
94+
} else {
9095
#ifndef NDEBUG
91-
std::cout << "debug: optimizing function: " << functionNames.back() << std::endl;
96+
std::cout << "debug: optimizing function: " << func.getName().str() << std::endl;
9297
#endif
93-
functionPassManager.run(func, functionAnalysisManager);
94-
} else if (func.hasFnAttribute(llvm::Attribute::OptimizeNone)) {
95-
// Remove this attribute to avoid JIT hangs
96-
// TODO: Optimize all functions, maybe it doesn't take so long
97-
func.removeFnAttr(llvm::Attribute::OptimizeNone);
98+
functionPassManager.run(func, functionAnalysisManager);
99+
}
98100
}
99101
}
100102
}
@@ -109,7 +111,7 @@ void LLVMCompilerContext::initJit()
109111
}
110112

111113
// Lookup functions to JIT-compile ahead of time
112-
for (const std::string &name : functionNames) {
114+
for (const std::string &name : lookupNames) {
113115
#ifndef NDEBUG
114116
std::cout << "debug: looking up function: " << name << std::endl;
115117
#endif

0 commit comments

Comments
 (0)