[llc] Add -pass-remarks-output

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

llvm-svn: 293121
This commit is contained in:
Adam Nemet 2017-01-26 00:39:51 +00:00
parent 309b3bfa6a
commit 916923e689
3 changed files with 74 additions and 5 deletions

View File

@ -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() ==

View File

@ -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

View File

@ -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;
@ -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;
}