diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index 539c130af33fa..2183675d84e84 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -23,6 +23,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/IR/ConstantRange.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" @@ -1293,8 +1294,26 @@ class CfiFunctionIndex { std::set> Index; public: - CfiFunctionIndex() = default; + class GUIDIterator + : public iterator_adaptor_base< + GUIDIterator, std::set>::const_iterator, + std::forward_iterator_tag, GlobalValue::GUID> { + using base = iterator_adaptor_base< + GUIDIterator, std::set>::const_iterator, + std::forward_iterator_tag, GlobalValue::GUID>; + + public: + GUIDIterator() = default; + explicit GUIDIterator(std::set>::const_iterator I) + : base(std::move(I)) {} + + GlobalValue::GUID operator*() const { + return GlobalValue::getGUID( + GlobalValue::dropLLVMManglingEscape(*this->wrapped())); + } + }; + CfiFunctionIndex() = default; template CfiFunctionIndex(It B, It E) : Index(B, E) {} std::set>::const_iterator begin() const { @@ -1305,6 +1324,12 @@ class CfiFunctionIndex { return Index.end(); } + GUIDIterator guid_begin() const { return GUIDIterator(Index.begin()); } + GUIDIterator guid_end() const { return GUIDIterator(Index.end()); } + iterator_range guids() const { + return make_range(guid_begin(), guid_end()); + } + template void emplace(Args &&...A) { Index.emplace(std::forward(A)...); } diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index dfd4b5188907d..e895a46b8cd77 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1437,12 +1437,10 @@ class InProcessThinBackend : public ThinBackendProc { OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism), AddStream(std::move(AddStream)), Cache(std::move(Cache)), ShouldEmitIndexFiles(ShouldEmitIndexFiles) { - for (auto &Name : CombinedIndex.cfiFunctionDefs()) - CfiFunctionDefs.insert( - GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name))); - for (auto &Name : CombinedIndex.cfiFunctionDecls()) - CfiFunctionDecls.insert( - GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name))); + auto &Defs = CombinedIndex.cfiFunctionDefs(); + CfiFunctionDefs.insert(Defs.guid_begin(), Defs.guid_end()); + auto &Decls = CombinedIndex.cfiFunctionDecls(); + CfiFunctionDecls.insert(Decls.guid_begin(), Decls.guid_end()); } virtual Error runThinLTOBackendThread( @@ -1965,12 +1963,10 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, // Any functions referenced by the jump table in the regular LTO object must // be exported. - for (auto &Def : ThinLTO.CombinedIndex.cfiFunctionDefs()) - ExportedGUIDs.insert( - GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Def))); - for (auto &Decl : ThinLTO.CombinedIndex.cfiFunctionDecls()) - ExportedGUIDs.insert( - GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Decl))); + auto &Defs = ThinLTO.CombinedIndex.cfiFunctionDefs(); + ExportedGUIDs.insert(Defs.guid_begin(), Defs.guid_end()); + auto &Decls = ThinLTO.CombinedIndex.cfiFunctionDecls(); + ExportedGUIDs.insert(Decls.guid_begin(), Decls.guid_end()); auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) { const auto &ExportList = ExportLists.find(ModuleIdentifier);