anemet updated this revision to Diff 67379. anemet added a comment. Address Aaron's comment
https://reviews.llvm.org/D23284 Files: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CodeGenAction.cpp lib/Frontend/CompilerInvocation.cpp test/Frontend/Inputs/optimization-remark-with-hotness.proftext test/Frontend/optimization-remark-with-hotness.c
Index: test/Frontend/optimization-remark-with-hotness.c =================================================================== --- /dev/null +++ test/Frontend/optimization-remark-with-hotness.c @@ -0,0 +1,41 @@ +// RUN: llvm-profdata merge \ +// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \ +// RUN: -o %t.profdata +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline -Rpass-with-hotness -verify +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline 2>&1 | FileCheck -check-prefix=HOTNESS_OFF %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ +// RUN: -check-prefix=HOTNESS_OFF %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -Rpass=inline -Rpass-analysis=inline -Rpass-with-hotness 2>&1 \ +// RUN: | FileCheck -check-prefix=NO_PGO %s + +int foo(int x, int y) __attribute__((always_inline)); +int foo(int x, int y) { return x + y; } + +int sum = 0; + +void bar(int x) { + // HOTNESS_OFF: foo inlined into bar + // HOTNESS_OFF-NOT: hotness: + // NO_PGO: '-Rpass-with-hotness' requires profile-guided optimization information + // expected-remark@+2 {{foo should always be inlined (cost=always) (hotness: 30)}} + // expected-remark@+1 {{foo inlined into bar (hotness: 30)}} + sum += foo(x, x - 2); +} + +int main(int argc, const char *argv[]) { + for (int i = 0; i < 30; i++) + // expected-remark@+1 {{bar should never be inlined}} + bar(argc); + return sum; +} Index: test/Frontend/Inputs/optimization-remark-with-hotness.proftext =================================================================== --- /dev/null +++ test/Frontend/Inputs/optimization-remark-with-hotness.proftext @@ -0,0 +1,25 @@ +foo +# Func Hash: +0 +# Num Counters: +1 +# Counter Values: +30 + +bar +# Func Hash: +0 +# Num Counters: +1 +# Counter Values: +30 + +main +# Func Hash: +4 +# Num Counters: +2 +# Counter Values: +1 +30 + Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -818,6 +818,13 @@ NeedLocTracking = true; } + Opts.PassRemarksWithHotness = + Args.hasFlag(options::OPT_Rpass_with_hotness, + options::OPT_Rno_pass_with_hotness, /*default*/ false); + if (Opts.PassRemarksWithHotness && + Opts.getProfileUse() == CodeGenOptions::ProfileNone) + Diags.Report(diag::warn_drv_rpass_with_hotness_requires_pgo); + // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile // can be incorporated into the IR. Index: lib/CodeGen/CodeGenAction.cpp =================================================================== --- lib/CodeGen/CodeGenAction.cpp +++ lib/CodeGen/CodeGenAction.cpp @@ -179,6 +179,7 @@ Ctx.getDiagnosticHandler(); void *OldDiagnosticContext = Ctx.getDiagnosticContext(); Ctx.setDiagnosticHandler(DiagnosticHandler, this); + Ctx.setDiagnosticHotnessRequested(CodeGenOpts.PassRemarksWithHotness); // Link LinkModule into this module if present, preserving its validity. for (auto &I : LinkModules) { @@ -511,9 +512,16 @@ FullSourceLoc Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); + std::string Msg; + raw_string_ostream MsgStream(Msg); + MsgStream << D.getMsg().str(); + + if (D.getHotness()) + MsgStream << " (hotness: " << *D.getHotness() << ")"; + Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName() ? D.getPassName() : "") - << D.getMsg().str(); + << MsgStream.str(); if (BadDebugInfo) // If we were not able to translate the file:line:col information Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -237,6 +237,9 @@ /// filename) VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0) +/// Whether to report the hotness of the code region for optimization remarks. +CODEGENOPT(PassRemarksWithHotness, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -303,6 +303,12 @@ "name matches the given POSIX regular expression">; def R_Joined : Joined<["-"], "R">, Group<R_Group>, Flags<[CC1Option, CoreOption]>, MetaVarName<"<remark>">, HelpText<"Enable the specified remark">; +// Don't include in R_Group, since this does not enable any remark group. +def Rpass_with_hotness : Flag<["-"], "Rpass-with-hotness">, Flags<[CC1Option]>, + HelpText<"If profile-guided optimization information is available, " + "include hotness of transformed code region in messages " + "reported by -Rpass* options">; +def Rno_pass_with_hotness : Flag<["-"], "Rno-pass-with-hotness">, Flags<[CC1Option]>; def S : Flag<["-"], "S">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>, HelpText<"Only run preprocess and compilation steps">; def Tbss : JoinedOrSeparate<["-"], "Tbss">, Group<T_Group>; Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -182,6 +182,9 @@ def warn_drv_empty_joined_argument : Warning< "joined argument expects additional value: '%0'">, InGroup<UnusedCommandLineArgument>; +def warn_drv_rpass_with_hotness_requires_pgo : Warning< + "argument '-Rpass-with-hotness' requires profile-guided optimization information">, + InGroup<UnusedCommandLineArgument>; def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; def warn_drv_deprecated_arg : Warning<
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits