[PATCH] D33539: [PM/PGO] Wire up the opt driver's new PM support to be able to run PGO.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 01:08:09 PDT 2017


chandlerc created this revision.
Herald added subscribers: eraman, mcrosier.

This lets us run the only test in the tree that uses the entire
instrumentation PGO pipeline (rather than a direct pass test) on both
the new PM as well as the old one. We could probably use more tests of
the semantically important parts of this pipeline (as evidenced by the
DCE bug I just fixed) but this at least is a start and makes sure the
core of the new PM's pipeline does actually support PGO.


https://reviews.llvm.org/D33539

Files:
  test/Transforms/PGOProfile/preinline.ll
  tools/opt/NewPMDriver.cpp


Index: tools/opt/NewPMDriver.cpp
===================================================================
--- tools/opt/NewPMDriver.cpp
+++ tools/opt/NewPMDriver.cpp
@@ -47,14 +47,46 @@
                         "pipeline for handling managed aliasing queries"),
                cl::Hidden);
 
+static cl::opt<bool>
+    RunProfileGen("new-pm-profile-generate", cl::init(false), cl::Hidden,
+                  cl::desc("Enable generating an instrumentation-based profile "
+                           "with the new pass manager."));
+
+static cl::opt<std::string> ProfileGenFile(
+    "new-pm-profile-generate-file", cl::init(""), cl::Hidden,
+    cl::value_desc("filename"),
+    cl::desc("Enable generating an instrumentation-based profile with the new "
+             "pass manager and write it to the specified file."));
+
+static cl::opt<std::string> ProfileUseFile(
+    "new-pm-profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"),
+    cl::desc("Enable using an instrumentation-based profile with the new "
+             "pass manager and the given file."));
+
 bool llvm::runPassPipeline(StringRef Arg0, Module &M,
                            TargetMachine *TM, tool_output_file *Out,
                            StringRef PassPipeline, OutputKind OK,
                            VerifierKind VK,
                            bool ShouldPreserveAssemblyUseListOrder,
                            bool ShouldPreserveBitcodeUseListOrder,
                            bool EmitSummaryIndex, bool EmitModuleHash) {
-  PassBuilder PB(TM);
+  // Handle any PGO options.
+  Optional<PGOOptions> PGOOpts = None;
+  if (RunProfileGen || !ProfileGenFile.empty()) {
+    if (!ProfileUseFile.empty()) {
+      errs() << Arg0 << ": cannot generate and use a profile in the same invocation.\n";
+      return false;
+    }
+
+    PGOOpts = PGOOptions();
+    PGOOpts->ProfileGenFile = ProfileGenFile;
+    PGOOpts->RunProfileGen = true;
+  } else if (!ProfileUseFile.empty()) {
+    PGOOpts = PGOOptions();
+    PGOOpts->ProfileUseFile = ProfileUseFile;
+  }
+
+  PassBuilder PB(TM, PGOOpts);
 
   // Specially handle the alias analysis manager so that we can register
   // a custom pipeline of AA passes with it.
Index: test/Transforms/PGOProfile/preinline.ll
===================================================================
--- test/Transforms/PGOProfile/preinline.ll
+++ test/Transforms/PGOProfile/preinline.ll
@@ -1,5 +1,9 @@
 ; RUN: opt < %s -O2 -profile-generate -S | FileCheck %s --check-prefix=GEN
 ; RUN: opt < %s -O2 -profile-generate -profile-generate-file=default.profraw -S | FileCheck %s --check-prefix=GEN
+
+; RUN: opt < %s -passes='default<O2>' -new-pm-profile-generate -S | FileCheck %s --check-prefix=GEN
+; RUN: opt < %s -passes='default<O2>' -new-pm-profile-generate-file=default.profraw -S | FileCheck %s --check-prefix=GEN
+
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33539.100212.patch
Type: text/x-patch
Size: 2959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/58038fe8/attachment.bin>


More information about the llvm-commits mailing list