• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
11 #include "OrcTestCommon.h"
12 #include "gtest/gtest.h"
13 
14 using namespace llvm;
15 using namespace llvm::orc;
16 
17 namespace {
18 
19 class DummyCallbackManager : public orc::JITCompileCallbackManager {
20 public:
DummyCallbackManager(ExecutionSession & ES)21   DummyCallbackManager(ExecutionSession &ES)
22       : JITCompileCallbackManager(ES, 0) {}
23 
24 public:
grow()25   Error grow() override { llvm_unreachable("not implemented"); }
26 };
27 
28 class DummyStubsManager : public orc::IndirectStubsManager {
29 public:
createStub(StringRef StubName,JITTargetAddress InitAddr,JITSymbolFlags Flags)30   Error createStub(StringRef StubName, JITTargetAddress InitAddr,
31                    JITSymbolFlags Flags) override {
32     llvm_unreachable("Not implemented");
33   }
34 
createStubs(const StubInitsMap & StubInits)35   Error createStubs(const StubInitsMap &StubInits) override {
36     llvm_unreachable("Not implemented");
37   }
38 
findStub(StringRef Name,bool ExportedStubsOnly)39   JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
40     llvm_unreachable("Not implemented");
41   }
42 
findPointer(StringRef Name)43   JITEvaluatedSymbol findPointer(StringRef Name) override {
44     llvm_unreachable("Not implemented");
45   }
46 
updatePointer(StringRef Name,JITTargetAddress NewAddr)47   Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {
48     llvm_unreachable("Not implemented");
49   }
50 };
51 
TEST(CompileOnDemandLayerTest,FindSymbol)52 TEST(CompileOnDemandLayerTest, FindSymbol) {
53   MockBaseLayer<int, std::shared_ptr<Module>> TestBaseLayer;
54   TestBaseLayer.findSymbolImpl =
55     [](const std::string &Name, bool) {
56       if (Name == "foo")
57         return JITSymbol(1, JITSymbolFlags::Exported);
58       return JITSymbol(nullptr);
59     };
60 
61 
62   ExecutionSession ES(std::make_shared<SymbolStringPool>());
63   DummyCallbackManager CallbackMgr(ES);
64 
65   auto GetResolver =
66       [](orc::VModuleKey) -> std::shared_ptr<llvm::orc::SymbolResolver> {
67     llvm_unreachable("Should never be called");
68   };
69 
70   auto SetResolver = [](orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>) {
71     llvm_unreachable("Should never be called");
72   };
73 
74   llvm::orc::CompileOnDemandLayer<decltype(TestBaseLayer)> COD(
75       ES, TestBaseLayer, GetResolver, SetResolver,
76       [](Function &F) { return std::set<Function *>{&F}; }, CallbackMgr,
77       [] { return llvm::make_unique<DummyStubsManager>(); }, true);
78 
79   auto Sym = COD.findSymbol("foo", true);
80 
81   EXPECT_TRUE(!!Sym) << "CompileOnDemand::findSymbol should call findSymbol in "
82                         "the base layer.";
83 }
84 }
85