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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 19 16:13:08 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: davidxl, wmi, wenlei, xur.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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

Add an error for printing non-text format output to a terminal.
(It cannot be portably tested.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104600

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


Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -316,6 +316,8 @@
     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 @@
                               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 @@
   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(
Index: llvm/test/tools/llvm-profdata/text-dump.test
===================================================================
--- llvm/test/tools/llvm-profdata/text-dump.test
+++ llvm/test/tools/llvm-profdata/text-dump.test
@@ -2,6 +2,7 @@
 
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104600.353216.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210619/4c597a19/attachment.bin>


More information about the llvm-commits mailing list