[llvm] r204211 - llvm-profdata: Make "merge" into a subcommand.

Justin Bogner mail at justinbogner.com
Tue Mar 18 19:20:46 PDT 2014


Author: bogner
Date: Tue Mar 18 21:20:46 2014
New Revision: 204211

URL: http://llvm.org/viewvc/llvm-project?rev=204211&view=rev
Log:
llvm-profdata: Make "merge" into a subcommand.

We'll be adding a few more subcommands in the near future.

Modified:
    llvm/trunk/test/tools/llvm-profdata/errors.test
    llvm/trunk/test/tools/llvm-profdata/simple.test
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp

Modified: llvm/trunk/test/tools/llvm-profdata/errors.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/errors.test?rev=204211&r1=204210&r2=204211&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/errors.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/errors.test Tue Mar 18 21:20:46 2014
@@ -1,19 +1,19 @@
-RUN: not llvm-profdata %p/Inputs/empty.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
-RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
-RUN: not llvm-profdata %p/Inputs/foo4-1.profdata %p/Inputs/empty.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
+RUN: not llvm-profdata merge %p/Inputs/empty.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
+RUN: not llvm-profdata merge %p/Inputs/foo3-1.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
+RUN: not llvm-profdata merge %p/Inputs/foo4-1.profdata %p/Inputs/empty.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH
 LENGTH: error: {{.*}}: truncated file
 
-RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=NAME
+RUN: not llvm-profdata merge %p/Inputs/foo3-1.profdata %p/Inputs/bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=NAME
 NAME: error: {{.*}}: function name mismatch
 
-RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=HASH
+RUN: not llvm-profdata merge %p/Inputs/foo3-1.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=HASH
 HASH: error: {{.*}}: function hash mismatch
 
-RUN: not llvm-profdata %p/Inputs/overflow.profdata %p/Inputs/overflow.profdata 2>&1 | FileCheck %s --check-prefix=OVERFLOW
+RUN: not llvm-profdata merge %p/Inputs/overflow.profdata %p/Inputs/overflow.profdata 2>&1 | FileCheck %s --check-prefix=OVERFLOW
 OVERFLOW: error: {{.*}}: counter overflow
 
-RUN: not llvm-profdata %p/Inputs/invalid-count-later.profdata %p/Inputs/invalid-count-later.profdata 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
+RUN: not llvm-profdata merge %p/Inputs/invalid-count-later.profdata %p/Inputs/invalid-count-later.profdata 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
 INVALID-COUNT-LATER: error: {{.*}}: invalid counter
 
-RUN: not llvm-profdata %p/Inputs/bad-hash.profdata %p/Inputs/bad-hash.profdata 2>&1 | FileCheck %s --check-prefix=BAD-HASH
+RUN: not llvm-profdata merge %p/Inputs/bad-hash.profdata %p/Inputs/bad-hash.profdata 2>&1 | FileCheck %s --check-prefix=BAD-HASH
 BAD-HASH: error: {{.*}}: bad function hash

Modified: llvm/trunk/test/tools/llvm-profdata/simple.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/simple.test?rev=204211&r1=204210&r2=204211&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/simple.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/simple.test Tue Mar 18 21:20:46 2014
@@ -1,5 +1,5 @@
-RUN: llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3
-RUN: llvm-profdata %p/Inputs/foo3-2.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3
+RUN: llvm-profdata merge %p/Inputs/foo3-1.profdata %p/Inputs/foo3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3
+RUN: llvm-profdata merge %p/Inputs/foo3-2.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3
 FOO3:      {{^foo$}}
 FOO3-NEXT: {{^3$}}
 FOO3-NEXT: {{^3$}}
@@ -7,8 +7,8 @@ FOO3-NEXT: {{^8$}}
 FOO3-NEXT: {{^7$}}
 FOO3-NEXT: {{^6$}}
 
-RUN: llvm-profdata %p/Inputs/foo4-1.profdata %p/Inputs/foo4-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO4
-RUN: llvm-profdata %p/Inputs/foo4-2.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO4
+RUN: llvm-profdata merge %p/Inputs/foo4-1.profdata %p/Inputs/foo4-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO4
+RUN: llvm-profdata merge %p/Inputs/foo4-2.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO4
 FOO4:      {{^foo$}}
 FOO4-NEXT: {{^4$}}
 FOO4-NEXT: {{^4$}}
@@ -17,8 +17,8 @@ FOO4-NEXT: {{^28$}}
 FOO4-NEXT: {{^38$}}
 FOO4-NEXT: {{^48$}}
 
-RUN: llvm-profdata %p/Inputs/foo3bar3-1.profdata %p/Inputs/foo3bar3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3
-RUN: llvm-profdata %p/Inputs/foo3bar3-2.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3
+RUN: llvm-profdata merge %p/Inputs/foo3bar3-1.profdata %p/Inputs/foo3bar3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3
+RUN: llvm-profdata merge %p/Inputs/foo3bar3-2.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3
 FOO3BAR3:      {{^foo$}}
 FOO3BAR3-NEXT: {{^3$}}
 FOO3BAR3-NEXT: {{^3$}}

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=204211&r1=204210&r2=204211&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Tue Mar 18 21:20:46 2014
@@ -22,17 +22,6 @@
 
 using namespace llvm;
 
-static cl::opt<std::string> Filename1(cl::Positional, cl::Required,
-                                      cl::desc("file1"));
-static cl::opt<std::string> Filename2(cl::Positional, cl::Required,
-                                      cl::desc("file2"));
-
-static cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
-                                           cl::init("-"),
-                                           cl::desc("Output file"));
-static cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
-                                 cl::aliasopt(OutputFilename));
-
 static void exitWithError(const std::string &Message,
                           const std::string &Filename, int64_t Line = -1) {
   errs() << "error: " << Filename;
@@ -43,11 +32,17 @@ static void exitWithError(const std::str
 }
 
 //===----------------------------------------------------------------------===//
-int main(int argc, char **argv) {
-  // Print a stack trace if we signal out.
-  sys::PrintStackTraceOnErrorSignal();
-  PrettyStackTraceProgram X(argc, argv);
-  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+int merge_main(int argc, const char *argv[]) {
+  cl::opt<std::string> Filename1(cl::Positional, cl::Required,
+                                 cl::desc("file1"));
+  cl::opt<std::string> Filename2(cl::Positional, cl::Required,
+                                 cl::desc("file2"));
+
+  cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
+                                      cl::init("-"),
+                                      cl::desc("Output file"));
+  cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
+                                 cl::aliasopt(OutputFilename));
 
   cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
 
@@ -127,3 +122,43 @@ int main(int argc, char **argv) {
 
   return 0;
 }
+
+int main(int argc, const char *argv[]) {
+  // Print a stack trace if we signal out.
+  sys::PrintStackTraceOnErrorSignal();
+  PrettyStackTraceProgram X(argc, argv);
+  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
+  StringRef ProgName(sys::path::filename(argv[0]));
+  if (argc > 1) {
+    int (*func)(int, const char *[]) = 0;
+
+    if (strcmp(argv[1], "merge") == 0)
+      func = merge_main;
+
+    if (func) {
+      std::string Invocation(ProgName.str() + " " + argv[1]);
+      argv[1] = Invocation.c_str();
+      return func(argc - 1, argv + 1);
+    }
+
+    if (strcmp(argv[1], "-h") == 0 ||
+        strcmp(argv[1], "-help") == 0 ||
+        strcmp(argv[1], "--help") == 0) {
+
+      errs() << "OVERVIEW: LLVM profile data tools\n\n"
+             << "USAGE: " << ProgName << " <command> [args...]\n"
+             << "USAGE: " << ProgName << " <command> -help\n\n"
+             << "Available commands: merge\n";
+      return 0;
+    }
+  }
+
+  if (argc < 2)
+    errs() << ProgName << ": No command specified!\n";
+  else
+    errs() << ProgName << ": Unknown command!\n";
+
+  errs() << "USAGE: " << ProgName << " <merge|show|generate> [args...]\n";
+  return 1;
+}





More information about the llvm-commits mailing list