[PATCH] D25687: [PGO] fix bogus warning for merging empty llvm profile file

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 10:26:47 PDT 2016


xur updated this revision to Diff 75028.
xur added a comment.

Integrated the review comments from David and Vedant:
(1) add a test,
(2) split the use-after-move fix to another patch.

Thanks!

-Rong


https://reviews.llvm.org/D25687

Files:
  include/llvm/ProfileData/InstrProfReader.h
  lib/ProfileData/InstrProfReader.cpp
  test/tools/llvm-profdata/Inputs/IR_profile.proftext
  test/tools/llvm-profdata/Inputs/clang_profile.proftext
  test/tools/llvm-profdata/merge_empty_profile.test
  tools/llvm-profdata/llvm-profdata.cpp


Index: tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- tools/llvm-profdata/llvm-profdata.cpp
+++ tools/llvm-profdata/llvm-profdata.cpp
@@ -144,6 +144,9 @@
     return;
 
   auto Reader = std::move(ReaderOrErr.get());
+  // Nullptr Reader means the file is empty. Skip it.
+  if (!Reader)
+    return;
   bool IsIRProfile = Reader->isIRLevelProfile();
   if (WC->Writer.setIsIRLevelProfile(IsIRProfile)) {
     WC->Err = make_error<StringError>(
Index: test/tools/llvm-profdata/merge_empty_profile.test
===================================================================
--- test/tools/llvm-profdata/merge_empty_profile.test
+++ test/tools/llvm-profdata/merge_empty_profile.test
@@ -0,0 +1,16 @@
+# Tests for merge of empty profile files.
+
+RUN: llvm-profdata merge -text -o %t_clang.proftext %p/Inputs/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 %p/Inputs/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
Index: test/tools/llvm-profdata/Inputs/clang_profile.proftext
===================================================================
--- test/tools/llvm-profdata/Inputs/clang_profile.proftext
+++ test/tools/llvm-profdata/Inputs/clang_profile.proftext
@@ -0,0 +1,8 @@
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
Index: test/tools/llvm-profdata/Inputs/IR_profile.proftext
===================================================================
--- test/tools/llvm-profdata/Inputs/IR_profile.proftext
+++ test/tools/llvm-profdata/Inputs/IR_profile.proftext
@@ -0,0 +1,9 @@
+:ir
+main
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+1
+
Index: lib/ProfileData/InstrProfReader.cpp
===================================================================
--- lib/ProfileData/InstrProfReader.cpp
+++ lib/ProfileData/InstrProfReader.cpp
@@ -46,6 +46,10 @@
   if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
     return make_error<InstrProfError>(instrprof_error::too_large);
 
+  // Return nullptr for an empty file.
+  if (Buffer->getBufferSize() == 0)
+    return std::unique_ptr<InstrProfReader>{};
+
   std::unique_ptr<InstrProfReader> Result;
   // Create the reader.
   if (IndexedInstrProfReader::hasFormat(*Buffer))
Index: include/llvm/ProfileData/InstrProfReader.h
===================================================================
--- include/llvm/ProfileData/InstrProfReader.h
+++ include/llvm/ProfileData/InstrProfReader.h
@@ -104,7 +104,7 @@
   }
 
   /// Factory method to create an appropriately typed reader for the given
-  /// instrprof file.
+  /// instrprof file. Nullptr will be returned for an empty profile file.
   static Expected<std::unique_ptr<InstrProfReader>> create(const Twine &Path);
 
   static Expected<std::unique_ptr<InstrProfReader>>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25687.75028.patch
Type: text/x-patch
Size: 3161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161018/a02377c0/attachment.bin>


More information about the llvm-commits mailing list