paulkirth updated this revision to Diff 492269. paulkirth added a comment. Rebase
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131137/new/ https://reviews.llvm.org/D131137 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CodeGenAction.cpp clang/test/Profile/Inputs/missing-annotation.proftext clang/test/Profile/missing-annotation.c
Index: clang/test/Profile/missing-annotation.c =================================================================== --- /dev/null +++ clang/test/Profile/missing-annotation.c @@ -0,0 +1,37 @@ +// Test that missing annotation diagnostics are suggested for hot branches + +// test diagnostics are issued when profiling data mis-matches annotations +// RUN: llvm-profdata merge %S/Inputs/missing-annotation.proftext -o %t.profdata +// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=exact -fdiagnostics-missing-annotations -debug-info-kind=line-tables-only -Rpass=missing-annotations + + +// foo-no-diagnostics + +int foo(int); +int baz(int); +int buzz(); + +const int inner_loop = 100; +const int outer_loop = 2000; +int bar() { + int rando = buzz(); + int x = 0; + if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} + x = baz(rando); + } else { + x = foo(50); + } + return x; +} + +int fizz() { + int rando = buzz(); + int x = 0; + if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} + x = baz(rando); + } else { + x = foo(50); + } + return x; +} + Index: clang/test/Profile/Inputs/missing-annotation.proftext =================================================================== --- /dev/null +++ clang/test/Profile/Inputs/missing-annotation.proftext @@ -0,0 +1,18 @@ +bar +# Func Hash: +11262309464 +# Num Counters: +2 +# Counter Values: +200000 +1 + +fizz +# Func Hash: +11262309464 +# Num Counters: +2 +# Counter Values: +200000 +1 + Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -347,6 +347,10 @@ Ctx.setMisExpectWarningRequested(true); } + if (CodeGenOpts.MissingAnnotations) { + Ctx.setAnnotationDiagsRequested(true); + } + if (CodeGenOpts.DiagnosticsMisExpectTolerance) { Ctx.setDiagnosticsMisExpectTolerance( CodeGenOpts.DiagnosticsMisExpectTolerance); Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -492,6 +492,7 @@ Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs; Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile; Options.MisExpect = CodeGenOpts.MisExpect; + Options.MissingAnnotations = CodeGenOpts.MissingAnnotations; return true; } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1509,6 +1509,10 @@ def fdiagnostics_misexpect_tolerance_EQ : Joined<["-"], "fdiagnostics-misexpect-tolerance=">, Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<value>">, HelpText<"Prevent misexpect diagnostics from being output if the profile counts are within N% of the expected. ">; +defm diagnostics_missing_annotations : BoolFOption<"diagnostics-missing-annotations", + CodeGenOpts<"MissingAnnotations">, DefaultFalse, + PosFlag<SetTrue, [CC1Option], "Enable profile hotness information in diagnostic line">, + NegFlag<SetFalse>>; defm diagnostics_show_option : BoolFOption<"diagnostics-show-option", DiagnosticOpts<"ShowOptionNames">, DefaultTrue, NegFlag<SetFalse, [CC1Option]>, PosFlag<SetTrue, [], "Print option name with mappable diagnostics">>; Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -180,6 +180,7 @@ CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled. CODEGENOPT(NoTypeCheck , 1, 0) ///< Set when -Wa,--no-type-check is enabled. CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled +CODEGENOPT(MissingAnnotations, 1, 0) ///< Set when suggesting missing perf annotations CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain ///< inline line tables.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits