[llvm] ea23c38 - [llvm-profdata] Allow omission of -o for --text output

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 12:02:03 PDT 2021


Author: Fangrui Song
Date: 2021-06-21T12:01:57-07:00
New Revision: ea23c38d0605514f68e33d319a6bdd858381257a

URL: https://github.com/llvm/llvm-project/commit/ea23c38d0605514f68e33d319a6bdd858381257a
DIFF: https://github.com/llvm/llvm-project/commit/ea23c38d0605514f68e33d319a6bdd858381257a.diff

LOG: [llvm-profdata] Allow omission of -o for --text output

This makes it more convenient to get a text format profile.

Add an error for printing non-text format output to a terminal for instrumentation profile.
(It cannot be portably tested. For sample profile, raw_fd_ostream is hidden deeply so it's inconvenient to add a diagnostic.)

Reviewed By: davidxl

Differential Revision: https://reviews.llvm.org/D104600

Added: 
    

Modified: 
    llvm/test/tools/llvm-profdata/text-dump.test
    llvm/tools/llvm-profdata/llvm-profdata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-profdata/text-dump.test b/llvm/test/tools/llvm-profdata/text-dump.test
index a6cdfec4b4f7a..22acb6e23039a 100644
--- a/llvm/test/tools/llvm-profdata/text-dump.test
+++ b/llvm/test/tools/llvm-profdata/text-dump.test
@@ -2,6 +2,7 @@ Basic tests for testing text dump functions.
 
 RUN: llvm-profdata show --all-functions -counts --text %p/Inputs/basic.proftext > %t-basic.proftext1
 RUN: llvm-profdata merge -o %t-basic.proftext2 --text  %p/Inputs/basic.proftext
+RUN: llvm-profdata merge --text %p/Inputs/basic.proftext | 
diff  %t-basic.proftext2 -
 
 RUN: llvm-profdata merge -binary -o %t-basic.profdata1 %t-basic.proftext1
 RUN: llvm-profdata merge -o %t-basic.profdata2 %t-basic.proftext2

diff  --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 58d3b41cba1bf..b61df6eacdce5 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -316,6 +316,8 @@ static void writeInstrProfile(StringRef OutputFilename,
     if (Error E = Writer.writeText(Output))
       warn(std::move(E));
   } else {
+    if (Output.is_displayed())
+      exitWithError("cannot write a non-text format profile to the terminal");
     if (Error E = Writer.write(Output))
       warn(std::move(E));
   }
@@ -326,9 +328,6 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
                               StringRef OutputFilename,
                               ProfileFormat OutputFormat, bool OutputSparse,
                               unsigned NumThreads, FailureMode FailMode) {
-  if (OutputFilename.compare("-") == 0)
-    exitWithError("cannot write indexed profdata format to stdout");
-
   if (OutputFormat != PF_Binary && OutputFormat != PF_Compact_Binary &&
       OutputFormat != PF_Ext_Binary && OutputFormat != PF_Text)
     exitWithError("unknown format is specified");
@@ -863,8 +862,7 @@ static int merge_main(int argc, const char *argv[]) {
   cl::alias RemappingFileA("r", cl::desc("Alias for --remapping-file"),
                            cl::aliasopt(RemappingFile));
   cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
-                                      cl::init("-"), cl::Required,
-                                      cl::desc("Output file"));
+                                      cl::init("-"), cl::desc("Output file"));
   cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
                             cl::aliasopt(OutputFilename));
   cl::opt<ProfileKinds> ProfileKind(


        


More information about the llvm-commits mailing list