26 changes: 13 additions & 13 deletions llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace llvm {
namespace orc {

class RTDyldObjectLinkingLayer2 : public ObjectLayer {
class RTDyldObjectLinkingLayer : public ObjectLayer {
public:
/// Functor for receiving object-loaded notifications.
using NotifyLoadedFunction =
Expand All @@ -51,7 +51,7 @@ class RTDyldObjectLinkingLayer2 : public ObjectLayer {

/// Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyEmitted functors.
RTDyldObjectLinkingLayer2(
RTDyldObjectLinkingLayer(
ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager,
NotifyLoadedFunction NotifyLoaded = NotifyLoadedFunction(),
NotifyEmittedFunction NotifyEmitted = NotifyEmittedFunction());
Expand All @@ -66,7 +66,7 @@ class RTDyldObjectLinkingLayer2 : public ObjectLayer {
/// the memory manager, rather than just the sections required for execution.
///
/// This is kludgy, and may be removed in the future.
RTDyldObjectLinkingLayer2 &setProcessAllSections(bool ProcessAllSections) {
RTDyldObjectLinkingLayer &setProcessAllSections(bool ProcessAllSections) {
this->ProcessAllSections = ProcessAllSections;
return *this;
}
Expand All @@ -79,13 +79,13 @@ class RTDyldObjectLinkingLayer2 : public ObjectLayer {
///
/// FIXME: We should be able to remove this if/when COFF properly tracks
/// exported symbols.
RTDyldObjectLinkingLayer2 &
RTDyldObjectLinkingLayer &
setOverrideObjectFlagsWithResponsibilityFlags(bool OverrideObjectFlags) {
this->OverrideObjectFlags = OverrideObjectFlags;
return *this;
}

/// If set, this RTDyldObjectLinkingLayer2 instance will claim responsibility
/// If set, this RTDyldObjectLinkingLayer instance will claim responsibility
/// for any symbols provided by a given object file that were not already in
/// the MaterializationResponsibility instance. Setting this flag allows
/// higher-level program representations (e.g. LLVM IR) to be added based on
Expand All @@ -96,7 +96,7 @@ class RTDyldObjectLinkingLayer2 : public ObjectLayer {
/// deterministically). If this option is set, clashes for the additional
/// symbols may not be detected until late, and detection may depend on
/// the flow of control through JIT'd code. Use with care.
RTDyldObjectLinkingLayer2 &
RTDyldObjectLinkingLayer &
setAutoClaimResponsibilityForObjectSymbols(bool AutoClaimObjectSymbols) {
this->AutoClaimObjectSymbols = AutoClaimObjectSymbols;
return *this;
Expand All @@ -121,7 +121,7 @@ class RTDyldObjectLinkingLayer2 : public ObjectLayer {
std::map<VModuleKey, std::shared_ptr<RuntimeDyld::MemoryManager>> MemMgrs;
};

class RTDyldObjectLinkingLayerBase {
class LegacyRTDyldObjectLinkingLayerBase {
public:
using ObjectPtr = std::unique_ptr<MemoryBuffer>;

Expand Down Expand Up @@ -173,10 +173,10 @@ class RTDyldObjectLinkingLayerBase {
/// object files to be loaded into memory, linked, and the addresses of their
/// symbols queried. All objects added to this layer can see each other's
/// symbols.
class RTDyldObjectLinkingLayer : public RTDyldObjectLinkingLayerBase {
class LegacyRTDyldObjectLinkingLayer : public LegacyRTDyldObjectLinkingLayerBase {
public:

using RTDyldObjectLinkingLayerBase::ObjectPtr;
using LegacyRTDyldObjectLinkingLayerBase::ObjectPtr;

/// Functor for receiving object-loaded notifications.
using NotifyLoadedFtor =
Expand All @@ -197,7 +197,7 @@ class RTDyldObjectLinkingLayer : public RTDyldObjectLinkingLayerBase {
template <typename MemoryManagerPtrT>
class ConcreteLinkedObject : public LinkedObject {
public:
ConcreteLinkedObject(RTDyldObjectLinkingLayer &Parent, VModuleKey K,
ConcreteLinkedObject(LegacyRTDyldObjectLinkingLayer &Parent, VModuleKey K,
OwnedObject Obj, MemoryManagerPtrT MemMgr,
std::shared_ptr<SymbolResolver> Resolver,
bool ProcessAllSections)
Expand Down Expand Up @@ -313,15 +313,15 @@ class RTDyldObjectLinkingLayer : public RTDyldObjectLinkingLayerBase {
};

VModuleKey K;
RTDyldObjectLinkingLayer &Parent;
LegacyRTDyldObjectLinkingLayer &Parent;
MemoryManagerPtrT MemMgr;
OwnedObject ObjForNotify;
std::unique_ptr<PreFinalizeContents> PFC;
};

template <typename MemoryManagerPtrT>
std::unique_ptr<ConcreteLinkedObject<MemoryManagerPtrT>>
createLinkedObject(RTDyldObjectLinkingLayer &Parent, VModuleKey K,
createLinkedObject(LegacyRTDyldObjectLinkingLayer &Parent, VModuleKey K,
OwnedObject Obj, MemoryManagerPtrT MemMgr,
std::shared_ptr<SymbolResolver> Resolver,
bool ProcessAllSections) {
Expand All @@ -341,7 +341,7 @@ class RTDyldObjectLinkingLayer : public RTDyldObjectLinkingLayerBase {

/// Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyFinalized functors.
RTDyldObjectLinkingLayer(
LegacyRTDyldObjectLinkingLayer(
ExecutionSession &ES, ResourcesGetter GetResources,
NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
NotifyFinalizedFtor NotifyFinalized = NotifyFinalizedFtor(),
Expand Down
30 changes: 15 additions & 15 deletions llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ namespace orc {
class PartitioningIRMaterializationUnit : public IRMaterializationUnit {
public:
PartitioningIRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM,
CompileOnDemandLayer2 &Parent)
CompileOnDemandLayer &Parent)
: IRMaterializationUnit(ES, std::move(TSM)), Parent(Parent) {}

PartitioningIRMaterializationUnit(
ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags,
SymbolNameToDefinitionMap SymbolToDefinition,
CompileOnDemandLayer2 &Parent)
CompileOnDemandLayer &Parent)
: IRMaterializationUnit(std::move(TSM), std::move(SymbolFlags),
std::move(SymbolToDefinition)),
Parent(Parent) {}
Expand All @@ -93,30 +93,30 @@ class PartitioningIRMaterializationUnit : public IRMaterializationUnit {
}

mutable std::mutex SourceModuleMutex;
CompileOnDemandLayer2 &Parent;
CompileOnDemandLayer &Parent;
};

Optional<CompileOnDemandLayer2::GlobalValueSet>
CompileOnDemandLayer2::compileRequested(GlobalValueSet Requested) {
Optional<CompileOnDemandLayer::GlobalValueSet>
CompileOnDemandLayer::compileRequested(GlobalValueSet Requested) {
return std::move(Requested);
}

Optional<CompileOnDemandLayer2::GlobalValueSet>
CompileOnDemandLayer2::compileWholeModule(GlobalValueSet Requested) {
Optional<CompileOnDemandLayer::GlobalValueSet>
CompileOnDemandLayer::compileWholeModule(GlobalValueSet Requested) {
return None;
}

CompileOnDemandLayer2::CompileOnDemandLayer2(
CompileOnDemandLayer::CompileOnDemandLayer(
ExecutionSession &ES, IRLayer &BaseLayer, LazyCallThroughManager &LCTMgr,
IndirectStubsManagerBuilder BuildIndirectStubsManager)
: IRLayer(ES), BaseLayer(BaseLayer), LCTMgr(LCTMgr),
BuildIndirectStubsManager(std::move(BuildIndirectStubsManager)) {}

void CompileOnDemandLayer2::setPartitionFunction(PartitionFunction Partition) {
void CompileOnDemandLayer::setPartitionFunction(PartitionFunction Partition) {
this->Partition = std::move(Partition);
}

void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K,
void CompileOnDemandLayer::emit(MaterializationResponsibility R, VModuleKey K,
ThreadSafeModule TSM) {
assert(TSM.getModule() && "Null module");

Expand Down Expand Up @@ -160,8 +160,8 @@ void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K,
std::move(Callables)));
}

CompileOnDemandLayer2::PerDylibResources &
CompileOnDemandLayer2::getPerDylibResources(JITDylib &TargetD) {
CompileOnDemandLayer::PerDylibResources &
CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
auto I = DylibResources.find(&TargetD);
if (I == DylibResources.end()) {
auto &ImplD =
Expand All @@ -176,7 +176,7 @@ CompileOnDemandLayer2::getPerDylibResources(JITDylib &TargetD) {
return I->second;
}

void CompileOnDemandLayer2::cleanUpModule(Module &M) {
void CompileOnDemandLayer::cleanUpModule(Module &M) {
for (auto &F : M.functions()) {
if (F.isDeclaration())
continue;
Expand All @@ -189,7 +189,7 @@ void CompileOnDemandLayer2::cleanUpModule(Module &M) {
}
}

void CompileOnDemandLayer2::expandPartition(GlobalValueSet &Partition) {
void CompileOnDemandLayer::expandPartition(GlobalValueSet &Partition) {
// Expands the partition to ensure the following rules hold:
// (1) If any alias is in the partition, its aliasee is also in the partition.
// (2) If any aliasee is in the partition, its aliases are also in the
Expand Down Expand Up @@ -221,7 +221,7 @@ void CompileOnDemandLayer2::expandPartition(GlobalValueSet &Partition) {
Partition.insert(GV);
}

void CompileOnDemandLayer2::emitPartition(
void CompileOnDemandLayer::emitPartition(
MaterializationResponsibility R, ThreadSafeModule TSM,
IRMaterializationUnit::SymbolNameToDefinitionMap Defs) {

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ iterator_range<CtorDtorIterator> getDestructors(const Module &M) {
CtorDtorIterator(DtorsList, true));
}

void CtorDtorRunner2::add(iterator_range<CtorDtorIterator> CtorDtors) {
void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) {
if (CtorDtors.begin() == CtorDtors.end())
return;

Expand Down Expand Up @@ -115,7 +115,7 @@ void CtorDtorRunner2::add(iterator_range<CtorDtorIterator> CtorDtors) {
}
}

Error CtorDtorRunner2::run() {
Error CtorDtorRunner::run() {
using CtorDtorTy = void (*)();

SymbolNameSet Names;
Expand Down Expand Up @@ -165,7 +165,7 @@ int LocalCXXRuntimeOverridesBase::CXAAtExitOverride(DestructorPtr Destructor,
return 0;
}

Error LocalCXXRuntimeOverrides2::enable(JITDylib &JD,
Error LocalCXXRuntimeOverrides::enable(JITDylib &JD,
MangleAndInterner &Mangle) {
SymbolMap RuntimeInterposes;
RuntimeInterposes[Mangle("__dso_handle")] =
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
namespace llvm {
namespace orc {

IRCompileLayer2::IRCompileLayer2(ExecutionSession &ES, ObjectLayer &BaseLayer,
IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
CompileFunction Compile)
: IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}

void IRCompileLayer2::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
std::lock_guard<std::mutex> Lock(IRLayerMutex);
this->NotifyCompiled = std::move(NotifyCompiled);
}

void IRCompileLayer2::emit(MaterializationResponsibility R, VModuleKey K,
void IRCompileLayer::emit(MaterializationResponsibility R, VModuleKey K,
ThreadSafeModule TSM) {
assert(TSM.getModule() && "Module must not be null");

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
namespace llvm {
namespace orc {

IRTransformLayer2::IRTransformLayer2(ExecutionSession &ES,
IRTransformLayer::IRTransformLayer(ExecutionSession &ES,
IRLayer &BaseLayer,
TransformFunction Transform)
: IRLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}

void IRTransformLayer2::emit(MaterializationResponsibility R, VModuleKey K,
void IRTransformLayer::emit(MaterializationResponsibility R, VModuleKey K,
ThreadSafeModule TSM) {
assert(TSM.getModule() && "Module must not be null");

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {
: llvm::orc::SimpleCompiler(*TM), TM(std::move(TM)) {}
private:
// FIXME: shared because std::functions (and thus
// IRCompileLayer2::CompileFunction) are not moveable.
// IRCompileLayer::CompileFunction) are not moveable.
std::shared_ptr<llvm::TargetMachine> TM;
};

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
namespace llvm {
namespace orc {

ObjectTransformLayer2::ObjectTransformLayer2(ExecutionSession &ES,
ObjectLayer &BaseLayer,
TransformFunction Transform)
ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES,
ObjectLayer &BaseLayer,
TransformFunction Transform)
: ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}

void ObjectTransformLayer2::emit(MaterializationResponsibility R, VModuleKey K,
std::unique_ptr<MemoryBuffer> O) {
void ObjectTransformLayer::emit(MaterializationResponsibility R, VModuleKey K,
std::unique_ptr<MemoryBuffer> O) {
assert(O && "Module must not be null");

if (auto TransformedObj = Transform(std::move(O)))
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class GenericLayer {
};

template <>
class GenericLayerImpl<orc::RTDyldObjectLinkingLayer> : public GenericLayer {
class GenericLayerImpl<orc::LegacyRTDyldObjectLinkingLayer> : public GenericLayer {
private:
using LayerT = orc::RTDyldObjectLinkingLayer;
using LayerT = orc::LegacyRTDyldObjectLinkingLayer;
public:
GenericLayerImpl(LayerT &Layer) : Layer(Layer) {}

Expand Down Expand Up @@ -107,10 +107,10 @@ class OrcCBindingsStack {
public:

using CompileCallbackMgr = orc::JITCompileCallbackManager;
using ObjLayerT = orc::RTDyldObjectLinkingLayer;
using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
using ObjLayerT = orc::LegacyRTDyldObjectLinkingLayer;
using CompileLayerT = orc::LegacyIRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
using CODLayerT =
orc::CompileOnDemandLayer<CompileLayerT, CompileCallbackMgr>;
orc::LegacyCompileOnDemandLayer<CompileLayerT, CompileCallbackMgr>;

using CallbackManagerBuilder =
std::function<std::unique_ptr<CompileCallbackMgr>()>;
Expand Down Expand Up @@ -312,7 +312,7 @@ class OrcCBindingsStack {

// Run the static constructors, and save the static destructor runner for
// execution when the JIT is torn down.
orc::CtorDtorRunner<OrcCBindingsStack> CtorRunner(std::move(CtorNames), K);
orc::LegacyCtorDtorRunner<OrcCBindingsStack> CtorRunner(std::move(CtorNames), K);
if (auto Err = CtorRunner.runViaLayer(*this))
return std::move(Err);

Expand Down Expand Up @@ -517,8 +517,8 @@ class OrcCBindingsStack {

std::map<orc::VModuleKey, std::unique_ptr<detail::GenericLayer>> KeyLayers;

orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
std::vector<orc::CtorDtorRunner<OrcCBindingsStack>> IRStaticDestructorRunners;
orc::LegacyLocalCXXRuntimeOverrides CXXRuntimeOverrides;
std::vector<orc::LegacyCtorDtorRunner<OrcCBindingsStack>> IRStaticDestructorRunners;
std::string ErrMsg;

ResolverMap Resolvers;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void OrcMCJITReplacement::runStaticConstructorsDestructors(bool isDtors) {
auto &CtorDtorsMap = isDtors ? UnexecutedDestructors : UnexecutedConstructors;

for (auto &KV : CtorDtorsMap)
cantFail(CtorDtorRunner<LazyEmitLayerT>(std::move(KV.second), KV.first)
cantFail(LegacyCtorDtorRunner<LazyEmitLayerT>(std::move(KV.second), KV.first)
.runViaLayer(LazyEmitLayer));

CtorDtorsMap.clear();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ class OrcMCJITReplacement : public ExecutionEngine {
return MangledName;
}

using ObjectLayerT = RTDyldObjectLinkingLayer;
using CompileLayerT = IRCompileLayer<ObjectLayerT, orc::SimpleCompiler>;
using ObjectLayerT = LegacyRTDyldObjectLinkingLayer;
using CompileLayerT = LegacyIRCompileLayer<ObjectLayerT, orc::SimpleCompiler>;
using LazyEmitLayerT = LazyEmittingLayer<CompileLayerT>;

ExecutionSession ES;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class JITDylibSearchOrderResolver : public JITSymbolResolver {
namespace llvm {
namespace orc {

RTDyldObjectLinkingLayer2::RTDyldObjectLinkingLayer2(
RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer(
ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager,
NotifyLoadedFunction NotifyLoaded, NotifyEmittedFunction NotifyEmitted)
: ObjectLayer(ES), GetMemoryManager(GetMemoryManager),
NotifyLoaded(std::move(NotifyLoaded)),
NotifyEmitted(std::move(NotifyEmitted)) {}

void RTDyldObjectLinkingLayer2::emit(MaterializationResponsibility R,
void RTDyldObjectLinkingLayer::emit(MaterializationResponsibility R,
VModuleKey K,
std::unique_ptr<MemoryBuffer> O) {
assert(O && "Object must not be null");
Expand Down Expand Up @@ -153,7 +153,7 @@ void RTDyldObjectLinkingLayer2::emit(MaterializationResponsibility R,
});
}

Error RTDyldObjectLinkingLayer2::onObjLoad(
Error RTDyldObjectLinkingLayer::onObjLoad(
VModuleKey K, MaterializationResponsibility &R, object::ObjectFile &Obj,
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
std::map<StringRef, JITEvaluatedSymbol> Resolved,
Expand Down Expand Up @@ -196,7 +196,7 @@ Error RTDyldObjectLinkingLayer2::onObjLoad(
return Error::success();
}

void RTDyldObjectLinkingLayer2::onObjEmit(VModuleKey K,
void RTDyldObjectLinkingLayer::onObjEmit(VModuleKey K,
MaterializationResponsibility &R,
Error Err) {
if (Err) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/tools/lli/lli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ int main(int argc, char **argv, char * const *envp) {
return Result;
}

static orc::IRTransformLayer2::TransformFunction createDebugDumper() {
static orc::IRTransformLayer::TransformFunction createDebugDumper() {
switch (OrcDumpKind) {
case DumpKind::NoDump:
return [](orc::ThreadSafeModule TSM,
Expand Down Expand Up @@ -781,7 +781,7 @@ int runOrcLazyJIT(const char *ProgName) {
auto J = ExitOnErr(orc::LLLazyJIT::Create(std::move(JTMB), DL, LazyJITCompileThreads));

if (PerModuleLazy)
J->setPartitionFunction(orc::CompileOnDemandLayer2::compileWholeModule);
J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule);

auto Dump = createDebugDumper();

Expand All @@ -797,7 +797,7 @@ int runOrcLazyJIT(const char *ProgName) {
ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(DL)));

orc::MangleAndInterner Mangle(J->getExecutionSession(), DL);
orc::LocalCXXRuntimeOverrides2 CXXRuntimeOverrides;
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
ExitOnErr(CXXRuntimeOverrides.enable(J->getMainJITDylib(), Mangle));

// Add the main module.
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ set(LLVM_LINK_COMPONENTS
)

add_llvm_unittest(OrcJITTests
CompileOnDemandLayerTest.cpp
CoreAPIsTest.cpp
IndirectionUtilsTest.cpp
GlobalMappingLayerTest.cpp
JITTargetMachineBuilderTest.cpp
LazyCallThroughAndReexportsTest.cpp
LazyEmittingLayerTest.cpp
LegacyAPIInteropTest.cpp
LegacyCompileOnDemandLayerTest.cpp
LegacyRTDyldObjectLinkingLayerTest.cpp
ObjectTransformLayerTest.cpp
OrcCAPITest.cpp
OrcTestCommon.cpp
QueueChannel.cpp
RemoteObjectLayerTest.cpp
RPCUtilsTest.cpp
RTDyldObjectLinkingLayerTest.cpp
RTDyldObjectLinkingLayer2Test.cpp
SymbolStringPoolTest.cpp
ThreadSafeModuleTest.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DummyStubsManager : public orc::IndirectStubsManager {
}
};

TEST(CompileOnDemandLayerTest, FindSymbol) {
TEST(LegacyCompileOnDemandLayerTest, FindSymbol) {
MockBaseLayer<int, std::shared_ptr<Module>> TestBaseLayer;
TestBaseLayer.findSymbolImpl =
[](const std::string &Name, bool) {
Expand All @@ -76,7 +76,7 @@ TEST(CompileOnDemandLayerTest, FindSymbol) {
llvm_unreachable("Should never be called");
};

llvm::orc::CompileOnDemandLayer<decltype(TestBaseLayer)> COD(
llvm::orc::LegacyCompileOnDemandLayer<decltype(TestBaseLayer)> COD(
ES, TestBaseLayer, GetResolver, SetResolver,
[](Function &F) { return std::set<Function *>{&F}; }, CallbackMgr,
[] { return llvm::make_unique<DummyStubsManager>(); }, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
//===- RTDyldObjectLinkingLayerTest.cpp - RTDyld linking layer unit tests -===//
//
// 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/RTDyldObjectLinkingLayer.h"
#include "OrcTestCommon.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/Legacy.h"
#include "llvm/ExecutionEngine/Orc/NullResolver.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
#include "gtest/gtest.h"

using namespace llvm;
using namespace llvm::orc;

namespace {

class LegacyRTDyldObjectLinkingLayerExecutionTest : public testing::Test,
public OrcExecutionTest {

};

class SectionMemoryManagerWrapper : public SectionMemoryManager {
public:
int FinalizationCount = 0;
int NeedsToReserveAllocationSpaceCount = 0;

bool needsToReserveAllocationSpace() override {
++NeedsToReserveAllocationSpaceCount;
return SectionMemoryManager::needsToReserveAllocationSpace();
}

bool finalizeMemory(std::string *ErrMsg = nullptr) override {
++FinalizationCount;
return SectionMemoryManager::finalizeMemory(ErrMsg);
}
};

TEST(LegacyRTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
class MemoryManagerWrapper : public SectionMemoryManager {
public:
MemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName,
bool IsReadOnly) override {
if (SectionName == ".debug_str")
DebugSeen = true;
return SectionMemoryManager::allocateDataSection(Size, Alignment,
SectionID,
SectionName,
IsReadOnly);
}
private:
bool &DebugSeen;
};

bool DebugSectionSeen = false;
auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen);

ExecutionSession ES;

LegacyRTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) {
return LegacyRTDyldObjectLinkingLayer::Resources{
MM, std::make_shared<NullResolver>()};
});

LLVMContext Context;
auto M = llvm::make_unique<Module>("", Context);
M->setTargetTriple("x86_64-unknown-linux-gnu");
Type *Int32Ty = IntegerType::get(Context, 32);
GlobalVariable *GV =
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
ConstantInt::get(Int32Ty, 42), "foo");

GV->setSection(".debug_str");


// Initialize the native target in case this is the first unit test
// to try to build a TM.
OrcNativeTarget::initialize();
std::unique_ptr<TargetMachine> TM(
EngineBuilder().selectTarget(Triple(M->getTargetTriple()), "", "",
SmallVector<std::string, 1>()));
if (!TM)
return;

auto Obj = SimpleCompiler(*TM)(*M);

{
// Test with ProcessAllSections = false (the default).
auto K = ES.allocateVModule();
cantFail(ObjLayer.addObject(
K, MemoryBuffer::getMemBufferCopy(Obj->getBuffer())));
cantFail(ObjLayer.emitAndFinalize(K));
EXPECT_EQ(DebugSectionSeen, false)
<< "Unexpected debug info section";
cantFail(ObjLayer.removeObject(K));
}

{
// Test with ProcessAllSections = true.
ObjLayer.setProcessAllSections(true);
auto K = ES.allocateVModule();
cantFail(ObjLayer.addObject(K, std::move(Obj)));
cantFail(ObjLayer.emitAndFinalize(K));
EXPECT_EQ(DebugSectionSeen, true)
<< "Expected debug info section not seen";
cantFail(ObjLayer.removeObject(K));
}
}

TEST_F(LegacyRTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
if (!SupportsJIT)
return;

ExecutionSession ES;

auto MM = std::make_shared<SectionMemoryManagerWrapper>();

std::map<orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>> Resolvers;

LegacyRTDyldObjectLinkingLayer ObjLayer(ES, [&](VModuleKey K) {
auto I = Resolvers.find(K);
assert(I != Resolvers.end() && "Missing resolver");
auto R = std::move(I->second);
Resolvers.erase(I);
return LegacyRTDyldObjectLinkingLayer::Resources{MM, std::move(R)};
});
SimpleCompiler Compile(*TM);

// Create a pair of modules that will trigger recursive finalization:
// Module 1:
// int bar() { return 42; }
// Module 2:
// int bar();
// int foo() { return bar(); }
//
// Verify that the memory manager is only finalized once (for Module 2).
// Failure suggests that finalize is being called on the inner RTDyld
// instance (for Module 1) which is unsafe, as it will prevent relocation of
// Module 2.

ModuleBuilder MB1(Context, "", "dummy");
{
MB1.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
Builder.CreateRet(FourtyTwo);
}

auto Obj1 = Compile(*MB1.getModule());

ModuleBuilder MB2(Context, "", "dummy");
{
MB2.getModule()->setDataLayout(TM->createDataLayout());
Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
BasicBlock *FooEntry = BasicBlock::Create(Context, "entry", FooImpl);
IRBuilder<> Builder(FooEntry);
Builder.CreateRet(Builder.CreateCall(BarDecl));
}
auto Obj2 = Compile(*MB2.getModule());

auto K1 = ES.allocateVModule();
Resolvers[K1] = std::make_shared<NullResolver>();
cantFail(ObjLayer.addObject(K1, std::move(Obj1)));

auto K2 = ES.allocateVModule();
auto LegacyLookup = [&](const std::string &Name) {
return ObjLayer.findSymbol(Name, true);
};

Resolvers[K2] = createSymbolResolver(
[&](const SymbolNameSet &Symbols) {
return cantFail(
getResponsibilitySetWithLegacyFn(Symbols, LegacyLookup));
},
[&](std::shared_ptr<AsynchronousSymbolQuery> Query,
const SymbolNameSet &Symbols) {
return lookupWithLegacyFn(ES, *Query, Symbols, LegacyLookup);
});

cantFail(ObjLayer.addObject(K2, std::move(Obj2)));
cantFail(ObjLayer.emitAndFinalize(K2));
cantFail(ObjLayer.removeObject(K2));

// Finalization of module 2 should trigger finalization of module 1.
// Verify that finalize on SMMW is only called once.
EXPECT_EQ(MM->FinalizationCount, 1)
<< "Extra call to finalize";
}

TEST_F(LegacyRTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
if (!SupportsJIT)
return;

ExecutionSession ES;

auto MM = std::make_shared<SectionMemoryManagerWrapper>();

LegacyRTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey K) {
return LegacyRTDyldObjectLinkingLayer::Resources{
MM, std::make_shared<NullResolver>()};
});
SimpleCompiler Compile(*TM);

// Create a pair of unrelated modules:
//
// Module 1:
// int foo() { return 42; }
// Module 2:
// int bar() { return 7; }
//
// Both modules will share a memory manager. We want to verify that the
// second object is not loaded before the first one is finalized. To do this
// in a portable way, we abuse the
// RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
// called once per object before any sections are allocated.

ModuleBuilder MB1(Context, "", "dummy");
{
MB1.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
Builder.CreateRet(FourtyTwo);
}

auto Obj1 = Compile(*MB1.getModule());

ModuleBuilder MB2(Context, "", "dummy");
{
MB2.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
Builder.CreateRet(Seven);
}
auto Obj2 = Compile(*MB2.getModule());

auto K = ES.allocateVModule();
cantFail(ObjLayer.addObject(K, std::move(Obj1)));
cantFail(ObjLayer.addObject(ES.allocateVModule(), std::move(Obj2)));
cantFail(ObjLayer.emitAndFinalize(K));
cantFail(ObjLayer.removeObject(K));

// Only one call to needsToReserveAllocationSpace should have been made.
EXPECT_EQ(MM->NeedsToReserveAllocationSpaceCount, 1)
<< "More than one call to needsToReserveAllocationSpace "
"(multiple unrelated objects loaded prior to finalization)";
}

TEST_F(LegacyRTDyldObjectLinkingLayerExecutionTest, TestNotifyLoadedSignature) {
ExecutionSession ES;
LegacyRTDyldObjectLinkingLayer ObjLayer(
ES,
[](VModuleKey) {
return LegacyRTDyldObjectLinkingLayer::Resources{
nullptr, std::make_shared<NullResolver>()};
},
[](VModuleKey, const object::ObjectFile &obj,
const RuntimeDyld::LoadedObjectInfo &info) {});
}

} // end anonymous namespace
24 changes: 12 additions & 12 deletions llvm/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ class MockBaseLayer {
}
};

// Test each operation on ObjectTransformLayer.
TEST(ObjectTransformLayerTest, Main) {
// Test each operation on LegacyObjectTransformLayer.
TEST(LegacyObjectTransformLayerTest, Main) {
MockBaseLayer M;

ExecutionSession ES(std::make_shared<SymbolStringPool>());

// Create one object transform layer using a transform (as a functor)
// that allocates new objects, and deals in unique pointers.
ObjectTransformLayer<MockBaseLayer, AllocatingTransform> T1(M);
LegacyObjectTransformLayer<MockBaseLayer, AllocatingTransform> T1(M);

// Create a second object transform layer using a transform (as a lambda)
// that mutates objects in place, and deals in naked pointers
ObjectTransformLayer<MockBaseLayer,
LegacyObjectTransformLayer<MockBaseLayer,
std::function<std::shared_ptr<MockObjectFile>(
std::shared_ptr<MockObjectFile>)>>
T2(M, [](std::shared_ptr<MockObjectFile> Obj) {
Expand Down Expand Up @@ -257,9 +257,9 @@ TEST(ObjectTransformLayerTest, Main) {
if (!RunStaticChecks)
return;

// Make sure that ObjectTransformLayer implements the object layer concept
// Make sure that LegacyObjectTransformLayer implements the object layer concept
// correctly by sandwitching one between an ObjectLinkingLayer and an
// IRCompileLayer, verifying that it compiles if we have a call to the
// LegacyIRCompileLayer, verifying that it compiles if we have a call to the
// IRComileLayer's addModule that should call the transform layer's
// addObject, and also calling the other public transform layer methods
// directly to make sure the methods they intend to forward to exist on
Expand All @@ -282,29 +282,29 @@ TEST(ObjectTransformLayerTest, Main) {
};

// Construct the jit layers.
RTDyldObjectLinkingLayer BaseLayer(ES, [](VModuleKey) {
return RTDyldObjectLinkingLayer::Resources{
LegacyRTDyldObjectLinkingLayer BaseLayer(ES, [](VModuleKey) {
return LegacyRTDyldObjectLinkingLayer::Resources{
std::make_shared<llvm::SectionMemoryManager>(),
std::make_shared<NullResolver>()};
});

auto IdentityTransform = [](std::unique_ptr<llvm::MemoryBuffer> Obj) {
return Obj;
};
ObjectTransformLayer<decltype(BaseLayer), decltype(IdentityTransform)>
LegacyObjectTransformLayer<decltype(BaseLayer), decltype(IdentityTransform)>
TransformLayer(BaseLayer, IdentityTransform);
auto NullCompiler = [](llvm::Module &) {
return std::unique_ptr<llvm::MemoryBuffer>(nullptr);
};
IRCompileLayer<decltype(TransformLayer), decltype(NullCompiler)>
LegacyIRCompileLayer<decltype(TransformLayer), decltype(NullCompiler)>
CompileLayer(TransformLayer, NullCompiler);

// Make sure that the calls from IRCompileLayer to ObjectTransformLayer
// Make sure that the calls from LegacyIRCompileLayer to LegacyObjectTransformLayer
// compile.
cantFail(CompileLayer.addModule(ES.allocateVModule(),
std::unique_ptr<llvm::Module>()));

// Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
// Make sure that the calls from LegacyObjectTransformLayer to ObjectLinkingLayer
// compile.
VModuleKey DummyKey = ES.allocateVModule();
cantFail(TransformLayer.emitAndFinalize(DummyKey));
Expand Down
228 changes: 0 additions & 228 deletions llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayer2Test.cpp

This file was deleted.

332 changes: 139 additions & 193 deletions llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp

Large diffs are not rendered by default.