Skip to content

Commit 1040cdd

Browse files
Address a comment.
1 parent f4650c9 commit 1040cdd

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

llvm/include/llvm/ProfileData/DataAccessProf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ class DataAccessProfData {
185185
ArrayRef<uint64_t> getKnownColdHashes() const {
186186
return KnownColdHashes.getArrayRef();
187187
}
188+
[[nodiscard]] bool empty() const {
189+
return Records.empty() && KnownColdSymbols.empty() &&
190+
KnownColdHashes.empty();
191+
}
188192

189193
private:
190194
/// Serialize the symbol strings into the output stream.

llvm/test/tools/llvm-profdata/memprof-yaml.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out-no-dap.yaml
1919
; RUN: diff -b %t/memprof-in-no-dap.yaml %t/memprof-out-no-dap.yaml
2020

21+
; memprof-in-no-heap.yaml has empty heap access profiles.
22+
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-no-heap.yaml -o %t/memprof-out-no-heap.indexed
23+
; RUN: llvm-profdata show --memory %t/memprof-out-no-heap.indexed > %t/memprof-out-no-heap.yaml
24+
; RUN: diff -b %t/memprof-in-no-heap.yaml %t/memprof-out-no-heap.yaml
25+
2126
;--- memprof-in.yaml
2227
---
2328
# MemProfSummary:
@@ -151,3 +156,32 @@ HeapProfileRecords:
151156
- { Function: 0x8888888888888888, LineOffset: 88, Column: 80, IsInlineFrame: false }
152157
CalleeGuids: [ 0x300 ]
153158
...
159+
;--- memprof-in-no-heap.yaml
160+
---
161+
# MemProfSummary:
162+
# Total contexts: 0
163+
# Total cold contexts: 0
164+
# Total hot contexts: 0
165+
# Maximum cold context total size: 0
166+
# Maximum warm context total size: 0
167+
# Maximum hot context total size: 0
168+
---
169+
DataAccessProfiles:
170+
SampledRecords:
171+
- Symbol: abcde
172+
AccessCount: 100
173+
Locations:
174+
- FileName: file2.h
175+
Line: 123
176+
- FileName: file3.cpp
177+
Line: 456
178+
- Hash: 101010
179+
AccessCount: 200
180+
Locations:
181+
- FileName: file.cpp
182+
Line: 233
183+
KnownColdSymbols:
184+
- foo
185+
- bar
186+
KnownColdStrHashes: [ 999, 1001 ]
187+
...

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
760760
auto DataAccessProfData = Reader->takeDataAccessProfData();
761761

762762
// Check for the empty input in case the YAML file is invalid.
763-
if (MemProfData.Records.empty()) {
763+
if (MemProfData.Records.empty() &&
764+
(!DataAccessProfData || DataAccessProfData->empty())) {
764765
WC->Errors.emplace_back(
765766
make_error<StringError>("The profile is empty.", std::error_code()),
766767
Filename);

0 commit comments

Comments
 (0)