]> granicus.if.org Git - llvm/commitdiff
Keep Optimization Remark Yaml in NewPM
authorSam Elliott <ashe2@cs.washington.edu>
Sun, 20 Aug 2017 01:30:45 +0000 (01:30 +0000)
committerSam Elliott <ashe2@cs.washington.edu>
Sun, 20 Aug 2017 01:30:45 +0000 (01:30 +0000)
Summary:
The New Pass Manager infrastructure was forgetting to keep around the optimization remark yaml file that the compiler might have been producing. This meant setting the option to '-' for stdout worked, but setting it to a filename didn't give file output (presumably it was deleted because compilation didn't explicitly keep it). This change just ensures that the file is kept if compilation succeeds.

So far I have updated one of the optimization remark output tests to add a version with the new pass manager. It is my intention for this patch to also include changes to all tests that use `-opt-remark-output=` but I wanted to get the code patch ready for review while I was making all those changes.

Fixes https://bugs.llvm.org/show_bug.cgi?id=33951

Reviewers: anemet, chandlerc

Reviewed By: anemet, chandlerc

Subscribers: javed.absar, chandlerc, fhahn, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311271 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/GVN/opt-remarks.ll
test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
test/Transforms/NewGVN/opt-remarks.ll
test/Transforms/PGOProfile/memop_size_opt.ll
test/Transforms/SLPVectorizer/AArch64/getelementptr.ll
test/Transforms/SLPVectorizer/AArch64/horizontal.ll
test/Transforms/SampleProfile/remarks.ll
test/Transforms/Util/libcalls-opt-remarks.ll
tools/opt/NewPMDriver.cpp
tools/opt/NewPMDriver.h
tools/opt/opt.cpp

index e31793038cb0c62bc13d6b063b98d3c9e1ffe6f6..d22998b6f215e0328530cb7832010db58fa67faf 100644 (file)
@@ -1,6 +1,9 @@
 ; RUN: opt < %s -gvn -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=gvn \
 ; RUN:     2>&1 | FileCheck %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
+; RUN: opt < %s -aa-pipeline=basic-aa -passes=gvn -o /dev/null -pass-remarks-output=%t -S -pass-remarks=gvn \
+; RUN:     2>&1 | FileCheck %s
+; RUN: cat %t | FileCheck -check-prefix=YAML %s
 
 ; CHECK:      remark: <unknown>:0:0: load of type i32 eliminated{{$}}
 ; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
index 4dc62d86453f7c65b66b5511aaa92f47253355e3..a6f35e2b0ce238bc48ea78821a488195bf855f9d 100644 (file)
@@ -2,6 +2,10 @@
 ; RUN: opt < %s -loop-vectorize -o /dev/null -pass-remarks-output=%t.yaml
 ; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
 
+; RUN: opt < %s -passes=loop-vectorize -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s
+; RUN: opt < %s -passes=loop-vectorize -o /dev/null -pass-remarks-output=%t.yaml
+; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
+
 ; C/C++ code for tests
 ; void test(int *A, int Length) {
 ; #pragma clang loop vectorize(enable) interleave(enable)
index 528b4545288b39bd354d89647f9b431f2993bb52..4da2ff4af4df880584edd85af98d3758ab63c5c0 100644 (file)
@@ -2,6 +2,10 @@
 ; RUN: opt < %s -newgvn -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=gvn \
 ; RUN:     2>&1 | FileCheck %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
+; RUN: opt < %s -passes=newgvn -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=gvn \
+; RUN:     2>&1 | FileCheck %s
+; RUN: cat %t | FileCheck -check-prefix=YAML %s
+
 
 ; CHECK:      remark: <unknown>:0:0: load of type i32 eliminated{{$}}
 ; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
index 0d2edd40e9c8e0e4b9d7c6244a90e819eb0e8ba8..fc5f41d40fbfebb3ba6d9bb360682c7b38918e2d 100644 (file)
@@ -1,6 +1,10 @@
+; RUN: opt < %s -pgo-memop-opt -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -S | FileCheck %s --check-prefix=MEMOP_OPT
 ; RUN: opt < %s -passes=pgo-memop-opt -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -S | FileCheck %s --check-prefix=MEMOP_OPT
 ; RUN: opt < %s -pgo-memop-opt -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -pass-remarks-with-hotness -pass-remarks-output=%t.opt.yaml -S | FileCheck %s --check-prefix=MEMOP_OPT
 ; RUN: FileCheck %s -input-file=%t.opt.yaml --check-prefix=YAML
+; RUN: opt < %s -passes=pgo-memop-opt -pgo-memop-count-threshold=90 -pgo-memop-percent-threshold=15 -pass-remarks-with-hotness -pass-remarks-output=%t.opt.yaml -S | FileCheck %s --check-prefix=MEMOP_OPT
+; RUN: FileCheck %s -input-file=%t.opt.yaml --check-prefix=YAML
+
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
index 962a6c3b57b3fec3f5204b7d90bf877fd979564d..47bc7c762f763cbecb605b8b79f419af6c28b238 100644 (file)
@@ -1,5 +1,8 @@
 ; RUN: opt -S -slp-vectorizer -slp-threshold=-18 -dce -instcombine -pass-remarks-output=%t < %s | FileCheck %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
+; RUN: opt -S -passes='slp-vectorizer,dce,instcombine' -slp-threshold=-18 -pass-remarks-output=%t < %s | FileCheck %s
+; RUN: cat %t | FileCheck -check-prefix=YAML %s
+
 
 target datalayout = "e-m:e-i32:64-i128:128-n32:64-S128"
 target triple = "aarch64--linux-gnu"
index 1a6a2fb890d30f951fb88c527eb3a92aefc69352..45063e33bd5ccc51f5d904ec581c86bf4a62c5a5 100644 (file)
@@ -1,5 +1,8 @@
 ; RUN: opt -slp-vectorizer -slp-threshold=-6 -S -pass-remarks-output=%t <  %s | FileCheck %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
+; RUN: opt -passes=slp-vectorizer -slp-threshold=-6 -S -pass-remarks-output=%t <  %s | FileCheck %s
+; RUN: cat %t | FileCheck -check-prefix=YAML %s
+
 
 ; FIXME: The threshold is changed to keep this test case a bit smaller.
 ; The AArch64 cost model should not give such high costs to select statements.
index 6285d69f9c78bc8ef3494d33a85b84fb0bcbb5d8..1fc8f38751e619ea0b443fd33188bef58dc6910c 100644 (file)
@@ -1,6 +1,8 @@
 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s
-; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
 ; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
+; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s
+; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
+
 ; Original test case.
 ;
 ;     1    #include <stdlib.h>
index 8c7aaf883f73ab90abe1f2433ed71a4b37b868b7..e8eb7ce9cc2ae780468173d407aa2f5aa9e1a7b8 100644 (file)
@@ -1,8 +1,9 @@
-; RUN: opt < %s -instcombine -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=instcombine \
-; RUN:     2>&1 | FileCheck %s
+; RUN: opt < %s -instcombine -o /dev/null  -pass-remarks-output=%t -S \
+; RUN:     -pass-remarks=instcombine 2>&1 | FileCheck %s
+; RUN: cat %t | FileCheck -check-prefix=YAML %s
+; RUN: opt < %s -passes='require<opt-remark-emit>,instcombine' -o /dev/null \
+; RUN:     -pass-remarks-output=%t -S -pass-remarks=instcombine 2>&1 | FileCheck %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
-; RUN: opt < %s -passes='require<opt-remark-emit>,instcombine' -o /dev/null -S -pass-remarks=instcombine \
-; RUN:     2>&1 | FileCheck %s
 
 ; CHECK:      remark: libcalls-opt-remarks.c:10:10: folded strlen(select) to select of constants{{$}}
 ; CHECK-NOT:  remark:
index f46d37ee8c7af21d94b1477e51395e221a287456..3ce33fd729e75800041b9d1fc5b560974b72c036 100644 (file)
@@ -170,6 +170,7 @@ void RegisterPollyPasses(PassBuilder &);
 bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
                            tool_output_file *Out,
                            tool_output_file *ThinLTOLinkOut,
+                           tool_output_file *OptRemarkFile,
                            StringRef PassPipeline, OutputKind OK,
                            VerifierKind VK,
                            bool ShouldPreserveAssemblyUseListOrder,
@@ -266,5 +267,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
     if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut)
       ThinLTOLinkOut->keep();
   }
+
+  if (OptRemarkFile)
+    OptRemarkFile->keep();
+
   return true;
 }
index 8012e0a025c92b6b5996d44bdb476c8e7c1fd9ed..88184f1aabc22cdb49c5f00f3d2de468d7587a20 100644 (file)
@@ -53,8 +53,8 @@ enum VerifierKind {
 /// nullptr.
 bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
                      tool_output_file *Out, tool_output_file *ThinLinkOut,
-                     StringRef PassPipeline, opt_tool::OutputKind OK,
-                     opt_tool::VerifierKind VK,
+                     tool_output_file *OptRemarkFile, StringRef PassPipeline,
+                     opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
                      bool ShouldPreserveAssemblyUseListOrder,
                      bool ShouldPreserveBitcodeUseListOrder,
                      bool EmitSummaryIndex, bool EmitModuleHash);
index 7bbdb7ebb236b0f60dcad2ca2b4f7b74524fd9f5..4c7d090097a0730d158521246fddda0095a347ed 100644 (file)
@@ -430,17 +430,17 @@ int main(int argc, char **argv) {
   if (PassRemarksHotnessThreshold)
     Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
 
-  std::unique_ptr<tool_output_file> YamlFile;
+  std::unique_ptr<tool_output_file> OptRemarkFile;
   if (RemarksFilename != "") {
     std::error_code EC;
-    YamlFile = llvm::make_unique<tool_output_file>(RemarksFilename, EC,
-                                                   sys::fs::F_None);
+    OptRemarkFile = llvm::make_unique<tool_output_file>(RemarksFilename, EC,
+                                                        sys::fs::F_None);
     if (EC) {
       errs() << EC.message() << '\n';
       return 1;
     }
     Context.setDiagnosticsOutputFile(
-        llvm::make_unique<yaml::Output>(YamlFile->os()));
+        llvm::make_unique<yaml::Output>(OptRemarkFile->os()));
   }
 
   // Load the input module...
@@ -540,7 +540,8 @@ int main(int argc, char **argv) {
     // string. Hand off the rest of the functionality to the new code for that
     // layer.
     return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
-                           PassPipeline, OK, VK, PreserveAssemblyUseListOrder,
+                           OptRemarkFile.get(), PassPipeline, OK, VK,
+                           PreserveAssemblyUseListOrder,
                            PreserveBitcodeUseListOrder, EmitSummaryIndex,
                            EmitModuleHash)
                ? 0
@@ -767,8 +768,8 @@ int main(int argc, char **argv) {
                 "the compile-twice option\n";
       Out->os() << BOS->str();
       Out->keep();
-      if (YamlFile)
-        YamlFile->keep();
+      if (OptRemarkFile)
+        OptRemarkFile->keep();
       return 1;
     }
     Out->os() << BOS->str();
@@ -778,8 +779,8 @@ int main(int argc, char **argv) {
   if (!NoOutput || PrintBreakpoints)
     Out->keep();
 
-  if (YamlFile)
-    YamlFile->keep();
+  if (OptRemarkFile)
+    OptRemarkFile->keep();
 
   if (ThinLinkOut)
     ThinLinkOut->keep();