[PATCH] D35807: Add test coverage for new PM PGOOpt handling.

Dehao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 10:32:46 PDT 2017


danielcdh created this revision.
Herald added a subscriber: sanjoy.

This patch adds flags and tests to cover the PGOOpt handling logic in new PM.


https://reviews.llvm.org/D35807

Files:
  lib/Passes/PassBuilder.cpp
  test/Other/Inputs/new-pm-pgo.prof
  test/Other/Inputs/new-pm-pgo.proftext
  test/Other/new-pm-pgo.ll


Index: test/Other/new-pm-pgo.ll
===================================================================
--- /dev/null
+++ test/Other/new-pm-pgo.ll
@@ -0,0 +1,12 @@
+; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-opt='gen=temp' %s 2>&1 |FileCheck %s --check-prefixes=GEN
+; RUN: llvm-profdata merge %S/Inputs/new-pm-pgo.proftext -o %t.profdata
+; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-opt='use=%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE
+; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-opt='sample-use=%S/Inputs/new-pm-pgo.prof' %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_USE
+;
+; GEN: Running pass: PGOInstrumentationGen
+; USE: Running pass: PGOInstrumentationUse
+; SAMPLE_USE: Running pass: SampleProfileLoaderPass
+
+define void @foo() {
+  ret void
+}
Index: test/Other/Inputs/new-pm-pgo.proftext
===================================================================
--- /dev/null
+++ test/Other/Inputs/new-pm-pgo.proftext
@@ -0,0 +1 @@
+:ir
Index: test/Other/Inputs/new-pm-pgo.prof
===================================================================
--- /dev/null
+++ test/Other/Inputs/new-pm-pgo.prof
@@ -0,0 +1 @@
+foo:0:0
Index: lib/Passes/PassBuilder.cpp
===================================================================
--- lib/Passes/PassBuilder.cpp
+++ lib/Passes/PassBuilder.cpp
@@ -172,6 +172,11 @@
     "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
     cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
 
+static cl::opt<std::string> PGOOptString(
+    "pgo-opt", cl::init(""), cl::Hidden,
+    cl::desc("PGOOpt string in the format of "
+             "{gen|use|sample_gen|sample_use}=value"));
+
 static Regex DefaultAliasRegex(
     "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
 
@@ -1101,6 +1106,34 @@
   return false;
 }
 
+/// Use user specifiy -pgo-opt option to override PGOOpt
+static void processPGOOpt(Optional<PGOOptions> &PGOOpt) {
+  if (PGOOptString.empty())
+    return;
+  auto pos = PGOOptString.find('=');
+  if (pos == std::string::npos) {
+    report_fatal_error("Invalid -pgo-opt.");
+    return;
+  }
+  PGOOptions pgoopt;
+  std::string command = PGOOptString.substr(0, pos);
+  if (command == "gen") {
+    pgoopt.ProfileGenFile = PGOOptString.substr(pos + 1);
+    pgoopt.RunProfileGen = true;
+  } else if (command == "use") {
+    pgoopt.ProfileUseFile = PGOOptString.substr(pos + 1);
+  } else if (command == "sample-gen") {
+    // FIXME: add -fdebug-info-for-profiling logic
+    ;
+  } else if (command == "sample-use") {
+    pgoopt.SampleProfileFile = PGOOptString.substr(pos + 1);
+  } else {
+    report_fatal_error("Invalid -pgo-opt.");
+    return;
+  }
+  PGOOpt = pgoopt;
+}
+
 template <typename CallbacksT>
 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
   // Manually handle aliases for pre-configured pipeline fragments.
@@ -1668,6 +1701,8 @@
   if (!Pipeline || Pipeline->empty())
     return false;
 
+  processPGOOpt(PGOOpt);
+
   // If the first name isn't at the module layer, wrap the pipeline up
   // automatically.
   StringRef FirstName = Pipeline->front().Name;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35807.107927.patch
Type: text/x-patch
Size: 3165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170724/a5e1ebf8/attachment.bin>


More information about the llvm-commits mailing list