2018-05-24 05:27:01 +08:00
|
|
|
//===--------------- 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 {
|
|
|
|
|
2018-10-16 06:56:10 +08:00
|
|
|
IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
|
2018-05-24 05:27:01 +08:00
|
|
|
CompileFunction Compile)
|
|
|
|
: IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
|
|
|
|
|
2018-10-16 06:56:10 +08:00
|
|
|
void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
|
2018-05-24 05:27:01 +08:00
|
|
|
std::lock_guard<std::mutex> Lock(IRLayerMutex);
|
|
|
|
this->NotifyCompiled = std::move(NotifyCompiled);
|
|
|
|
}
|
|
|
|
|
2018-10-16 06:56:10 +08:00
|
|
|
void IRCompileLayer::emit(MaterializationResponsibility R, VModuleKey K,
|
2018-09-26 09:24:12 +08:00
|
|
|
ThreadSafeModule TSM) {
|
|
|
|
assert(TSM.getModule() && "Module must not be null");
|
2018-05-24 05:27:01 +08:00
|
|
|
|
2018-09-26 09:24:12 +08:00
|
|
|
if (auto Obj = Compile(*TSM.getModule())) {
|
2018-05-24 05:27:01 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> Lock(IRLayerMutex);
|
|
|
|
if (NotifyCompiled)
|
2018-09-26 09:24:12 +08:00
|
|
|
NotifyCompiled(K, std::move(TSM));
|
2018-05-24 05:27:01 +08:00
|
|
|
else
|
2018-09-26 09:24:12 +08:00
|
|
|
TSM = ThreadSafeModule();
|
2018-05-24 05:27:01 +08:00
|
|
|
}
|
|
|
|
BaseLayer.emit(std::move(R), std::move(K), std::move(*Obj));
|
|
|
|
} else {
|
|
|
|
R.failMaterialization();
|
|
|
|
getExecutionSession().reportError(Obj.takeError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|