weiwang updated this revision to Diff 286468. weiwang marked an inline comment as done. weiwang added a comment.
fix typo Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85810/new/ https://reviews.llvm.org/D85810 Files: clang/include/clang/Driver/Driver.h clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/opt-record.c
Index: clang/test/Driver/opt-record.c =================================================================== --- clang/test/Driver/opt-record.c +++ clang/test/Driver/opt-record.c @@ -18,7 +18,17 @@ // RUN: %clang -### -S -o FOO -fsave-optimization-record -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT // RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT // RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE-FORMAT -// + +// Test remarks options pass-through +// No pass-through: lto is disabled +// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fdiagnostics-hotness-threshold=100 -fsave-optimization-record %s 2>&1 | not FileCheck %s -check-prefix=CHECK-PASS + +// Pass-through: +// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto -fdiagnostics-hotness-threshold=100 -fsave-optimization-record -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS +// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=gold -flto -fdiagnostics-hotness-threshold=100 -fsave-optimization-record -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS +// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=100 -fsave-optimization-record=some-format -foptimization-record-file=FOO.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS-CUSTOM +// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=100 -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS-RPASS + // CHECK: "-cc1" // CHECK: "-opt-record-file" "FOO.opt.yaml" @@ -41,3 +51,17 @@ // CHECK-EQ-FORMAT: "-opt-record-format" "some-format" // CHECK-FOPT-DISABLE-FORMAT-NOT: "-fno-save-optimization-record" + +// CHECK-PASS: "--plugin-opt=opt-remarks-filename=FOO.opt.ld.yaml" +// CHECK-PASS: "--plugin-opt=opt-remarks-passes=inline" +// CHECK-PASS: "--plugin-opt=opt-remarks-format=yaml" +// CHECK-PASS: "--plugin-opt=opt-remarks-hotness-threshold=100" + +// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-filename=FOO.txt.opt.ld.some-format" +// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-format=some-format" +// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-hotness-threshold=100" + +// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks=inline" +// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks-missed=inline" +// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks-analysis=inline" +// CHECK-PASS-RPASS: "--plugin-opt=opt-remarks-hotness-threshold=100" Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -60,6 +60,66 @@ using namespace clang; using namespace llvm::opt; +static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs) { + if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ)) + CmdArgs.push_back(Args.MakeArgString(Twine("--plugin-opt=-pass-remarks=") + + A->getValue())); + + if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ)) + CmdArgs.push_back(Args.MakeArgString( + Twine("--plugin-opt=-pass-remarks-missed=") + A->getValue())); + + if (const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ)) + CmdArgs.push_back(Args.MakeArgString( + Twine("--plugin-opt=-pass-remarks-analysis=") + A->getValue())); +} + +static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, + const llvm::Triple &Triple, + const InputInfo &Input, + const InputInfo &Output) { + StringRef Format = "yaml"; + if (const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ)) + Format = A->getValue(); + + SmallString<128> F; + const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ); + if (A) { + F = A->getValue(); + } else { + if (Output.isFilename()) + F = Output.getFilename(); + + // Use the input filename. + if (F.empty()) + F = llvm::sys::path::stem(Input.getBaseInput()); + } + // Append "opt.ld.<format>" to the end of the file name. + CmdArgs.push_back( + Args.MakeArgString(Twine("--plugin-opt=opt-remarks-filename=") + F + + Twine(".opt.ld.") + Format)); + + if (const Arg *A = + Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) + CmdArgs.push_back(Args.MakeArgString( + Twine("--plugin-opt=opt-remarks-passes=") + A->getValue())); + + CmdArgs.push_back(Args.MakeArgString( + Twine("--plugin-opt=opt-remarks-format=") + Format.data())); +} + +static void renderRemarksHotnessOptions(const ArgList &Args, + ArgStringList &CmdArgs) { + if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness, + options::OPT_fno_diagnostics_show_hotness, false)) + CmdArgs.push_back("--plugin-opt=opt-remarks-with-hotness"); + + if (const Arg *A = + Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) + CmdArgs.push_back(Args.MakeArgString( + Twine("--plugin-opt=opt-remarks-hotness-threshold=") + A->getValue())); +} + void tools::addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths) { if (D.getVFS().exists(Path)) @@ -531,6 +591,19 @@ Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile)); addX86AlignBranchArgs(D, Args, CmdArgs, /*IsLTO=*/true); + + // Handle remark diagnostics on screen options: '-Rpass-*'. + if (usesRpassOptions(Args)) + renderRpassOptions(Args, CmdArgs); + + // Handle serialized remarks options: '-fsave-optimization-record' + // and '-foptimization-record-*'. + if (willEmitRemarks(Args)) + renderRemarksOptions(Args, CmdArgs, ToolChain.getEffectiveTriple(), Input, + Output); + + // Handle remarks hotness/threshold related options. + renderRemarksHotnessOptions(Args, CmdArgs); } void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args, Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -5214,3 +5214,19 @@ return true; return false; } + +bool clang::driver::usesRpassOptions(const ArgList &Args) { + // -Rpass=<format> enables it. + if (Args.getLastArg(options::OPT_Rpass_EQ)) + return true; + + // -Rpass-missed=<format> alone enables it too. + if (Args.getLastArg(options::OPT_Rpass_missed_EQ)) + return true; + + // -Rpass-analysis=<format> alone enables it too. + if (Args.getLastArg(options::OPT_Rpass_analysis_EQ)) + return true; + + return false; +} Index: clang/include/clang/Driver/Driver.h =================================================================== --- clang/include/clang/Driver/Driver.h +++ clang/include/clang/Driver/Driver.h @@ -632,6 +632,11 @@ /// \return True if the argument combination will end up generating remarks. bool willEmitRemarks(const llvm::opt::ArgList &Args); +/// \return True if the argument combination will end up outputing remarks +/// onto screen. +/// This checks for clang specific R-value ('-Rpass-*') group. +bool usesRpassOptions(const llvm::opt::ArgList &Args); + } // end namespace driver } // end namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits