OSDN Git Service

[AVX-512] Add support for selecting 512-bit VPABSB/VPABSW when BWI is available.
[android-x86/external-llvm.git] / unittests / ExecutionEngine / Orc / LogicalDylibTest.cpp
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 "OrcTestCommon.h"
11 #include "llvm/ExecutionEngine/Orc/LogicalDylib.h"
12 #include "gtest/gtest.h"
13
14 using namespace llvm;
15 using namespace llvm::orc;
16
17 namespace {
18
19
20 TEST(LogicalDylibTest, getLogicalModuleResourcesForSymbol) {
21
22   std::map<int, std::set<std::string>> ModuleSymbols;
23
24   ModuleSymbols[0] = std::set<std::string>({ "foo", "dummy" });
25   ModuleSymbols[1] = std::set<std::string>({ "bar" });
26   ModuleSymbols[2] = std::set<std::string>({ "baz", "dummy" });
27
28   auto MockBaseLayer = createMockBaseLayer<int>(
29       DoNothingAndReturn<int>(0),
30       DoNothingAndReturn<void>(),
31       [&](const std::string &Name, bool) {
32         for (auto &S : ModuleSymbols)
33           if (S.second.count(Name))
34             return JITSymbol(1, JITSymbolFlags::Exported);
35         return JITSymbol(nullptr);
36       },
37       [&](int H, const std::string &Name, bool) {
38         if (ModuleSymbols[H].count(Name))
39           return JITSymbol(1, JITSymbolFlags::Exported);
40         return JITSymbol(nullptr);
41       });
42
43   struct LDResources { };
44   struct LMResources {
45   public:
46     int ID;
47     std::set<std::string> *Symbols;
48
49     LMResources() : ID(0), Symbols(nullptr) {}
50     LMResources(int ID, std::set<std::string> &Symbols)
51         : ID(ID), Symbols(&Symbols) {}
52
53     JITSymbol findSymbol(const std::string &Name, bool) {
54       assert(Symbols);
55       if (Symbols->count(Name))
56         return JITSymbol(ID, JITSymbolFlags::Exported);
57       return JITSymbol(nullptr);
58     }
59   };
60
61   LogicalDylib<decltype(MockBaseLayer), LMResources, LDResources>
62     LD(MockBaseLayer);
63
64   // Add logical module resources for each of our dummy modules.
65   for (int I = 0; I < 3; ++I) {
66     auto H = LD.createLogicalModule();
67     LD.addToLogicalModule(H, I);
68     LD.getLogicalModuleResources(H) = LMResources(I, ModuleSymbols[I]);
69   }
70
71   {
72     auto LMR = LD.getLogicalModuleResourcesForSymbol("bar", true);
73     EXPECT_TRUE(LMR->ID == 1) << "getLogicalModuleResourcesForSymbol failed";
74   }
75 }
76 }