Skip to content

Commit

Permalink
[llc] Add -pass-remarks-output
Browse files Browse the repository at this point in the history
This is the opt/llc counterpart of -fsave-optimization-record to output
optimization remarks in a YAML file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293121 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
anemet committed Jan 26, 2017
1 parent e350b28 commit c8168e7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/Analysis/OptimizationDiagnosticInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ void MappingTraits<DiagnosticInfoOptimizationBase *>::mapping(
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() ==
Expand Down
42 changes: 42 additions & 0 deletions test/CodeGen/AArch64/arm64-spill-remarks.ll
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ static cl::opt<bool> PassRemarksWithHotness(
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;

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c8168e7

Please sign in to comment.