LLVM: lib/TextAPI/RecordsSlice.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
18#include
19
20using namespace llvm;
22
25
26 auto [APIName, SymKind, InterfaceType] = parseSymbol(Name);
27 Name = APIName;
28 switch (SymKind) {
30 return addGlobal(Name, Linkage, GV, Flags);
35
36
39 return Rec;
40 }
42 auto [Super, IVar] = Name.split('.');
43
45
46 if (Container == nullptr)
48 return addObjCIVar(Container, IVar, Linkage);
49 }
50 }
51
52 llvm_unreachable("unexpected symbol kind when adding to Record Slice");
53}
54
57 StringRef Super = IsIVar ? Name.split('.').first : Name;
59
60
61 if (Container == nullptr)
63 return Container;
64}
65
66template <typename R, typename C = RecordMap, typename K = StringRef>
68 const auto *Record = Container.find(Key);
69 if (Record == Container.end())
70 return nullptr;
71 return Record->second.get();
72}
73
78 return nullptr;
79
80 switch (GV) {
82 if (->isVariable())
83 return nullptr;
84 break;
85 }
87 if (->isFunction())
88 return nullptr;
89 break;
90 }
93 }
94
96}
97
101 "expected single ObjCIFSymbolKind enum value");
103 return Linkages.Class;
104
106 return Linkages.MetaClass;
107
109 return Linkages.EHType;
110
112}
113
117 Linkages.Class = std::max(Link, Linkages.Class);
119 Linkages.MetaClass = std::max(Link, Linkages.MetaClass);
121 Linkages.EHType = std::max(Link, Linkages.EHType);
122
123
124
125
126
128 std::max(Linkages.Class, std::max(Linkages.MetaClass, Linkages.EHType));
129}
130
134
140
144
147
148 if (IsScopedName) {
149
150 auto *Container = findContainer(true, Name);
151 if (!Container)
152 return nullptr;
153
154 StringRef IVar = Name.substr(Name.find_first_of('.') + 1);
155 return Container->findObjCIVar(IVar);
156 }
157
158
160 for (const auto &[_, Container] : Records) {
161 if (auto *IVarR = Container->findObjCIVar(Name))
162 return IVarR;
163 }
164 return nullptr;
165 };
166
167 if (auto *IVarRecord = getIVar(Classes))
168 return IVarRecord;
169
170 return getIVar(Categories);
171}
172
175 bool Inlined) {
180
182 auto Result = Globals.try_emplace(Name);
183 if (Result.second)
184 Result.first->second =
185 std::make_unique(Name, Linkage, Flags, GV, Inlined);
186 else {
187 updateLinkage(Result.first->second.get(), Linkage);
188 updateFlags(Result.first->second.get(), Flags);
189 }
190 return Result.first->second.get();
191}
192
197 auto Result = Classes.try_emplace(Name);
198 if (Result.second)
199 Result.first->second =
200 std::make_unique(Name, Linkage, SymType);
201 else
202 Result.first->second->updateLinkageForSymbols(SymType, Linkage);
203 return Result.first->second.get();
204}
205
207
208 switch (Linkage) {
211 return Flags;
214 return Flags;
215 default:
216 return Flags;
217 }
218}
219
221 auto Result = Categories.insert({Name, Record});
222 return Result.second;
223}
224
228 ClassToExtend = copyString(ClassToExtend);
229
230
231 auto Result = Categories.try_emplace(std::make_pair(ClassToExtend, Category));
232 if (Result.second)
233 Result.first->second =
234 std::make_unique(ClassToExtend, Category);
235
236
238 ObjCClass->addObjCCategory(Result.first->second.get());
239
240 return Result.first->second.get();
241}
242
244 std::vector<ObjCIVarRecord *> Records;
245 Records.reserve(IVars.size());
246 for (const auto &Record : IVars)
249}
250
251std::vector<ObjCCategoryRecord *>
253 std::vector<ObjCCategoryRecord *> Records;
254 Records.reserve(Categories.size());
255 for (const auto &Record : Categories)
258}
259
262 auto Result = IVars.try_emplace(IVar);
263 if (Result.second)
264 Result.first->second = std::make_unique(IVar, Linkage);
265 return Result.first->second.get();
266}
267
273 updateLinkage(Record, Linkage);
275}
276
279 return {};
280
281 if (StringAllocator.identifyObject(String.data()))
283
284 void *Ptr = StringAllocator.Allocate(String.size(), 1);
286 return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
287}
288
291 BA = std::make_unique();
292 return *BA;
293}
294
296 for (auto &G : Globals)
297 V.visitGlobal(*G.second);
298 for (auto &C : Classes)
299 V.visitObjCInterface(*C.second);
300 for (auto &Cat : Categories)
301 V.visitObjCCategory(*Cat.second);
302}
303
304static std::unique_ptr
306
307 auto Symbols = std::make_unique();
308 for (auto &S : Slices) {
309 if (S->empty())
310 continue;
311 auto &BA = S->getBinaryAttrs();
312 if (BA.InstallName != InstallName)
313 continue;
314
316 !BA.TwoLevelNamespace);
318 }
319
320 auto File = std::make_unique(std::move(Symbols));
321 File->setInstallName(InstallName);
322
323 for (auto &S : Slices) {
324 if (S->empty())
325 continue;
326 auto &BA = S->getBinaryAttrs();
327 if (BA.InstallName != InstallName)
328 continue;
329 const Target &Targ = S->getTarget();
330 File->addTarget(Targ);
331 File->setFromBinaryAttrs(BA, Targ);
332 }
333
334 return File;
335}
336
337std::unique_ptr
339 std::unique_ptr File;
340 if (Slices.empty())
341 return File;
342
344 for (auto &S : Slices) {
345 auto Name = S->getBinaryAttrs().InstallName;
346 if (Name.empty())
347 continue;
348 InstallNames.insert(Name);
349 }
350
354
355 return File;
356}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static std::unique_ptr< InterfaceFile > createInterfaceFile(const Records &Slices, StringRef InstallName)
Definition RecordsSlice.cpp:305
R * findRecord(K Key, const C &Container)
Definition RecordsSlice.cpp:67
Implements the TAPI Record Collection Type.
This file implements a set that has insertion order iteration characteristics.
Implements the TAPI Record Types.
LLVM_ABI ObjCIVarRecord * addObjCIVar(StringRef IVar, RecordLinkage Linkage)
Definition RecordsSlice.cpp:260
LLVM_ABI ObjCIVarRecord * findObjCIVar(StringRef IVar) const
Definition RecordsSlice.cpp:141
LLVM_ABI std::vector< ObjCIVarRecord * > getObjCIVars() const
Definition RecordsSlice.cpp:243
LLVM_ABI RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const
Definition RecordsSlice.cpp:99
LLVM_ABI std::vector< ObjCCategoryRecord * > getObjCCategories() const
Definition RecordsSlice.cpp:252
LLVM_ABI bool addObjCCategory(ObjCCategoryRecord *Record)
Definition RecordsSlice.cpp:220
LLVM_ABI void updateLinkageForSymbols(ObjCIFSymbolKind SymType, RecordLinkage Link)
Definition RecordsSlice.cpp:114
Base class for any usage of traversing over collected Records.
LLVM_ABI StringRef copyString(StringRef String)
Store any strings owned by RecordSlice into allocator and return back reference to that.
Definition RecordsSlice.cpp:277
LLVM_ABI ObjCIVarRecord * findObjCIVar(bool IsScopedName, StringRef Name) const
Find ObjC instance variable.
Definition RecordsSlice.cpp:145
LLVM_ABI ObjCCategoryRecord * addObjCCategory(StringRef ClassToExtend, StringRef Category)
Add ObjC Category record.
Definition RecordsSlice.cpp:225
LLVM_ABI ObjCInterfaceRecord * addObjCInterface(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType)
Add ObjC Class record.
Definition RecordsSlice.cpp:193
LLVM_ABI ObjCContainerRecord * findContainer(bool IsIVar, StringRef Name) const
Find ObjC Container.
Definition RecordsSlice.cpp:55
LLVM_ABI ObjCIVarRecord * addObjCIVar(ObjCContainerRecord *Container, StringRef Name, RecordLinkage Linkage)
Add ObjC IVar record.
Definition RecordsSlice.cpp:268
LLVM_ABI GlobalRecord * addGlobal(StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV, SymbolFlags Flags=SymbolFlags::None, bool Inlined=false)
Add non-ObjC global record.
Definition RecordsSlice.cpp:173
LLVM_ABI GlobalRecord * findGlobal(StringRef Name, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown) const
Find non-objc global.
Definition RecordsSlice.cpp:74
LLVM_ABI ObjCCategoryRecord * findObjCCategory(StringRef ClassToExtend, StringRef Category) const
Find ObjC Category.
Definition RecordsSlice.cpp:135
LLVM_ABI BinaryAttrs & getBinaryAttrs()
Return reference to BinaryAttrs.
Definition RecordsSlice.cpp:289
LLVM_ABI ObjCInterfaceRecord * findObjCInterface(StringRef Name) const
Find ObjC Class.
Definition RecordsSlice.cpp:131
LLVM_ABI Record * addRecord(StringRef Name, SymbolFlags Flags, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown, RecordLinkage Linkage=RecordLinkage::Unknown)
Add unspecified record to slice.
Definition RecordsSlice.cpp:23
LLVM_ABI void visit(RecordVisitor &V) const
Definition RecordsSlice.cpp:295
bool hasBinaryAttrs() const
Specialized RecordVisitor for collecting exported symbols and undefined symbols if RecordSlice being ...
A vector that has set insertion semantics.
iterator begin()
Get an iterator to the beginning of the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI std::unique_ptr< InterfaceFile > convertToInterfaceFile(const Records &Slices)
Definition RecordsSlice.cpp:338
ObjCIFSymbolKind
ObjC Interface symbol mappings.
@ EHType
Is OBJC_EHTYPE* symbol.
@ Class
Is OBJC_CLASS* symbol.
@ MetaClass
Is OBJC_METACLASS* symbol.
@ ObjectiveCInstanceVariable
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
@ WeakDefined
Weak defined symbol.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key