Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit c887230

Browse files
committed
[PGO] Fix bogus warning for merging empty llvm profile file
Profile runtime can generate an empty raw profile (when there is no function in the shared library). This empty profile is treated as a text format profile. A test format profile without the flag of "#IR" is thought to be a clang generated profile. So in llvm profile merging, we will get a bogus warning of "Merge IR generated profile with Clang generated profile." The fix here is to skip the empty profile (when the buffer size is 0) for profile merge. Reviewers: vsk, davidxl Differential Revision: http://reviews.llvm.org/D25687 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284659 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 207b6ab commit c887230

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

include/llvm/ProfileData/InstrProf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ enum class instrprof_error {
292292
counter_overflow,
293293
value_site_count_mismatch,
294294
compress_failed,
295-
uncompress_failed
295+
uncompress_failed,
296+
empty_raw_profile
296297
};
297298

298299
inline std::error_code make_error_code(instrprof_error E) {

lib/ProfileData/InstrProf.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ std::string getInstrProfErrString(instrprof_error Err) {
7070
return "Failed to compress data (zlib)";
7171
case instrprof_error::uncompress_failed:
7272
return "Failed to uncompress data (zlib)";
73+
case instrprof_error::empty_raw_profile:
74+
return "Empty raw profile file";
7375
}
7476
llvm_unreachable("A value of instrprof_error has no message.");
7577
}

lib/ProfileData/InstrProfReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
4646
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
4747
return make_error<InstrProfError>(instrprof_error::too_large);
4848

49+
if (Buffer->getBufferSize() == 0)
50+
return make_error<InstrProfError>(instrprof_error::empty_raw_profile);
51+
4952
std::unique_ptr<InstrProfReader> Result;
5053
// Create the reader.
5154
if (IndexedInstrProfReader::hasFormat(*Buffer))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:ir
2+
main
3+
# Func Hash:
4+
12884901887
5+
# Num Counters:
6+
1
7+
# Counter Values:
8+
1
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
main
2+
# Func Hash:
3+
0
4+
# Num Counters:
5+
1
6+
# Counter Values:
7+
1
8+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Tests for merge of empty profile files.
2+
3+
RUN: touch %t_empty.proftext
4+
RUN: llvm-profdata merge -text -o %t_clang.proftext %t_empty.proftext %p/Inputs/clang_profile.proftext
5+
RUN: FileCheck --input-file=%t_clang.proftext %s -check-prefix=CLANG_PROF_TEXT
6+
CLANG_PROF_TEXT: main
7+
CLANG_PROF_TEXT: 0
8+
CLANG_PROF_TEXT: 1
9+
CLANG_PROF_TEXT: 1
10+
11+
RUN: llvm-profdata merge -text -o %t_ir.proftext %t_empty.proftext %p/Inputs/IR_profile.proftext
12+
RUN: FileCheck --input-file=%t_ir.proftext %s -check-prefix=IR_PROF_TEXT
13+
IR_PROF_TEXT: :ir
14+
IR_PROF_TEXT: main
15+
IR_PROF_TEXT: 0
16+
IR_PROF_TEXT: 1
17+
IR_PROF_TEXT: 1

tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
140140
WC->ErrWhence = Input.Filename;
141141

142142
auto ReaderOrErr = InstrProfReader::create(Input.Filename);
143-
if ((WC->Err = ReaderOrErr.takeError()))
143+
if (Error E = ReaderOrErr.takeError()) {
144+
// Skip the empty profiles by returning sliently.
145+
instrprof_error IPE = InstrProfError::take(std::move(E));
146+
if (IPE != instrprof_error::empty_raw_profile)
147+
WC->Err = make_error<InstrProfError>(IPE);
144148
return;
149+
}
145150

146151
auto Reader = std::move(ReaderOrErr.get());
147152
bool IsIRProfile = Reader->isIRLevelProfile();

0 commit comments

Comments
 (0)