diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -849,6 +849,8 @@ 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 --- /dev/null +++ b/llvm/test/Transforms/GCOVProfiling/noprofile.ll @@ -0,0 +1,71 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=insert-gcov-profiling -o - -S %s | FileCheck %s +define dso_local i32 @no_instr(i32 %a) #0 !dbg !9 { +; CHECK-LABEL: @no_instr( +; CHECK-NEXT: ret i32 42, !dbg [[DBG11:![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 [[DBG13:![0-9]+]] +; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GCOV_CTR]], 1, !dbg [[DBG13]] +; CHECK-NEXT: store i64 [[TMP1]], i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0), align 4, !dbg [[DBG13]] +; CHECK-NEXT: ret i32 42, !dbg [[DBG13]] +; + ret i32 42, !dbg !44 +} + +attributes #0 = { noprofile } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.gcov = !{!7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Nick Desaulniers clang version 13.0.0 (git@github.com:llvm/llvm-project.git b7df99b83a257261369053d4424b4d3229f85106)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "foo.c", directory: "/android0/llvm-project") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 7, !"uwtable", i32 1} +!6 = !{i32 7, !"frame-pointer", i32 2} +!7 = !{!"/android0/llvm-project/-.gcno", !"/android0/llvm-project/-.gcda", !0} +!8 = !{!"Nick Desaulniers clang version 13.0.0 (git@github.com:llvm/llvm-project.git b7df99b83a257261369053d4424b4d3229f85106)"} +!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) +!11 = !DILocation(line: 6, column: 7, scope: !9) +!12 = !DILocation(line: 7, column: 12, scope: !9) +!13 = !DILocation(line: 7, column: 8, scope: !9) +!14 = !DILocation(line: 7, column: 19, scope: !9) +!15 = !DILocation(line: 7, column: 23, scope: !9) +!16 = !DILocation(line: 7, column: 21, scope: !9) +!17 = !DILocation(line: 7, column: 3, scope: !9) +!18 = !DILocation(line: 8, column: 14, scope: !9) +!19 = !DILocation(line: 8, column: 12, scope: !9) +!20 = !DILocation(line: 8, column: 9, scope: !9) +!21 = !DILocation(line: 8, column: 5, scope: !9) +!22 = !DILocation(line: 7, column: 27, scope: !9) +!23 = distinct !{!23, !17, !24, !25} +!24 = !DILocation(line: 8, column: 15, scope: !9) +!25 = !{!"llvm.loop.mustprogress"} +!26 = !DILocation(line: 9, column: 10, scope: !9) +!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) +!29 = !DILocation(line: 13, column: 7, scope: !28) +!30 = !DILocation(line: 14, column: 12, scope: !28) +!31 = !DILocation(line: 14, column: 8, scope: !28) +!32 = !DILocation(line: 14, column: 19, scope: !28) +!33 = !DILocation(line: 14, column: 23, scope: !28) +!34 = !DILocation(line: 14, column: 21, scope: !28) +!35 = !DILocation(line: 14, column: 3, scope: !28) +!36 = !DILocation(line: 15, column: 14, scope: !28) +!37 = !DILocation(line: 15, column: 12, scope: !28) +!38 = !DILocation(line: 15, column: 9, scope: !28) +!39 = !DILocation(line: 15, column: 5, scope: !28) +!40 = !DILocation(line: 14, column: 27, scope: !28) +!41 = distinct !{!41, !35, !42, !25} +!42 = !DILocation(line: 15, column: 15, scope: !28) +!43 = !DILocation(line: 16, column: 10, scope: !28) +!44 = !DILocation(line: 16, column: 3, scope: !28)