mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-16 05:10:32 +00:00

MaterializationResponsibility. VModuleKeys are intended to enable selective removal of modules from a JIT session, however for a wide variety of use cases selective removal is not needed and introduces unnecessary overhead. As of this commit, the default constructed VModuleKey value is reserved as a "do not track" value, and becomes the default when adding a new module to the JIT. This commit also changes the propagation of VModuleKeys. They were passed alongside the MaterializationResponsibity instance in XXLayer::emit methods, but are now propagated as part of the MaterializationResponsibility instance itself (and as part of MaterializationUnit when stored in a JITDylib). Associating VModuleKeys with MaterializationUnits in this way should allow for a thread-safe module removal mechanism in the future, even when a module is in the process of being compiled, by having the MaterializationResponsibility object check in on its VModuleKey's state before commiting its results to the JITDylib. llvm-svn: 344643
45 lines
1.4 KiB
C++
45 lines
1.4 KiB
C++
//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
|
|
CompileFunction Compile)
|
|
: IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
|
|
|
|
void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
|
|
std::lock_guard<std::mutex> Lock(IRLayerMutex);
|
|
this->NotifyCompiled = std::move(NotifyCompiled);
|
|
}
|
|
|
|
void IRCompileLayer::emit(MaterializationResponsibility R,
|
|
ThreadSafeModule TSM) {
|
|
assert(TSM.getModule() && "Module must not be null");
|
|
|
|
if (auto Obj = Compile(*TSM.getModule())) {
|
|
{
|
|
std::lock_guard<std::mutex> Lock(IRLayerMutex);
|
|
if (NotifyCompiled)
|
|
NotifyCompiled(R.getVModuleKey(), std::move(TSM));
|
|
else
|
|
TSM = ThreadSafeModule();
|
|
}
|
|
BaseLayer.emit(std::move(R), std::move(*Obj));
|
|
} else {
|
|
R.failMaterialization();
|
|
getExecutionSession().reportError(Obj.takeError());
|
|
}
|
|
}
|
|
|
|
} // End namespace orc.
|
|
} // End namespace llvm.
|