[llvm] r284659 - [PGO] Fix bogus warning for merging empty llvm profile file

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 15:51:18 PDT 2016


Author: xur
Date: Wed Oct 19 17:51:17 2016
New Revision: 284659

URL: http://llvm.org/viewvc/llvm-project?rev=284659&view=rev
Log:
[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

Added:
    llvm/trunk/test/tools/llvm-profdata/Inputs/IR_profile.proftext
    llvm/trunk/test/tools/llvm-profdata/Inputs/clang_profile.proftext
    llvm/trunk/test/tools/llvm-profdata/merge_empty_profile.test
Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProf.h
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=284659&r1=284658&r2=284659&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Wed Oct 19 17:51:17 2016
@@ -292,7 +292,8 @@ enum class instrprof_error {
   counter_overflow,
   value_site_count_mismatch,
   compress_failed,
-  uncompress_failed
+  uncompress_failed,
+  empty_raw_profile
 };
 
 inline std::error_code make_error_code(instrprof_error E) {

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=284659&r1=284658&r2=284659&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Wed Oct 19 17:51:17 2016
@@ -70,6 +70,8 @@ std::string getInstrProfErrString(instrp
     return "Failed to compress data (zlib)";
   case instrprof_error::uncompress_failed:
     return "Failed to uncompress data (zlib)";
+  case instrprof_error::empty_raw_profile:
+    return "Empty raw profile file";
   }
   llvm_unreachable("A value of instrprof_error has no message.");
 }

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=284659&r1=284658&r2=284659&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Wed Oct 19 17:51:17 2016
@@ -46,6 +46,9 @@ InstrProfReader::create(std::unique_ptr<
   if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
     return make_error<InstrProfError>(instrprof_error::too_large);
 
+  if (Buffer->getBufferSize() == 0)
+    return make_error<InstrProfError>(instrprof_error::empty_raw_profile);
+
   std::unique_ptr<InstrProfReader> Result;
   // Create the reader.
   if (IndexedInstrProfReader::hasFormat(*Buffer))

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/IR_profile.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/IR_profile.proftext?rev=284659&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/IR_profile.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/IR_profile.proftext Wed Oct 19 17:51:17 2016
@@ -0,0 +1,9 @@
+:ir
+main
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+1
+

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/clang_profile.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/clang_profile.proftext?rev=284659&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/clang_profile.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/clang_profile.proftext Wed Oct 19 17:51:17 2016
@@ -0,0 +1,8 @@
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+

Added: llvm/trunk/test/tools/llvm-profdata/merge_empty_profile.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/merge_empty_profile.test?rev=284659&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/merge_empty_profile.test (added)
+++ llvm/trunk/test/tools/llvm-profdata/merge_empty_profile.test Wed Oct 19 17:51:17 2016
@@ -0,0 +1,17 @@
+# Tests for merge of empty profile files.
+
+RUN: touch %t_empty.proftext
+RUN: llvm-profdata merge -text -o %t_clang.proftext %t_empty.proftext %p/Inputs/clang_profile.proftext
+RUN: FileCheck --input-file=%t_clang.proftext %s -check-prefix=CLANG_PROF_TEXT
+CLANG_PROF_TEXT: main
+CLANG_PROF_TEXT: 0
+CLANG_PROF_TEXT: 1
+CLANG_PROF_TEXT: 1
+
+RUN: llvm-profdata merge -text -o %t_ir.proftext %t_empty.proftext %p/Inputs/IR_profile.proftext
+RUN: FileCheck --input-file=%t_ir.proftext %s -check-prefix=IR_PROF_TEXT
+IR_PROF_TEXT: :ir
+IR_PROF_TEXT: main
+IR_PROF_TEXT: 0
+IR_PROF_TEXT: 1
+IR_PROF_TEXT: 1

Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=284659&r1=284658&r2=284659&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Wed Oct 19 17:51:17 2016
@@ -140,8 +140,13 @@ static void loadInput(const WeightedFile
   WC->ErrWhence = Input.Filename;
 
   auto ReaderOrErr = InstrProfReader::create(Input.Filename);
-  if ((WC->Err = ReaderOrErr.takeError()))
+  if (Error E = ReaderOrErr.takeError()) {
+    // Skip the empty profiles by returning sliently.
+    instrprof_error IPE = InstrProfError::take(std::move(E));
+    if (IPE != instrprof_error::empty_raw_profile)
+      WC->Err = make_error<InstrProfError>(IPE);
     return;
+  }
 
   auto Reader = std::move(ReaderOrErr.get());
   bool IsIRProfile = Reader->isIRLevelProfile();




More information about the llvm-commits mailing list