[llvm] r250796 - [Orc] Make CompileOnDemandLayer::findSymbol call BaseLayer::findSymbol if no
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 21:35:03 PDT 2015
Author: lhames
Date: Mon Oct 19 23:35:02 2015
New Revision: 250796
URL: http://llvm.org/viewvc/llvm-project?rev=250796&view=rev
Log:
[Orc] Make CompileOnDemandLayer::findSymbol call BaseLayer::findSymbol if no
symbol definition is found in the logical dylibs.
Added:
llvm/trunk/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt
llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=250796&r1=250795&r2=250796&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Mon Oct 19 23:35:02 2015
@@ -169,7 +169,7 @@ public:
LDI != LDE; ++LDI)
if (auto Symbol = findSymbolIn(LDI, Name, ExportedSymbolsOnly))
return Symbol;
- return nullptr;
+ return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
}
/// @brief Get the address of a symbol provided by this layer, or some layer
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt?rev=250796&r1=250795&r2=250796&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt Mon Oct 19 23:35:02 2015
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_unittest(OrcJITTests
+ CompileOnDemandLayerTest.cpp
IndirectionUtilsTest.cpp
GlobalMappingLayerTest.cpp
LazyEmittingLayerTest.cpp
Added: llvm/trunk/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp?rev=250796&view=auto
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp (added)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp Mon Oct 19 23:35:02 2015
@@ -0,0 +1,82 @@
+//===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "OrcTestCommon.h"
+#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+namespace {
+
+class DummyCallbackManager : public orc::JITCompileCallbackManagerBase {
+public:
+ DummyCallbackManager()
+ : JITCompileCallbackManagerBase(0, 0), NextStubAddress(0),
+ UniversalCompile([]() { return 0; }) {
+ }
+
+ CompileCallbackInfo getCompileCallback(LLVMContext &Context) override {
+ return CompileCallbackInfo(++NextStubAddress, UniversalCompile);
+ }
+public:
+ TargetAddress NextStubAddress;
+ CompileFtor UniversalCompile;
+};
+
+class DummyStubsManager : public orc::IndirectStubsManagerBase {
+public:
+ std::error_code init(const StubInitsMap &StubInits) override {
+ llvm_unreachable("Not implemented");
+ }
+
+ JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
+ llvm_unreachable("Not implemented");
+ }
+
+ JITSymbol findPointer(StringRef Name) override {
+ llvm_unreachable("Not implemented");
+ }
+
+ std::error_code updatePointer(StringRef Name,
+ TargetAddress NewAddr) override {
+ llvm_unreachable("Not implemented");
+ }
+};
+
+TEST(CompileOnDemandLayerTest, FindSymbol) {
+ auto MockBaseLayer =
+ createMockBaseLayer<int>(DoNothingAndReturn<int>(0),
+ DoNothingAndReturn<void>(),
+ [](const std::string &Name, bool) {
+ if (Name == "foo")
+ return JITSymbol(1, JITSymbolFlags::Exported);
+ return JITSymbol(nullptr);
+ },
+ DoNothingAndReturn<JITSymbol>(nullptr));
+
+ typedef decltype(MockBaseLayer) MockBaseLayerT;
+ DummyCallbackManager CallbackMgr;
+ auto StubsMgrBuilder =
+ []() {
+ return llvm::make_unique<DummyStubsManager>();
+ };
+
+ llvm::orc::CompileOnDemandLayer<MockBaseLayerT>
+ COD(MockBaseLayer,
+ [](Function &F) { std::set<Function*> S; S.insert(&F); return S; },
+ CallbackMgr, StubsMgrBuilder, true);
+ auto Sym = COD.findSymbol("foo", true);
+
+ EXPECT_TRUE(!!Sym)
+ << "CompileOnDemand::findSymbol should call findSymbol in the base layer.";
+}
+
+}
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h?rev=250796&r1=250795&r2=250796&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h Mon Oct 19 23:35:02 2015
@@ -20,6 +20,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/TypeBuilder.h"
+#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include <memory>
namespace llvm {
@@ -60,6 +61,87 @@ namespace llvm {
}
};
+template <typename HandleT,
+ typename AddModuleSetFtor,
+ typename RemoveModuleSetFtor,
+ typename FindSymbolFtor,
+ typename FindSymbolInFtor>
+class MockBaseLayer {
+public:
+
+ typedef HandleT ModuleSetHandleT;
+
+ MockBaseLayer(AddModuleSetFtor &&AddModuleSet,
+ RemoveModuleSetFtor &&RemoveModuleSet,
+ FindSymbolFtor &&FindSymbol,
+ FindSymbolInFtor &&FindSymbolIn)
+ : AddModuleSet(AddModuleSet), RemoveModuleSet(RemoveModuleSet),
+ FindSymbol(FindSymbol), FindSymbolIn(FindSymbolIn)
+ {}
+
+ template <typename ModuleSetT, typename MemoryManagerPtrT,
+ typename SymbolResolverPtrT>
+ ModuleSetHandleT addModuleSet(ModuleSetT Ms, MemoryManagerPtrT MemMgr,
+ SymbolResolverPtrT Resolver) {
+ return AddModuleSet(std::move(Ms), std::move(MemMgr), std::move(Resolver));
+ }
+
+ void removeModuleSet(ModuleSetHandleT H) {
+ RemoveModuleSet(H);
+ }
+
+ orc::JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
+ return FindSymbol(Name, ExportedSymbolsOnly);
+ }
+
+ orc::JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
+ bool ExportedSymbolsOnly) {
+ return FindSymbolIn(H, Name, ExportedSymbolsOnly);
+ }
+
+private:
+ AddModuleSetFtor AddModuleSet;
+ RemoveModuleSetFtor RemoveModuleSet;
+ FindSymbolFtor FindSymbol;
+ FindSymbolInFtor FindSymbolIn;
+};
+
+template <typename ModuleSetHandleT,
+ typename AddModuleSetFtor,
+ typename RemoveModuleSetFtor,
+ typename FindSymbolFtor,
+ typename FindSymbolInFtor>
+MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
+ FindSymbolFtor, FindSymbolInFtor>
+createMockBaseLayer(AddModuleSetFtor &&AddModuleSet,
+ RemoveModuleSetFtor &&RemoveModuleSet,
+ FindSymbolFtor &&FindSymbol,
+ FindSymbolInFtor &&FindSymbolIn) {
+ return MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
+ FindSymbolFtor, FindSymbolInFtor>(
+ std::forward<AddModuleSetFtor>(AddModuleSet),
+ std::forward<RemoveModuleSetFtor>(RemoveModuleSet),
+ std::forward<FindSymbolFtor>(FindSymbol),
+ std::forward<FindSymbolInFtor>(FindSymbolIn));
+}
+
+template <typename ReturnT>
+class DoNothingAndReturn {
+public:
+ DoNothingAndReturn(ReturnT Val) : Val(Val) {}
+
+ template <typename... Args>
+ ReturnT operator()(Args...) const { return Val; }
+private:
+ ReturnT Val;
+};
+
+template <>
+class DoNothingAndReturn<void> {
+public:
+ template <typename... Args>
+ void operator()(Args...) const { }
+};
} // namespace llvm
More information about the llvm-commits
mailing list