From bef299286104c2b6383a43b9d1eb0e47838cb5b6 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Fri, 18 Jun 2021 13:58:34 -0700 Subject: [PATCH] [GCOVProfiling] don't profile Fn's w/ noprofile attribute Similar to D104475, the Linux kernel would like to avoid compiler generated code in certain functions. The no_profile function attribute can be used in C to generate the the noprofile fn attr in IR. Respect that from GCOVProfiling. Link: https://lore.kernel.org/lkml/CAKwvOdmPTi93n2L0_yQkrzLdmpxzrOR7zggSzonyaw2PGshApw@mail.gmail.com/ Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D104257 --- .../Transforms/Instrumentation/GCOVProfiling.cpp | 2 ++ llvm/test/Transforms/GCOVProfiling/noprofile.ll | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 llvm/test/Transforms/GCOVProfiling/noprofile.ll diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index aae04cb..c99f2e6 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -849,6 +849,8 @@ bool GCOVProfiler::emitProfileNotes( continue; // TODO: Functions using scope-based EH are currently not supported. if (isUsingScopeBasedEH(F)) continue; + if (F.hasFnAttribute(llvm::Attribute::NoProfile)) + continue; // Add the function line number to the lines of the entry block // to have a counter for the function definition. diff --git a/llvm/test/Transforms/GCOVProfiling/noprofile.ll b/llvm/test/Transforms/GCOVProfiling/noprofile.ll new file mode 100644 index 0000000..6a84fb7 --- /dev/null +++ b/llvm/test/Transforms/GCOVProfiling/noprofile.ll @@ -0,0 +1,33 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=insert-gcov-profiling -S %s | FileCheck %s + +; Test that the noprofile attribute disables profiling. +define dso_local i32 @no_instr(i32 %a) noprofile !dbg !9 { +; CHECK-LABEL: @no_instr( +; CHECK-NEXT: ret i32 42, !dbg [[DBG6:![0-9]+]] +; + ret i32 42, !dbg !27 +} + +define dso_local i32 @instr(i32 %a) !dbg !28 { +; CHECK-LABEL: @instr( +; CHECK-NEXT: [[GCOV_CTR:%.*]] = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0), align 4, !dbg [[DBG8:![0-9]+]] +; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GCOV_CTR]], 1, !dbg [[DBG8]] +; CHECK-NEXT: store i64 [[TMP1]], i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0), align 4, !dbg [[DBG8]] +; CHECK-NEXT: ret i32 42, !dbg [[DBG8]] +; + ret i32 42, !dbg !44 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "a.c", directory: "") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!9 = distinct !DISubprogram(name: "no_instr", scope: !1, file: !1, line: 5, type: !10, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!10 = !DISubroutineType(types: !2) +!27 = !DILocation(line: 9, column: 3, scope: !9) +!28 = distinct !DISubprogram(name: "instr", scope: !1, file: !1, line: 12, type: !10, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!44 = !DILocation(line: 16, column: 3, scope: !28) -- 2.7.4