OSDN Git Service

[AVX-512] Add support for selecting 512-bit VPABSB/VPABSW when BWI is available.
[android-x86/external-llvm.git] / include / llvm / ExecutionEngine / Orc / LogicalDylib.h
1 //===--- LogicalDylib.h - Simulates dylib-style symbol lookup ---*- C++ -*-===//
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 // Simulates symbol resolution inside a dylib.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
15 #define LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
16
17 #include "llvm/ExecutionEngine/JITSymbol.h"
18 #include <string>
19 #include <vector>
20
21 namespace llvm {
22 namespace orc {
23
24 template <typename BaseLayerT,
25           typename LogicalModuleResources,
26           typename LogicalDylibResources>
27 class LogicalDylib {
28 public:
29   typedef typename BaseLayerT::ModuleSetHandleT BaseLayerModuleSetHandleT;
30 private:
31
32   typedef std::vector<BaseLayerModuleSetHandleT> BaseLayerHandleList;
33
34   struct LogicalModule {
35     // Make this move-only to ensure they don't get duplicated across moves of
36     // LogicalDylib or anything like that.
37     LogicalModule(LogicalModule &&RHS)
38         : Resources(std::move(RHS.Resources)),
39           BaseLayerHandles(std::move(RHS.BaseLayerHandles)) {}
40     LogicalModule() = default;
41     LogicalModuleResources Resources;
42     BaseLayerHandleList BaseLayerHandles;
43   };
44   typedef std::vector<LogicalModule> LogicalModuleList;
45
46 public:
47
48   typedef typename BaseLayerHandleList::iterator BaseLayerHandleIterator;
49   typedef typename LogicalModuleList::size_type LogicalModuleHandle;
50
51   LogicalDylib(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
52
53   ~LogicalDylib() {
54     for (auto &LM : LogicalModules)
55       for (auto BLH : LM.BaseLayerHandles)
56         BaseLayer.removeModuleSet(BLH);
57   }
58
59   // If possible, remove this and ~LogicalDylib once the work in the dtor is
60   // moved to members (eg: self-unregistering base layer handles).
61   LogicalDylib(LogicalDylib &&RHS)
62       : BaseLayer(std::move(RHS.BaseLayer)),
63         LogicalModules(std::move(RHS.LogicalModules)),
64         DylibResources(std::move(RHS.DylibResources)) {}
65
66   LogicalModuleHandle createLogicalModule() {
67     LogicalModules.push_back(LogicalModule());
68     return LogicalModules.size() - 1;
69   }
70
71   void addToLogicalModule(LogicalModuleHandle LMH,
72                           BaseLayerModuleSetHandleT BaseLayerHandle) {
73     LogicalModules[LMH].BaseLayerHandles.push_back(BaseLayerHandle);
74   }
75
76   LogicalModuleResources& getLogicalModuleResources(LogicalModuleHandle LMH) {
77     return LogicalModules[LMH].Resources;
78   }
79
80   BaseLayerHandleIterator moduleHandlesBegin(LogicalModuleHandle LMH) {
81     return LogicalModules[LMH].BaseLayerHandles.begin();
82   }
83
84   BaseLayerHandleIterator moduleHandlesEnd(LogicalModuleHandle LMH) {
85     return LogicalModules[LMH].BaseLayerHandles.end();
86   }
87
88   JITSymbol findSymbolInLogicalModule(LogicalModuleHandle LMH,
89                                       const std::string &Name,
90                                       bool ExportedSymbolsOnly) {
91
92     if (auto StubSym =
93           LogicalModules[LMH].Resources.findSymbol(Name, ExportedSymbolsOnly))
94       return StubSym;
95
96     for (auto BLH : LogicalModules[LMH].BaseLayerHandles)
97       if (auto Symbol = BaseLayer.findSymbolIn(BLH, Name, ExportedSymbolsOnly))
98         return Symbol;
99     return nullptr;
100   }
101
102   JITSymbol findSymbolInternally(LogicalModuleHandle LMH,
103                                  const std::string &Name) {
104     if (auto Symbol = findSymbolInLogicalModule(LMH, Name, false))
105       return Symbol;
106
107     for (typename LogicalModuleList::size_type I = 0, E = LogicalModules.size();
108          I != E; ++I) {
109       if (I != LMH)
110         if (auto Symbol = findSymbolInLogicalModule(I, Name, false))
111           return Symbol;
112     }
113
114     return nullptr;
115   }
116
117   JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
118     for (typename LogicalModuleList::size_type I = 0, E = LogicalModules.size();
119          I != E; ++I)
120       if (auto Sym = findSymbolInLogicalModule(I, Name, ExportedSymbolsOnly))
121         return Sym;
122     return nullptr;
123   }
124
125   LogicalDylibResources& getDylibResources() { return DylibResources; }
126
127   LogicalModuleResources*
128   getLogicalModuleResourcesForSymbol(const std::string &Name,
129                                      bool ExportedSymbolsOnly) {
130     for (typename LogicalModuleList::size_type I = 0, E = LogicalModules.size();
131          I != E; ++I)
132       if (auto Sym = LogicalModules[I].Resources.findSymbol(Name, ExportedSymbolsOnly))
133         return &LogicalModules[I].Resources;
134     return nullptr;
135   }
136
137 protected:
138   BaseLayerT BaseLayer;
139   LogicalModuleList LogicalModules;
140   LogicalDylibResources DylibResources;
141 };
142
143 } // End namespace orc.
144 } // End namespace llvm.
145
146 #endif // LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H