diff options
author | Teresa Johnson <tejohnson@google.com> | 2025-01-14 13:46:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-14 13:46:34 -0800 |
commit | 6a214ec1eeef6b404bf111edeca13c6e0d958103 (patch) | |
tree | b2f28f48cb3a1b693b6445bb3ec4d98e6a06295f /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | f09db6a3af971ab7d9bbc7ba574a8dc0c10b2940 (diff) | |
download | llvm-6a214ec1eeef6b404bf111edeca13c6e0d958103.zip llvm-6a214ec1eeef6b404bf111edeca13c6e0d958103.tar.gz llvm-6a214ec1eeef6b404bf111edeca13c6e0d958103.tar.bz2 |
[MemProf] Fix an assertion when writing distributed index for aliasee (#122946)
The ThinLTO index bitcode writer uses a helper forEachSummary to manage
preparation and writing of summaries needed for each distributed index
file. For alias summaries, it invokes the provided callback for the
aliasee as well, as we at least need to produce a value id for the
alias's summary. However, all summary generation for the aliasee itself
should be skipped on calls when IsAliasee is true. We invoke the
callback again if that value's summary is to be written as well.
We were asserting in debug mode when invoking collectMemProfCallStacks,
because a given stack id index was not in the StackIdIndicesToIndex
map. It was not added because the forEachSummary invocation that records
these ids in the map (invoked from the IndexBitcodeWriter constructor)
was correctly skipping this handling when invoked for aliasees. We need
the same guard in the invocation that calls collectMemProfCallStacks.
Note that this doesn't cause any real problems in a non-asserts build
as the missing map lookup will return the default 0 value from the map,
which isn't used since we don't actually write the corresponding
summary.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 94d3afa..31c9640 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -494,6 +494,9 @@ public: // are currently saved in the index in terms of GUID. forEachSummary([&](GVInfo I, bool IsAliasee) { GUIDToValueIdMap[I.first] = ++GlobalValueId; + // If this is invoked for an aliasee, we want to record the above mapping, + // but not the information needed for its summary entry (if the aliasee is + // to be imported, we will invoke this separately with IsAliasee=false). if (IsAliasee) return; auto *FS = dyn_cast<FunctionSummary>(I.second); @@ -4847,6 +4850,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { // radix tree array are identified based on this order. MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks; forEachSummary([&](GVInfo I, bool IsAliasee) { + // Don't collect this when invoked for an aliasee, as it is not needed for + // the alias summary. If the aliasee is to be imported, we will invoke this + // separately with IsAliasee=false. + if (IsAliasee) + return; GlobalValueSummary *S = I.second; assert(S); auto *FS = dyn_cast<FunctionSummary>(S); |