Skip to content

Commit d871f40

Browse files
authored
[WebAssembly] Use DebugValueManager only when subprogram exists (#77978)
We previously scanned the whole BB for `DBG_VALUE` instruction even when the program doesn't have debug info, i.e., the function doesn't have a subprogram associated with it, which can make compilation unnecessarily slow. This disables `DebugValueManager` when a `DISubprogram` doesn't exist for a function. This only reduces unnecessary work in non-debug mode and does not change output, so it's hard to add a test to test this behavior. Test changes were necessary because their `DISubprogram`s were not correctly linked with the functions, so with this PR the compiler incorrectly assumed the functions didn't have a subprogram and the tests started to fail. Fixes emscripten-core/emscripten#21048.
1 parent 91b53a2 commit d871f40

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
#include "WebAssemblyMachineFunctionInfo.h"
1818
#include "llvm/CodeGen/MachineInstr.h"
1919
#include "llvm/IR/DebugInfoMetadata.h"
20+
#include "llvm/IR/Function.h"
2021

2122
using namespace llvm;
2223

2324
WebAssemblyDebugValueManager::WebAssemblyDebugValueManager(MachineInstr *Def)
2425
: Def(Def) {
26+
if (!Def->getMF()->getFunction().getSubprogram())
27+
return;
28+
2529
// This code differs from MachineInstr::collectDebugValues in that it scans
2630
// the whole BB, not just contiguous DBG_VALUEs, until another definition to
2731
// the same register is encountered.

llvm/test/CodeGen/WebAssembly/cfg-stackify-dbg-skip.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
target triple = "wasm32-unknown-unknown"
1717

18-
define void @foo(i64 %arg) {
18+
define void @foo(i64 %arg) !dbg !37 {
1919
start:
2020
%val = trunc i64 %arg to i32
2121
%cmp = icmp eq i32 %val, 0
@@ -39,7 +39,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
3939
!22 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "&str", file: !6, size: 64, align: 32, elements: !{}, identifier: "111094d970b097647de579f9c509ef08")
4040
!33 = !{i32 2, !"Debug Info Version", i32 3}
4141
!35 = distinct !DILexicalBlock(scope: !37, file: !6, line: 357, column: 8)
42-
!37 = distinct !DISubprogram(name: "foobar", linkageName: "_fooba", scope: !38, file: !6, line: 353, type: !39, isLocal: true, isDefinition: true, scopeLine: 353, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !2, retainedNodes: !42)
42+
!37 = distinct !DISubprogram(name: "foo", scope: !6, file: !6, line: 353, type: !39, isLocal: true, isDefinition: true, scopeLine: 353, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !2, retainedNodes: !42)
4343
!38 = !DINamespace(name: "ptr", scope: null)
4444
!39 = !DISubroutineType(types: !2)
4545
!42 = !{!46}

llvm/test/DebugInfo/WebAssembly/dbg-value-move-clone.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
declare void @foo(i32)
2121
declare i32 @bar()
2222

23-
define void @test(i64 %arg) {
23+
define void @test(i64 %arg) !dbg !6 {
2424
unreachable
2525
}
2626

@@ -32,7 +32,7 @@
3232
!3 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "&str", file: !2, size: 64, align: 32, elements: !{}, identifier: "111094d970b097647de579f9c509ef08")
3333
!4 = !{i32 2, !"Debug Info Version", i32 3}
3434
!5 = distinct !DILexicalBlock(scope: !6, file: !2, line: 357, column: 8)
35-
!6 = distinct !DISubprogram(name: "testfoo", linkageName: "_testba", scope: !7, file: !2, line: 353, type: !8, isLocal: true, isDefinition: true, scopeLine: 353, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !1, retainedNodes: !9)
35+
!6 = distinct !DISubprogram(name: "test", scope: !7, file: !2, line: 353, type: !8, isLocal: true, isDefinition: true, scopeLine: 353, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !1, retainedNodes: !9)
3636
!7 = !DINamespace(name: "ptr", scope: null)
3737
!8 = !DISubroutineType(types: !1)
3838
!9 = !{!10}

llvm/test/DebugInfo/WebAssembly/dbg-value-reg-stackify.mir

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@
88
declare void @use(i32)
99
declare void @use_2(i32, i32)
1010

11-
define void @sink_simple() {
11+
define void @sink_simple() !dbg !6 {
1212
call void @llvm.dbg.value(metadata i32 0, metadata !5, metadata !DIExpression()), !dbg !10
1313
call void @llvm.dbg.value(metadata i32 0, metadata !11, metadata !DIExpression()), !dbg !10
1414
call void @llvm.dbg.value(metadata i32 0, metadata !12, metadata !DIExpression()), !dbg !10
1515
call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !10
1616
ret void
1717
}
18-
define void @sink_non_consecutive() {
18+
define void @sink_non_consecutive() !dbg !14 {
1919
unreachable
2020
}
21-
define void @dont_sink_above_def() {
21+
define void @dont_sink_above_def() !dbg !15 {
2222
unreachable
2323
}
24-
define void @sink_to_same_place() {
24+
define void @sink_to_same_place() !dbg !16 {
2525
unreachable
2626
}
27-
define void @cannot_sink_across_same_variable() {
27+
define void @cannot_sink_across_same_variable() !dbg !17 {
2828
unreachable
2929
}
30-
define void @cannot_sink_across_same_variable2() {
30+
define void @cannot_sink_across_same_variable2() !dbg !18 {
3131
unreachable
3232
}
33-
define void @can_sink_across_same_variable_with_same_const() {
33+
define void @can_sink_across_same_variable_with_same_const() !dbg !19 {
3434
unreachable
3535
}
36-
define void @sink_multiple_defs() {
36+
define void @sink_multiple_defs() !dbg !20 {
3737
unreachable
3838
}
39-
define void @clone_same_bb() {
39+
define void @clone_same_bb() !dbg !21 {
4040
unreachable
4141
}
42-
define void @clone_different_bb() {
42+
define void @clone_different_bb() !dbg !22 {
4343
unreachable
4444
}
45-
define void @tee_with_two_use_insts() {
45+
define void @tee_with_two_use_insts() !dbg !23 {
4646
unreachable
4747
}
48-
define void @tee_with_one_inst_with_two_uses() {
48+
define void @tee_with_one_inst_with_two_uses() !dbg !24 {
4949
unreachable
5050
}
5151
declare void @llvm.dbg.value(metadata, metadata, metadata)
@@ -81,6 +81,17 @@
8181
; CHECK: ![[VAR_C:[0-9]+]] = !DILocalVariable(name: "var_c"
8282
!13 = !DILocalVariable(name: "var_d", scope: !6, file: !1, line: 2, type: !9)
8383
; CHECK: ![[VAR_D:[0-9]+]] = !DILocalVariable(name: "var_d"
84+
!14 = distinct !DISubprogram(name: "sink_non_consecutive", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
85+
!15 = distinct !DISubprogram(name: "dont_sink_above_def", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
86+
!16 = distinct !DISubprogram(name: "sink_to_same_place", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
87+
!17 = distinct !DISubprogram(name: "cannot_sink_across_same_variable", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
88+
!18 = distinct !DISubprogram(name: "cannot_sink_across_same_variable2", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
89+
!19 = distinct !DISubprogram(name: "can_sink_across_same_variable_with_same_const", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
90+
!20 = distinct !DISubprogram(name: "sink_multiple_defs", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
91+
!21 = distinct !DISubprogram(name: "clone_same_bb", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
92+
!22 = distinct !DISubprogram(name: "clone_different_bb", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
93+
!23 = distinct !DISubprogram(name: "tee_with_two_use_insts", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
94+
!24 = distinct !DISubprogram(name: "tee_with_one_inst_with_two_uses", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
8495
...
8596

8697
---

0 commit comments

Comments
 (0)