Author: thegameg Date: Tue Mar 12 13:28:50 2019 New Revision: 355964 URL: http://llvm.org/viewvc/llvm-project?rev=355964&view=rev Log: [Remarks] Add -foptimization-record-passes to filter remark emission
Currently we have -Rpass for filtering the remarks that are displayed as diagnostics, but when using -fsave-optimization-record, there is no way to filter the remarks while generating them. This adds support for filtering remarks by passes using a regex. Ex: `clang -fsave-optimization-record -foptimization-record-passes=inline` will only emit the remarks coming from the pass `inline`. This adds: * `-fsave-optimization-record` to the driver * `-opt-record-passes` to cc1 * `-lto-pass-remarks-filter` to the LTOCodeGenerator * `--opt-remarks-passes` to lld * `-pass-remarks-filter` to llc, opt, llvm-lto, llvm-lto2 * `-opt-remarks-passes` to gold-plugin Differential Revision: https://reviews.llvm.org/D59268 Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Driver/Options.td cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/CodeGen/CodeGenAction.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Driver/ToolChains/Darwin.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/CodeGen/opt-record-MIR.c cfe/trunk/test/CodeGen/opt-record.c cfe/trunk/test/Driver/darwin-ld.c cfe/trunk/test/Driver/opt-record.c Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original) +++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Tue Mar 12 13:28:50 2019 @@ -238,6 +238,10 @@ public: /// records. std::string OptRecordFile; + /// The regex that filters the passes that should be saved to the optimization + /// records. + std::string OptRecordPasses; + /// Regular expression to select optimizations for which we should enable /// optimization remarks. Transformation passes whose name matches this /// expression (and support this feature), will emit a diagnostic Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Mar 12 13:28:50 2019 @@ -603,6 +603,8 @@ def arcmt_migrate : Flag<["-"], "arcmt-m def opt_record_file : Separate<["-"], "opt-record-file">, HelpText<"File name to use for YAML optimization record output">; +def opt_record_passes : Separate<["-"], "opt-record-passes">, + HelpText<"Only record remark information for passes whose names match the given regular expression">; def print_stats : Flag<["-"], "print-stats">, HelpText<"Print performance metrics and statistics">; Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Tue Mar 12 13:28:50 2019 @@ -1715,6 +1715,10 @@ def fno_save_optimization_record : Flag< def foptimization_record_file_EQ : Joined<["-"], "foptimization-record-file=">, Group<f_Group>, HelpText<"Specify the file name of any generated YAML optimization record">; +def foptimization_record_passes_EQ : Joined<["-"], "foptimization-record-passes=">, + Group<f_Group>, + HelpText<"Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)">; + def ftest_coverage : Flag<["-"], "ftest-coverage">, Group<f_Group>; def fvectorize : Flag<["-"], "fvectorize">, Group<f_Group>, Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Mar 12 13:28:50 2019 @@ -1340,6 +1340,7 @@ static void runThinLTOBackend(ModuleSumm Conf.DebugPassManager = CGOpts.DebugPassManager; Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness; Conf.RemarksFilename = CGOpts.OptRecordFile; + Conf.RemarksPasses = CGOpts.OptRecordPasses; Conf.DwoPath = CGOpts.SplitDwarfFile; switch (Action) { case Backend_EmitNothing: Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Mar 12 13:28:50 2019 @@ -19,6 +19,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/Preprocessor.h" @@ -280,6 +281,12 @@ namespace clang { Ctx.setRemarkStreamer(llvm::make_unique<RemarkStreamer>( CodeGenOpts.OptRecordFile, OptRecordFile->os())); + if (!CodeGenOpts.OptRecordPasses.empty()) + if (Error E = Ctx.getRemarkStreamer()->setFilter( + CodeGenOpts.OptRecordPasses)) + Diags.Report(diag::err_drv_optimization_remark_pattern) + << toString(std::move(E)) << CodeGenOpts.OptRecordPasses; + if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone) Ctx.setDiagnosticsHotnessRequested(true); } Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Mar 12 13:28:50 2019 @@ -5032,8 +5032,11 @@ void Clang::ConstructJob(Compilation &C, options::OPT_fno_apple_pragma_pack, false)) CmdArgs.push_back("-fapple-pragma-pack"); + // Remarks can be enabled with any of the `-f.*optimization-record.*` flags. if (Args.hasFlag(options::OPT_fsave_optimization_record, options::OPT_foptimization_record_file_EQ, + options::OPT_fno_save_optimization_record, false) || + Args.hasFlag(options::OPT_foptimization_record_passes_EQ, options::OPT_fno_save_optimization_record, false)) { CmdArgs.push_back("-opt-record-file"); @@ -5068,6 +5071,11 @@ void Clang::ConstructJob(Compilation &C, llvm::sys::path::replace_extension(F, "opt.yaml"); CmdArgs.push_back(Args.MakeArgString(F)); } + if (const Arg *A = + Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) { + CmdArgs.push_back("-opt-record-passes"); + CmdArgs.push_back(A->getValue()); + } } bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports, Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Tue Mar 12 13:28:50 2019 @@ -483,6 +483,14 @@ void darwin::Linker::ConstructJob(Compil CmdArgs.push_back(Args.MakeArgString(Opt)); } } + + if (const Arg *A = + Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) { + CmdArgs.push_back("-mllvm"); + std::string Passes = + std::string("-lto-pass-remarks-filter=") + A->getValue(); + CmdArgs.push_back(Args.MakeArgString(Passes)); + } } // Propagate the -moutline flag to the linker in LTO. Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Mar 12 13:28:50 2019 @@ -1218,6 +1218,11 @@ static bool ParseCodeGenArgs(CodeGenOpti if (!Opts.OptRecordFile.empty()) NeedLocTracking = true; + if (Arg *A = Args.getLastArg(OPT_opt_record_passes)) { + Opts.OptRecordPasses = A->getValue(); + NeedLocTracking = true; + } + if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) { Opts.OptimizationRemarkPattern = GenerateOptimizationRemarkRegex(Diags, Args, A); Modified: cfe/trunk/test/CodeGen/opt-record-MIR.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/opt-record-MIR.c?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/opt-record-MIR.c (original) +++ cfe/trunk/test/CodeGen/opt-record-MIR.c Tue Mar 12 13:28:50 2019 @@ -3,6 +3,8 @@ // RUN: %clang_cc1 -triple arm64-apple-ios -S -o /dev/null %s -O2 -dwarf-column-info 2>&1 | FileCheck -allow-empty -check-prefix=NO_REMARK %s // RUN: %clang_cc1 -triple arm64-apple-ios -S -o /dev/null %s -O2 -dwarf-column-info -opt-record-file %t.yaml // RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s +// RUN: %clang_cc1 -triple arm64-apple-ios -S -o /dev/null %s -O2 -dwarf-column-info -opt-record-file %t.yaml -opt-record-passes asm-printer +// RUN: cat %t.yaml | FileCheck -check-prefix=PASSES %s void bar(float); @@ -15,15 +17,15 @@ void foo(float *p, int i) { } } -// REMARK: opt-record-MIR.c:10:11: remark: {{.}} spills {{.}} reloads generated in loop +// REMARK: opt-record-MIR.c:{{[1-9][0-9]*}}:{{[1-9][0-9]*}}: remark: {{.}} spills {{.}} reloads generated in loop // NO_REMARK-NOT: remark: // YAML: --- !Missed // YAML: Pass: regalloc // YAML: Name: LoopSpillReload // YAML: DebugLoc: { File: {{[^,]+}}, -// YAML: Line: 10, -// YAML: Column: 11 } +// YAML: Line: {{[1-9][0-9]*}} +// YAML: Column: {{[1-9][0-9]*}} } // YAML: Function: foo // YAML: Args: // YAML: - NumSpills: '{{.}}' @@ -32,3 +34,6 @@ void foo(float *p, int i) { // YAML: - String: ' reloads ' // YAML: - String: generated // YAML: ... + +// PASSES: Pass: asm-printer +// PASSES-NOT: regalloc Modified: cfe/trunk/test/CodeGen/opt-record.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/opt-record.c?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/opt-record.c (original) +++ cfe/trunk/test/CodeGen/opt-record.c Tue Mar 12 13:28:50 2019 @@ -3,6 +3,8 @@ // RUN: llvm-profdata merge %S/Inputs/opt-record.proftext -o %t.profdata // RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -fprofile-instrument-use-path=%t.profdata %s -o %t -dwarf-column-info -opt-record-file %t.yaml -emit-obj // RUN: cat %t.yaml | FileCheck -check-prefix=CHECK -check-prefix=CHECK-PGO %s +// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 %s -o %t -dwarf-column-info -opt-record-file %t.yaml -opt-record-passes inline -emit-obj +// RUN: cat %t.yaml | FileCheck -check-prefix=CHECK-PASSES %s // REQUIRES: x86-registered-target void bar(); @@ -23,6 +25,7 @@ void Test(int *res, int *c, int *d, int // CHECK: DebugLoc: // CHECK: Function: foo // CHECK-PGO: Hotness: +// CHECK-PASSES: Pass: inline // CHECK: --- !Passed // CHECK: Pass: loop-vectorize @@ -30,4 +33,4 @@ void Test(int *res, int *c, int *d, int // CHECK: DebugLoc: // CHECK: Function: Test // CHECK-PGO: Hotness: - +// CHECK-PASSES-NOT: loop-vectorize Modified: cfe/trunk/test/Driver/darwin-ld.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/test/Driver/darwin-ld.c (original) +++ cfe/trunk/test/Driver/darwin-ld.c Tue Mar 12 13:28:50 2019 @@ -327,6 +327,10 @@ // RUN: FileCheck -check-prefix=PASS_REMARKS_WITH_HOTNESS_THRESHOLD %s < %t.log // PASS_REMARKS_WITH_HOTNESS_THRESHOLD: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "foo/bar.out.opt.yaml" "-mllvm" "-lto-pass-remarks-with-hotness" "-mllvm" "-lto-pass-remarks-hotness-threshold=100" +// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -foptimization-record-passes=inline -### -o foo/bar.out 2> %t.log +// RUN: FileCheck -check-prefix=PASS_REMARKS_WITH_PASSES %s < %t.log +// PASS_REMARKS_WITH_PASSES: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "foo/bar.out.opt.yaml" "-mllvm" "-lto-pass-remarks-filter=inline" + // RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 -fprofile-instr-generate -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log Modified: cfe/trunk/test/Driver/opt-record.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opt-record.c?rev=355964&r1=355963&r2=355964&view=diff ============================================================================== --- cfe/trunk/test/Driver/opt-record.c (original) +++ cfe/trunk/test/Driver/opt-record.c Tue Mar 12 13:28:50 2019 @@ -12,6 +12,10 @@ // RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ // RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE +// RUN: %clang -### -S -o FOO -fsave-optimization-record -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-PASSES +// RUN: %clang -### -S -o FOO -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-PASSES +// RUN: %clang -### -S -o FOO -foptimization-record-passes=inline -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE-PASSES +// // CHECK: "-cc1" // CHECK: "-opt-record-file" "FOO.opt.yaml" @@ -23,3 +27,8 @@ // CHECK-EQ: "-opt-record-file" "BAR.txt" // CHECK-FOPT-DISABLE-NOT: "-fno-save-optimization-record" + +// CHECK-EQ-PASSES: "-cc1" +// CHECK-EQ-PASSES: "-opt-record-passes" "inline" + +// CHECK-FOPT-DISABLE-PASSES-NOT: "-fno-save-optimization-record" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits