mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-02 13:12:09 +00:00

This commit adds a ManglingOptions struct to IRMaterializationUnit, and replaces IRCompileLayer::CompileFunction with a new IRCompileLayer::IRCompiler class. The ManglingOptions struct defines the emulated-TLS state (via a bool member, EmulatedTLS, which is true if emulated-TLS is enabled and false otherwise). The IRCompileLayer::IRCompiler class wraps an IRCompiler (the same way that the CompileFunction typedef used to), but adds a method to return the IRCompileLayer::ManglingOptions that the compiler will use. These changes allow us to correctly determine the symbols that will be produced when a thread local global variable defined at the IR level is compiled with or without emulated TLS. This is required for ORCv2, where MaterializationUnits must declare their interface up-front. Most ORCv2 clients should not require any changes. Clients writing custom IR compilers will need to wrap their compiler in an IRCompileLayer::IRCompiler, rather than an IRCompileLayer::CompileFunction, however this should be a straightforward change (see modifications to CompileUtils.* in this patch for an example).
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
IRCompileLayer::IRCompiler::~IRCompiler() {}
|
|
|
|
IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
|
|
std::unique_ptr<IRCompiler> Compile)
|
|
: IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
|
|
Compile(std::move(Compile)) {
|
|
ManglingOpts = &this->Compile->getManglingOptions();
|
|
}
|
|
|
|
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 && "Module must not be null");
|
|
|
|
if (auto Obj = TSM.withModuleDo(*Compile)) {
|
|
{
|
|
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.
|