@@ -1291,52 +1291,69 @@ struct TypeIdSummary {
1291
1291
};
1292
1292
1293
1293
class CfiFunctionIndex {
1294
- std::set<std::string, std::less<>> Index;
1294
+ DenseMap<GlobalValue::GUID, std::set<std::string, std::less<>>> Index;
1295
+ using IndexIterator =
1296
+ DenseMap<GlobalValue::GUID,
1297
+ std::set<std::string, std::less<>>>::const_iterator;
1298
+ using NestedIterator = std::set<std::string, std::less<>>::const_iterator;
1295
1299
1296
1300
public:
1297
- class GUIDIterator
1298
- : public iterator_adaptor_base<
1299
- GUIDIterator, std::set<std::string, std::less<>>::const_iterator,
1300
- std::forward_iterator_tag, GlobalValue::GUID> {
1301
- using base = iterator_adaptor_base<
1302
- GUIDIterator, std::set<std::string, std::less<>>::const_iterator,
1303
- std::forward_iterator_tag, GlobalValue::GUID>;
1301
+ // Iterates keys of the DenseMap.
1302
+ class GUIDIterator : public iterator_adaptor_base <GUIDIterator, IndexIterator,
1303
+ std::forward_iterator_tag,
1304
+ GlobalValue::GUID> {
1305
+ using base = GUIDIterator::iterator_adaptor_base;
1304
1306
1305
1307
public:
1306
1308
GUIDIterator () = default ;
1307
- explicit GUIDIterator (std::set<std::string, std::less<>>::const_iterator I)
1308
- : base(std::move(I)) {}
1309
+ explicit GUIDIterator (IndexIterator I) : base(I) {}
1309
1310
1310
- GlobalValue::GUID operator *() const {
1311
- return GlobalValue::getGUID (
1312
- GlobalValue::dropLLVMManglingEscape (*this ->wrapped ()));
1313
- }
1311
+ GlobalValue::GUID operator *() const { return this ->wrapped ()->first ; }
1314
1312
};
1315
1313
1316
1314
CfiFunctionIndex () = default ;
1317
- template <typename It> CfiFunctionIndex (It B, It E) : Index(B, E) {}
1318
-
1319
- std::set<std::string, std::less<>>::const_iterator begin () const {
1320
- return Index.begin ();
1315
+ template <typename It> CfiFunctionIndex (It B, It E) {
1316
+ for (; B != E; ++B)
1317
+ emplace (*B);
1321
1318
}
1322
1319
1323
- std::set<std::string, std::less<>>::const_iterator end () const {
1324
- return Index.end ();
1320
+ std::vector<StringRef> symbols () const {
1321
+ std::vector<StringRef> Symbols;
1322
+ for (auto &[GUID, Syms] : Index)
1323
+ Symbols.insert (Symbols.end (), Syms.begin (), Syms.end ());
1324
+ return Symbols;
1325
1325
}
1326
1326
1327
- std::vector<StringRef> symbols () const { return {begin (), end ()}; }
1328
-
1329
1327
GUIDIterator guid_begin () const { return GUIDIterator (Index.begin ()); }
1330
1328
GUIDIterator guid_end () const { return GUIDIterator (Index.end ()); }
1331
1329
iterator_range<GUIDIterator> guids () const {
1332
1330
return make_range (guid_begin (), guid_end ());
1333
1331
}
1334
1332
1333
+ iterator_range<NestedIterator> forGuid (GlobalValue::GUID GUID) const {
1334
+ auto I = Index.find (GUID);
1335
+ if (I == Index.end ())
1336
+ return make_range (NestedIterator{}, NestedIterator{});
1337
+ return make_range (I->second .begin (), I->second .end ());
1338
+ }
1339
+
1335
1340
template <typename ... Args> void emplace (Args &&...A) {
1336
- Index.emplace (std::forward<Args>(A)...);
1341
+ StringRef S (std::forward<Args>(A)...);
1342
+ GlobalValue::GUID GUID =
1343
+ GlobalValue::getGUID (GlobalValue::dropLLVMManglingEscape (S));
1344
+ Index[GUID].emplace (S);
1345
+ }
1346
+
1347
+ size_t count (StringRef S) const {
1348
+ GlobalValue::GUID GUID =
1349
+ GlobalValue::getGUID (GlobalValue::dropLLVMManglingEscape (S));
1350
+ auto I = Index.find (GUID);
1351
+ if (I == Index.end ())
1352
+ return 0 ;
1353
+ return I->second .count (S);
1337
1354
}
1338
1355
1339
- size_t count (StringRef S ) const { return Index.count (S ); }
1356
+ bool empty ( ) const { return Index.empty ( ); }
1340
1357
};
1341
1358
1342
1359
// / 160 bits SHA1
0 commit comments