diff options
author | Vitaly Buka <vitalybuka@google.com> | 2025-03-11 20:36:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-11 20:36:39 -0700 |
commit | 1585db458f040b5861d449a3a882388f8dcb6e62 (patch) | |
tree | 5393b46e7fc3a23efd58b230d11c7083e1f89764 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | bf2d1c46072a0461cb3ddcaefcafeccc2637995e (diff) | |
download | llvm-1585db458f040b5861d449a3a882388f8dcb6e62.zip llvm-1585db458f040b5861d449a3a882388f8dcb6e62.tar.gz llvm-1585db458f040b5861d449a3a882388f8dcb6e62.tar.bz2 |
[IR] Optimize CFI in `writeCombinedGlobalValueSummary` (#130382)
Before the patch,
`writeCombinedGlobalValueSummary` traversed entire
`cfiFunction*` for each module, just to pick a few
symbols from `DefOrUseGUIDs`.
Now we change internals of `cfiFunctionDefs` and
`cfiFunctionDecls` to maintain a map from GUID to StringSet.
So now we iterate `DefOrUseGUIDs`, usually small,
and pick exact subset of symbols.
Sorting is not strictly necessary, but it
preserves the order of emitted values.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 2f4802c..f6510a7 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -5064,19 +5064,25 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { getReferencedTypeIds(FS, ReferencedTypeIds); } + SmallVector<StringRef, 4> Functions; auto EmitCfiFunctions = [&](const CfiFunctionIndex &CfiIndex, bitc::GlobalValueSummarySymtabCodes Code) { - for (auto &S : CfiIndex) { - if (DefOrUseGUIDs.contains( - GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) { - NameVals.push_back(StrtabBuilder.add(S)); - NameVals.push_back(S.size()); - } + if (CfiIndex.empty()) + return; + for (GlobalValue::GUID GUID : DefOrUseGUIDs) { + auto Defs = CfiIndex.forGuid(GUID); + Functions.insert(Functions.end(), Defs.begin(), Defs.end()); } - if (!NameVals.empty()) { - Stream.EmitRecord(Code, NameVals); - NameVals.clear(); + if (Functions.empty()) + return; + llvm::sort(Functions); + for (const auto &S : Functions) { + NameVals.push_back(StrtabBuilder.add(S)); + NameVals.push_back(S.size()); } + Stream.EmitRecord(Code, NameVals); + NameVals.clear(); + Functions.clear(); }; EmitCfiFunctions(Index.cfiFunctionDefs(), bitc::FS_CFI_FUNCTION_DEFS); |