[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / unittests / ExecutionEngine / Orc / LegacyCompileOnDemandLayerTest.cpp
blob59cd11c5e5a683961c4b86d4cbbb60196d338978
1 //===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
10 #include "OrcTestCommon.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
14 using namespace llvm::orc;
16 namespace {
18 class DummyTrampolinePool : public orc::TrampolinePool {
19 public:
20 Expected<JITTargetAddress> getTrampoline() {
21 llvm_unreachable("Unimplemented");
25 class DummyCallbackManager : public JITCompileCallbackManager {
26 public:
27 DummyCallbackManager(ExecutionSession &ES)
28 : JITCompileCallbackManager(std::make_unique<DummyTrampolinePool>(), ES,
29 0) {}
32 class DummyStubsManager : public orc::IndirectStubsManager {
33 public:
34 Error createStub(StringRef StubName, JITTargetAddress InitAddr,
35 JITSymbolFlags Flags) override {
36 llvm_unreachable("Not implemented");
39 Error createStubs(const StubInitsMap &StubInits) override {
40 llvm_unreachable("Not implemented");
43 JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
44 llvm_unreachable("Not implemented");
47 JITEvaluatedSymbol findPointer(StringRef Name) override {
48 llvm_unreachable("Not implemented");
51 Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {
52 llvm_unreachable("Not implemented");
56 TEST(LegacyCompileOnDemandLayerTest, FindSymbol) {
57 MockBaseLayer<int, std::shared_ptr<Module>> TestBaseLayer;
58 TestBaseLayer.findSymbolImpl =
59 [](const std::string &Name, bool) {
60 if (Name == "foo")
61 return JITSymbol(1, JITSymbolFlags::Exported);
62 return JITSymbol(nullptr);
66 ExecutionSession ES(std::make_shared<SymbolStringPool>());
67 DummyCallbackManager CallbackMgr(ES);
69 auto GetResolver =
70 [](orc::VModuleKey) -> std::shared_ptr<llvm::orc::SymbolResolver> {
71 llvm_unreachable("Should never be called");
74 auto SetResolver = [](orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>) {
75 llvm_unreachable("Should never be called");
78 llvm::orc::LegacyCompileOnDemandLayer<decltype(TestBaseLayer)> COD(
79 AcknowledgeORCv1Deprecation, ES, TestBaseLayer, GetResolver, SetResolver,
80 [](Function &F) { return std::set<Function *>{&F}; }, CallbackMgr,
81 [] { return std::make_unique<DummyStubsManager>(); }, true);
83 auto Sym = COD.findSymbol("foo", true);
85 EXPECT_TRUE(!!Sym) << "CompileOnDemand::findSymbol should call findSymbol in "
86 "the base layer.";