1 //===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
10 #include "OrcTestCommon.h"
11 #include "gtest/gtest.h"
14 using namespace llvm::orc
;
18 class DummyTrampolinePool
: public orc::TrampolinePool
{
20 Expected
<JITTargetAddress
> getTrampoline() {
21 llvm_unreachable("Unimplemented");
25 class DummyCallbackManager
: public JITCompileCallbackManager
{
27 DummyCallbackManager(ExecutionSession
&ES
)
28 : JITCompileCallbackManager(std::make_unique
<DummyTrampolinePool
>(), ES
,
32 class DummyStubsManager
: public orc::IndirectStubsManager
{
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) {
61 return JITSymbol(1, JITSymbolFlags::Exported
);
62 return JITSymbol(nullptr);
66 ExecutionSession
ES(std::make_shared
<SymbolStringPool
>());
67 DummyCallbackManager
CallbackMgr(ES
);
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 "