Skip to content

Commit b701089

Browse files
committed
LLVMCompilerContext: Compile functions ahead of time
1 parent 76e5cfc commit b701089

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

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

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

6263
llvm::PassBuilder passBuilder;
6364
llvm::LoopAnalysisManager loopAnalysisManager;
@@ -83,6 +84,8 @@ void LLVMCompilerContext::initJit()
8384
// Run the O3 pipeline for specific functions
8485
for (llvm::Function &func : m_module->functions()) {
8586
if (!func.isDeclaration()) {
87+
functionNames.push_back(func.getName().str());
88+
8689
if (func.hasExternalLinkage() && !func.hasFnAttribute(llvm::Attribute::OptimizeNone)) {
8790
#ifndef NDEBUG
8891
std::cout << "debug: optimizing function: " << functionNames.back() << std::endl;
@@ -104,6 +107,14 @@ void LLVMCompilerContext::initJit()
104107
llvm::errs() << "error: failed to add module '" << name << "' to JIT: " << toString(std::move(err)) << "\n";
105108
return;
106109
}
110+
111+
// Lookup functions to JIT-compile ahead of time
112+
for (const std::string &name : functionNames) {
113+
#ifndef NDEBUG
114+
std::cout << "debug: looking up function: " << name << std::endl;
115+
#endif
116+
lookupFunction<void *>(name);
117+
}
107118
}
108119

109120
bool LLVMCompilerContext::jitInitialized() const

0 commit comments

Comments
 (0)