[llvm] ccbbb4f - [Sample-PGO] Emit FS discriminators only when -fdebug-info-for-profiling is set

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 25 09:41:31 PST 2022


Author: Rong Xu
Date: 2022-02-25T09:41:17-08:00
New Revision: ccbbb4f6c716ba14d98cceff08a81777228ab4d1

URL: https://github.com/llvm/llvm-project/commit/ccbbb4f6c716ba14d98cceff08a81777228ab4d1
DIFF: https://github.com/llvm/llvm-project/commit/ccbbb4f6c716ba14d98cceff08a81777228ab4d1.diff

LOG: [Sample-PGO] Emit FS discriminators only when -fdebug-info-for-profiling is set

IR level addDiscriminator pass is guarded by DebugInfoForProfiling
(set by option -fdebug-info-for-profiling).
This patch syncs the logic for the MIR and IR level implementations.

Differential Revision: https://reviews.llvm.org/D120536

Added: 
    llvm/test/CodeGen/X86/fsafdo_test4.ll

Modified: 
    llvm/lib/CodeGen/MIRFSDiscriminator.cpp
    llvm/test/CodeGen/X86/fsafdo_test1.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp
index bf78594e9b231..c978f82ba9f3c 100644
--- a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp
+++ b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp
@@ -68,6 +68,8 @@ static uint64_t getCallStackHash(const MachineBasicBlock &BB,
 bool MIRAddFSDiscriminators::runOnMachineFunction(MachineFunction &MF) {
   if (!EnableFSDiscriminator)
     return false;
+  if (!MF.getFunction().isDebugInfoForProfiling())
+    return false;
 
   bool Changed = false;
   using LocationDiscriminator = std::tuple<StringRef, unsigned, unsigned>;

diff  --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll b/llvm/test/CodeGen/X86/fsafdo_test1.ll
index ca7120461481b..d2bb99ad98ef0 100644
--- a/llvm/test/CodeGen/X86/fsafdo_test1.ll
+++ b/llvm/test/CodeGen/X86/fsafdo_test1.ll
@@ -2,7 +2,7 @@
 ;
 ; Check that fs-afdo discriminators are generated.
 ; CHECK: .loc    1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3
-; Check: .loc    1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
+; ChECK: .loc    1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
 ; CHECK: .loc    1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5
 ; CHECK: .loc    1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
 ; Check that variable __llvm_fs_discriminator__ is generated.
@@ -45,7 +45,7 @@ while.end4:
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!3, !4}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, emissionKind: LineTablesOnly)
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, debugInfoForProfiling: true, emissionKind: LineTablesOnly)
 !1 = !DIFile(filename: "foo.c", directory: "b/")
 !2 = !{}
 !3 = !{i32 2, !"Dwarf Version", i32 4}

diff  --git a/llvm/test/CodeGen/X86/fsafdo_test4.ll b/llvm/test/CodeGen/X86/fsafdo_test4.ll
new file mode 100644
index 0000000000000..541fe29e5dae0
--- /dev/null
+++ b/llvm/test/CodeGen/X86/fsafdo_test4.ll
@@ -0,0 +1,55 @@
+; RUN: llc -enable-fs-discriminator < %s | FileCheck %s
+;
+; Check that fs-afdo discriminators are NOT generated, as debugInfoForProfiling is false (not set).
+; CHECK: .loc    1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3
+; CHECK: .loc    1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
+; CHECK-NOT: .loc    1 9 5 is_stmt 0 discriminator 11266 # foo.c:9:5
+; CHECK-NOT: .loc    1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
+; Check that variable __llvm_fs_discriminator__ is NOT generated.
+; CHECK-NOT: __llvm_fs_discriminator__:
+
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.Node = type { %struct.Node* }
+
+define i32 @foo(%struct.Node* readonly %node, %struct.Node* readnone %root) !dbg !6 {
+entry:
+  %cmp = icmp eq %struct.Node* %node, %root, !dbg !8
+  br i1 %cmp, label %while.end4, label %while.cond1.preheader.lr.ph, !dbg !10
+
+while.cond1.preheader.lr.ph:
+  %tobool = icmp eq %struct.Node* %node, null
+  br i1 %tobool, label %while.cond1.preheader.us.preheader, label %while.body2.preheader, !dbg !11
+
+while.body2.preheader:
+  br label %while.body2, !dbg !11
+
+while.cond1.preheader.us.preheader:
+  br label %while.cond1.preheader.us, !dbg !10
+
+while.cond1.preheader.us:
+  br label %while.cond1.preheader.us, !dbg !10
+
+while.body2:
+  br label %while.body2, !dbg !11
+
+while.end4:
+  ret i32 0, !dbg !12
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, emissionKind: LineTablesOnly)
+!1 = !DIFile(filename: "foo.c", directory: "b/")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{}
+!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !7, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
+!7 = !DISubroutineType(types: !2)
+!8 = !DILocation(line: 7, column: 15, scope: !9)
+!9 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 2)
+!10 = !DILocation(line: 7, column: 3, scope: !9)
+!11 = !DILocation(line: 9, column: 5, scope: !9)
+!12 = !DILocation(line: 14, column: 3, scope: !6)


        


More information about the llvm-commits mailing list