Skip to content

Commit 7dd5f23

Browse files
authored
[NFC][LTO] Move GUID calculation into CfiFunctionIndex (llvm#130370)
Preparation for CFI Index refactoring, which will fix O(N^2) in ThinLTO indexing.
1 parent 3121da5 commit 7dd5f23

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/StringExtras.h"
2424
#include "llvm/ADT/StringMap.h"
2525
#include "llvm/ADT/StringRef.h"
26+
#include "llvm/ADT/iterator_range.h"
2627
#include "llvm/IR/ConstantRange.h"
2728
#include "llvm/IR/GlobalValue.h"
2829
#include "llvm/IR/Module.h"
@@ -1293,8 +1294,26 @@ class CfiFunctionIndex {
12931294
std::set<std::string, std::less<>> Index;
12941295

12951296
public:
1296-
CfiFunctionIndex() = default;
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>;
1304+
1305+
public:
1306+
GUIDIterator() = default;
1307+
explicit GUIDIterator(std::set<std::string, std::less<>>::const_iterator I)
1308+
: base(std::move(I)) {}
1309+
1310+
GlobalValue::GUID operator*() const {
1311+
return GlobalValue::getGUID(
1312+
GlobalValue::dropLLVMManglingEscape(*this->wrapped()));
1313+
}
1314+
};
12971315

1316+
CfiFunctionIndex() = default;
12981317
template <typename It> CfiFunctionIndex(It B, It E) : Index(B, E) {}
12991318

13001319
std::set<std::string, std::less<>>::const_iterator begin() const {
@@ -1305,6 +1324,12 @@ class CfiFunctionIndex {
13051324
return Index.end();
13061325
}
13071326

1327+
GUIDIterator guid_begin() const { return GUIDIterator(Index.begin()); }
1328+
GUIDIterator guid_end() const { return GUIDIterator(Index.end()); }
1329+
iterator_range<GUIDIterator> guids() const {
1330+
return make_range(guid_begin(), guid_end());
1331+
}
1332+
13081333
template <typename... Args> void emplace(Args &&...A) {
13091334
Index.emplace(std::forward<Args>(A)...);
13101335
}

llvm/lib/LTO/LTO.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,12 +1437,10 @@ class InProcessThinBackend : public ThinBackendProc {
14371437
OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism),
14381438
AddStream(std::move(AddStream)), Cache(std::move(Cache)),
14391439
ShouldEmitIndexFiles(ShouldEmitIndexFiles) {
1440-
for (auto &Name : CombinedIndex.cfiFunctionDefs())
1441-
CfiFunctionDefs.insert(
1442-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
1443-
for (auto &Name : CombinedIndex.cfiFunctionDecls())
1444-
CfiFunctionDecls.insert(
1445-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
1440+
auto &Defs = CombinedIndex.cfiFunctionDefs();
1441+
CfiFunctionDefs.insert(Defs.guid_begin(), Defs.guid_end());
1442+
auto &Decls = CombinedIndex.cfiFunctionDecls();
1443+
CfiFunctionDecls.insert(Decls.guid_begin(), Decls.guid_end());
14461444
}
14471445

14481446
virtual Error runThinLTOBackendThread(
@@ -1965,12 +1963,10 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
19651963

19661964
// Any functions referenced by the jump table in the regular LTO object must
19671965
// be exported.
1968-
for (auto &Def : ThinLTO.CombinedIndex.cfiFunctionDefs())
1969-
ExportedGUIDs.insert(
1970-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Def)));
1971-
for (auto &Decl : ThinLTO.CombinedIndex.cfiFunctionDecls())
1972-
ExportedGUIDs.insert(
1973-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Decl)));
1966+
auto &Defs = ThinLTO.CombinedIndex.cfiFunctionDefs();
1967+
ExportedGUIDs.insert(Defs.guid_begin(), Defs.guid_end());
1968+
auto &Decls = ThinLTO.CombinedIndex.cfiFunctionDecls();
1969+
ExportedGUIDs.insert(Decls.guid_begin(), Decls.guid_end());
19741970

19751971
auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) {
19761972
const auto &ExportList = ExportLists.find(ModuleIdentifier);

0 commit comments

Comments
 (0)