llvm.org GIT mirror llvm / c887230
[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 Rong Xu 2 years ago
7 changed file(s) with 47 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
291291 counter_overflow,
292292 value_site_count_mismatch,
293293 compress_failed,
294 uncompress_failed
294 uncompress_failed,
295 empty_raw_profile
295296 };
296297
297298 inline std::error_code make_error_code(instrprof_error E) {
6969 return "Failed to compress data (zlib)";
7070 case instrprof_error::uncompress_failed:
7171 return "Failed to uncompress data (zlib)";
72 case instrprof_error::empty_raw_profile:
73 return "Empty raw profile file";
7274 }
7375 llvm_unreachable("A value of instrprof_error has no message.");
7476 }
4444 // Sanity check the buffer.
4545 if (Buffer->getBufferSize() > std::numeric_limits::max())
4646 return make_error(instrprof_error::too_large);
47
48 if (Buffer->getBufferSize() == 0)
49 return make_error(instrprof_error::empty_raw_profile);
4750
4851 std::unique_ptr Result;
4952 // Create the reader.
0 :ir
1 main
2 # Func Hash:
3 12884901887
4 # Num Counters:
5 1
6 # Counter Values:
7 1
8
0 main
1 # Func Hash:
2 0
3 # Num Counters:
4 1
5 # Counter Values:
6 1
7
0 # Tests for merge of empty profile files.
1
2 RUN: touch %t_empty.proftext
3 RUN: llvm-profdata merge -text -o %t_clang.proftext %t_empty.proftext %p/Inputs/clang_profile.proftext
4 RUN: FileCheck --input-file=%t_clang.proftext %s -check-prefix=CLANG_PROF_TEXT
5 CLANG_PROF_TEXT: main
6 CLANG_PROF_TEXT: 0
7 CLANG_PROF_TEXT: 1
8 CLANG_PROF_TEXT: 1
9
10 RUN: llvm-profdata merge -text -o %t_ir.proftext %t_empty.proftext %p/Inputs/IR_profile.proftext
11 RUN: FileCheck --input-file=%t_ir.proftext %s -check-prefix=IR_PROF_TEXT
12 IR_PROF_TEXT: :ir
13 IR_PROF_TEXT: main
14 IR_PROF_TEXT: 0
15 IR_PROF_TEXT: 1
16 IR_PROF_TEXT: 1
139139 WC->ErrWhence = Input.Filename;
140140
141141 auto ReaderOrErr = InstrProfReader::create(Input.Filename);
142 if ((WC->Err = ReaderOrErr.takeError()))
142 if (Error E = ReaderOrErr.takeError()) {
143 // Skip the empty profiles by returning sliently.
144 instrprof_error IPE = InstrProfError::take(std::move(E));
145 if (IPE != instrprof_error::empty_raw_profile)
146 WC->Err = make_error(IPE);
143147 return;
148 }
144149
145150 auto Reader = std::move(ReaderOrErr.get());
146151 bool IsIRProfile = Reader->isIRLevelProfile();