mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
a7a66b3792
Summary: Prototype of a JIT compiler that utilizes ThinLTO summaries to compile modules ahead of time. This is an implementation of the concept I presented in my "ThinLTO Summaries in JIT Compilation" talk at the 2018 Developers' Meeting: http://llvm.org/devmtg/2018-10/talk-abstracts.html#lt8 Upfront the JIT first populates the *combined ThinLTO module index*, which provides fast access to the global call-graph and module paths by function. Next, it loads the main function's module and compiles it. All functions in the module will be emitted with prolog instructions that *fire a discovery flag* once execution reaches them. In parallel, the *discovery thread* is busy-watching the existing flags. Once it detects one has fired, it uses the module index to find all functions that are reachable from it within a given number of calls and submits their defining modules to the compilation pipeline. While execution continues, more flags are fired and further modules added. Ideally the JIT can be tuned in a way, so that in the majority of cases the code on the execution path can be compiled ahead of time. In cases where it doesn't work, the JIT has a *definition generator* in place that loads modules if missing functions are reached. Reviewers: lhames, dblaikie, jfb, tejohnson, pree-jackie, AlexDenisov, kavon Subscribers: mgorny, mehdi_amini, inglorion, hiraditya, steven_wu, dexonsmith, arphaman, jfb, merge_guards_bot, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72486
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
#include "ThinLtoDiscoveryThread.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
#include "llvm/Support/Debug.h"
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "ThinLtoInstrumentationLayer.h"
|
|
#include "ThinLtoModuleIndex.h"
|
|
|
|
#include <thread>
|
|
|
|
#define DEBUG_TYPE "thinltojit"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
void ThinLtoDiscoveryThread::operator()() {
|
|
while (KeepRunning.load()) {
|
|
std::vector<unsigned> Indexes = Layer.takeFlagsThatFired();
|
|
|
|
if (!Indexes.empty()) {
|
|
LLVM_DEBUG(dbgs() << Indexes.size() << " new flags raised\n");
|
|
auto ReachedFunctions = Layer.takeFlagOwners(std::move(Indexes));
|
|
|
|
for (GlobalValue::GUID F : ReachedFunctions) {
|
|
if (GlobalValueSummary *S = GlobalIndex.getSummary(F)) {
|
|
assert(isa<FunctionSummary>(S) && "Reached symbols are functions");
|
|
GlobalIndex.discoverCalleeModulePaths(cast<FunctionSummary>(S),
|
|
LookaheadLevels);
|
|
} else {
|
|
LLVM_DEBUG(dbgs() << "No summary for GUID: " << F << "\n");
|
|
}
|
|
}
|
|
|
|
if (GlobalIndex.getNumDiscoveredModules() > 0)
|
|
spawnLookupForHighRankModules();
|
|
}
|
|
}
|
|
}
|
|
|
|
void ThinLtoDiscoveryThread::spawnLookupForHighRankModules() {
|
|
std::vector<std::string> Paths = GlobalIndex.selectNextPaths();
|
|
GlobalIndex.scheduleModuleParsing(Paths);
|
|
|
|
// In order to add modules we need exclusive access to the execution session.
|
|
std::thread([this, Paths = std::move(Paths)]() {
|
|
ES.runSessionLocked([this, Paths = std::move(Paths)]() mutable {
|
|
for (const std::string &Path : Paths) {
|
|
ThreadSafeModule TSM = GlobalIndex.takeModule(Path);
|
|
if (!TSM)
|
|
// In the meantime the module was added synchronously.
|
|
continue;
|
|
|
|
if (Error LoadErr = AddModule(std::move(TSM)))
|
|
// Failed to add the module to the session.
|
|
ES.reportError(std::move(LoadErr));
|
|
|
|
++NumModulesSubmitted;
|
|
}
|
|
});
|
|
}).detach();
|
|
}
|
|
|
|
} // namespace orc
|
|
} // namespace llvm
|