[llvm] r293121 - [llc] Add -pass-remarks-output

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 16:39:52 PST 2017


Author: anemet
Date: Wed Jan 25 18:39:51 2017
New Revision: 293121

URL: http://llvm.org/viewvc/llvm-project?rev=293121&view=rev
Log:
[llc] Add -pass-remarks-output

This is the opt/llc counterpart of -fsave-optimization-record to output
optimization remarks in a YAML file.

Modified:
    llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
    llvm/trunk/test/CodeGen/AArch64/arm64-spill-remarks.ll
    llvm/trunk/tools/llc/llc.cpp

Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=293121&r1=293120&r2=293121&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Wed Jan 25 18:39:51 2017
@@ -71,13 +71,19 @@ void MappingTraits<DiagnosticInfoOptimiz
     IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
   assert(io.outputting() && "input not yet implemented");
 
-  if (io.mapTag("!Passed", OptDiag->getKind() == DK_OptimizationRemark))
+  if (io.mapTag("!Passed",
+                (OptDiag->getKind() == DK_OptimizationRemark ||
+                 OptDiag->getKind() == DK_MachineOptimizationRemark)))
     ;
-  else if (io.mapTag("!Missed",
-                     OptDiag->getKind() == DK_OptimizationRemarkMissed))
+  else if (io.mapTag(
+               "!Missed",
+               (OptDiag->getKind() == DK_OptimizationRemarkMissed ||
+                OptDiag->getKind() == DK_MachineOptimizationRemarkMissed)))
     ;
-  else if (io.mapTag("!Analysis",
-                     OptDiag->getKind() == DK_OptimizationRemarkAnalysis))
+  else if (io.mapTag(
+               "!Analysis",
+               (OptDiag->getKind() == DK_OptimizationRemarkAnalysis ||
+                OptDiag->getKind() == DK_MachineOptimizationRemarkAnalysis)))
     ;
   else if (io.mapTag("!AnalysisFPCommute",
                      OptDiag->getKind() ==

Modified: llvm/trunk/test/CodeGen/AArch64/arm64-spill-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/arm64-spill-remarks.ll?rev=293121&r1=293120&r2=293121&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/arm64-spill-remarks.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/arm64-spill-remarks.ll Wed Jan 25 18:39:51 2017
@@ -1,6 +1,8 @@
 ; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple -pass-remarks-missed=regalloc 2>&1 | FileCheck -check-prefix=REMARK %s
 ; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple -pass-remarks-missed=regalloc -pass-remarks-with-hotness 2>&1 | FileCheck -check-prefix=HOTNESS %s
 ; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple 2>&1 | FileCheck -check-prefix=NO_REMARK %s
+; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple -pass-remarks-output=%t.yaml -pass-remarks-with-hotness 2>&1 | FileCheck -check-prefix=NO_REMARK %s
+; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
 
 ; This has two nested loops, each with one value that has to be spilled and
 ; then reloaded.
@@ -21,6 +23,46 @@
 
 ; NO_REMARK-NOT: remark
 
+; YAML: --- !Missed
+; YAML: Pass:            regalloc
+; YAML: Name:            LoopSpillReload
+; YAML: DebugLoc:        { File: /tmp/kk.c, Line: 3, Column: 20 }
+; YAML: Function:        fpr128
+; YAML: Hotness:         300
+; YAML: Args:
+; YAML:   - NumSpills:       '1'
+; YAML:   - String:          ' spills '
+; YAML:   - NumReloads:      '1'
+; YAML:   - String:          ' reloads '
+; YAML:   - String:          generated in loop
+; YAML: ...
+; YAML: --- !Missed
+; YAML: Pass:            regalloc
+; YAML: Name:            LoopSpillReload
+; YAML: DebugLoc:        { File: /tmp/kk.c, Line: 2, Column: 20 }
+; YAML: Function:        fpr128
+; YAML: Hotness:         30000
+; YAML: Args:
+; YAML:   - NumSpills:       '1'
+; YAML:   - String:          ' spills '
+; YAML:   - NumReloads:      '1'
+; YAML:   - String:          ' reloads '
+; YAML:   - String:          generated in loop
+; YAML: ...
+; YAML: --- !Missed
+; YAML: Pass:            regalloc
+; YAML: Name:            LoopSpillReload
+; YAML: DebugLoc:        { File: /tmp/kk.c, Line: 1, Column: 20 }
+; YAML: Function:        fpr128
+; YAML: Hotness:         300
+; YAML: Args:
+; YAML:   - NumSpills:       '2'
+; YAML:   - String:          ' spills '
+; YAML:   - NumReloads:      '2'
+; YAML:   - String:          ' reloads '
+; YAML:   - String:          generated in loop
+; YAML: ...
+
 define void @fpr128(<4 x float>* %p) nounwind ssp !prof !11 {
 entry:
   br label %loop, !dbg !8

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=293121&r1=293120&r2=293121&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Wed Jan 25 18:39:51 2017
@@ -141,6 +141,11 @@ static cl::opt<bool> PassRemarksWithHotn
     cl::desc("With PGO, include profile count in optimization remarks"),
     cl::Hidden);
 
+static cl::opt<std::string>
+    RemarksFilename("pass-remarks-output",
+                    cl::desc("YAML output filename for pass remarks"),
+                    cl::value_desc("filename"));
+
 namespace {
 static ManagedStatic<std::vector<std::string>> RunPassNames;
 
@@ -292,11 +297,27 @@ int main(int argc, char **argv) {
   if (PassRemarksWithHotness)
     Context.setDiagnosticHotnessRequested(true);
 
+  std::unique_ptr<tool_output_file> YamlFile;
+  if (RemarksFilename != "") {
+    std::error_code EC;
+    YamlFile = 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()));
+  }
+
   // Compile the module TimeCompilations times to give better compile time
   // metrics.
   for (unsigned I = TimeCompilations; I; --I)
     if (int RetVal = compileModule(argv, Context))
       return RetVal;
+
+  if (YamlFile)
+    YamlFile->keep();
   return 0;
 }
 




More information about the llvm-commits mailing list