diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3825,7 +3825,8 @@ Flags |= 0x10; Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef{Flags}); - for (const auto &GVI : valueIds()) { + const std::map &ValueIds = valueIds(); + for (const auto &GVI : ValueIds) { Stream.EmitRecord(bitc::FS_VALUE_GUID, ArrayRef{GVI.second, GVI.first}); } @@ -3904,9 +3905,13 @@ NameVals.clear(); }; + std::set DefOrUseGUIDs; forEachSummary([&](GVInfo I, bool IsAliasee) { GlobalValueSummary *S = I.second; assert(S); + DefOrUseGUIDs.insert(I.first); + for (const ValueInfo &VI : S->refs()) + DefOrUseGUIDs.insert(VI.getGUID()); auto ValueId = getValueId(I.first); assert(ValueId); @@ -4047,20 +4052,28 @@ if (!Index.cfiFunctionDefs().empty()) { for (auto &S : Index.cfiFunctionDefs()) { - NameVals.push_back(StrtabBuilder.add(S)); - NameVals.push_back(S.size()); + if (DefOrUseGUIDs.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) { + NameVals.push_back(StrtabBuilder.add(S)); + NameVals.push_back(S.size()); + } + } + if (!NameVals.empty()) { + Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals); + NameVals.clear(); } - Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals); - NameVals.clear(); } if (!Index.cfiFunctionDecls().empty()) { for (auto &S : Index.cfiFunctionDecls()) { - NameVals.push_back(StrtabBuilder.add(S)); - NameVals.push_back(S.size()); + if (DefOrUseGUIDs.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) { + NameVals.push_back(StrtabBuilder.add(S)); + NameVals.push_back(S.size()); + } + } + if (!NameVals.empty()) { + Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals); + NameVals.clear(); } - Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals); - NameVals.clear(); } // Walk the GUIDs that were referenced, and write the