1# RUN: llc -run-pass livedebugvalues %s -o - | FileCheck %s 2 3# Test if LiveDebugValue analysis works on Wasm. 4 5--- | 6 target triple = "wasm32-unknown-unknown" 7 8 define void @test_consts() !dbg !5 { 9 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !10 10 call void @llvm.dbg.value(metadata i32 0, metadata !11, metadata !DIExpression()), !dbg !10 11 call void @llvm.dbg.value(metadata i32 0, metadata !12, metadata !DIExpression()), !dbg !10 12 call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !10 13 ret void 14 } 15 16 define void @test_target_indices() !dbg !14 { 17 call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !16 18 call void @llvm.dbg.value(metadata i32 0, metadata !17, metadata !DIExpression()), !dbg !16 19 call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !16 20 call void @llvm.dbg.value(metadata i32 0, metadata !19, metadata !DIExpression()), !dbg !16 21 call void @llvm.dbg.value(metadata i32 0, metadata !20, metadata !DIExpression()), !dbg !16 22 ret void 23 } 24 25 define void @test_target_index_defs() !dbg !21 { 26 call void @llvm.dbg.value(metadata i32 0, metadata !22, metadata !DIExpression()), !dbg !23 27 call void @llvm.dbg.value(metadata i32 0, metadata !24, metadata !DIExpression()), !dbg !23 28 call void @llvm.dbg.value(metadata i32 0, metadata !25, metadata !DIExpression()), !dbg !23 29 ret void 30 } 31 32 declare void @llvm.dbg.value(metadata, metadata, metadata) 33 34 !llvm.dbg.cu = !{!0} 35 !llvm.module.flags = !{!2, !3, !4} 36 37 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug) 38 !1 = !DIFile(filename: "test.c", directory: "") 39 !2 = !{i32 7, !"Dwarf Version", i32 5} 40 !3 = !{i32 2, !"Debug Info Version", i32 3} 41 !4 = !{i32 1, !"wchar_size", i32 4} 42 !5 = distinct !DISubprogram(name: "test_consts", scope: !1, file: !1, line: 1, type: !6, scopeLine: 1, unit: !0) 43 ; CHECK: ![[T0_SP:[0-9]+]] = distinct !DISubprogram(name: "test_consts" 44 !6 = !DISubroutineType(types: !7) 45 !7 = !{!8} 46 !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 47 !9 = !DILocalVariable(name: "var0", scope: !5, file: !1, line: 2, type: !8) 48 ; CHECK: ![[T0_VAR0:[0-9]+]] = !DILocalVariable(name: "var0", scope: ![[T0_SP]] 49 !10 = !DILocation(line: 0, scope: !5) 50 !11 = !DILocalVariable(name: "var1", scope: !5, file: !1, line: 2, type: !8) 51 ; CHECK: ![[T0_VAR1:[0-9]+]] = !DILocalVariable(name: "var1", scope: ![[T0_SP]] 52 !12 = !DILocalVariable(name: "var2", scope: !5, file: !1, line: 2, type: !8) 53 ; CHECK: ![[T0_VAR2:[0-9]+]] = !DILocalVariable(name: "var2", scope: ![[T0_SP]] 54 !13 = !DILocalVariable(name: "var3", scope: !5, file: !1, line: 2, type: !8) 55 ; CHECK: ![[T0_VAR3:[0-9]+]] = !DILocalVariable(name: "var3", scope: ![[T0_SP]] 56 !14 = distinct !DISubprogram(name: "test_target_indices", scope: !1, file: !1, line: 10, type: !6, scopeLine: 1, unit: !0) 57 ; CHECK: ![[T1_SP:[0-9]+]] = distinct !DISubprogram(name: "test_target_indices" 58 !15 = !DILocalVariable(name: "var0", scope: !14, file: !1, line: 11, type: !8) 59 ; CHECK: ![[T1_VAR0:[0-9]+]] = !DILocalVariable(name: "var0", scope: ![[T1_SP]] 60 !16 = !DILocation(line: 10, scope: !14) 61 !17 = !DILocalVariable(name: "var1", scope: !14, file: !1, line: 11, type: !8) 62 ; CHECK: ![[T1_VAR1:[0-9]+]] = !DILocalVariable(name: "var1", scope: ![[T1_SP]] 63 !18 = !DILocalVariable(name: "var2", scope: !14, file: !1, line: 11, type: !8) 64 ; CHECK: ![[T1_VAR2:[0-9]+]] = !DILocalVariable(name: "var2", scope: ![[T1_SP]] 65 !19 = !DILocalVariable(name: "var3", scope: !14, file: !1, line: 11, type: !8) 66 ; CHECK: ![[T1_VAR3:[0-9]+]] = !DILocalVariable(name: "var3", scope: ![[T1_SP]] 67 !20 = !DILocalVariable(name: "var4", scope: !14, file: !1, line: 11, type: !8) 68 ; CHECK: ![[T1_VAR4:[0-9]+]] = !DILocalVariable(name: "var4", scope: ![[T1_SP]] 69 !21 = distinct !DISubprogram(name: "test_target_index_defs", scope: !1, file: !1, line: 10, type: !6, scopeLine: 1, unit: !0) 70 !22 = !DILocalVariable(name: "var0", scope: !21, file: !1, line: 20, type: !8) 71 !23 = !DILocation(line: 10, scope: !21) 72 !24 = !DILocalVariable(name: "var1", scope: !21, file: !1, line: 20, type: !8) 73 !25 = !DILocalVariable(name: "var2", scope: !21, file: !1, line: 20, type: !8) 74... 75 76--- 77# var0: Its debug value is set once in bb.0 and valid throughout the function. 78# So a new DBG_VALUE will be added to the beginnings of all other BBs 79# (bb.1, bb.2, and bb.3). 80# var1: Its debug value is set in bb.0, but is reset to no info in bb.1. So a 81# new DBG_VALUE will be added in the beginning of bb.1 and bb.2, but bb.3 82# will not, because its two predecesors (bb.1 and bb.2) have different 83# debug values. 84# var2: Its debug value is set both in bb.1 and bb.2 with the same value. bb.3 85# will have a new DBG_VALUE representing that value. 86# var3: Its debug value is set both in bb.1 and bb.2 but with different values. 87# bb.3 will NOT have a new DBG_VALUE instruction because its predecessors 88# don't agree on a value. 89# CHECK-LABEL: name: test_consts 90name: test_consts 91liveins: 92 - { reg: '$arguments' } 93body: | 94 bb.0: 95 successors: %bb.1, %bb.2 96 liveins: $arguments 97 DBG_VALUE 10, $noreg, !9, !DIExpression(), debug-location !10 98 DBG_VALUE 20, $noreg, !11, !DIExpression(), debug-location !10 99 %0:i32 = CONST_I32 1, implicit-def $arguments 100 BR_IF %bb.2, %0:i32, implicit-def $arguments 101 102 ; CHECK: bb.1: 103 ; CHECK-DAG: DBG_VALUE 10, $noreg, ![[T0_VAR0]] 104 ; CHECK-DAG: DBG_VALUE 20, $noreg, ![[T0_VAR1]] 105 bb.1: 106 ; predecessors: %bb.0 107 successors: %bb.3 108 DBG_VALUE $noreg, $noreg, !11, !DIExpression(), debug-location !10 109 DBG_VALUE 30, $noreg, !12, !DIExpression(), debug-location !10 110 DBG_VALUE 30, $noreg, !13, !DIExpression(), debug-location !10 111 BR %bb.3, implicit-def $arguments 112 113 ; CHECK: bb.2: 114 ; CHECK-DAG: DBG_VALUE 10, $noreg, ![[T0_VAR0]] 115 ; CHECK-DAG: DBG_VALUE 20, $noreg, ![[T0_VAR1]] 116 bb.2: 117 ; predecessors: %bb.0 118 successors: %bb.3 119 DBG_VALUE 30, $noreg, !12, !DIExpression(), debug-location !10 120 DBG_VALUE 40, $noreg, !13, !DIExpression(), debug-location !10 121 BR %bb.3, implicit-def $arguments 122 123 ; CHECK: bb.3: 124 ; CHECK-DAG: DBG_VALUE 10, $noreg, ![[T0_VAR0]] 125 ; CHECK-DAG: DBG_VALUE 30, $noreg, ![[T0_VAR2]] 126 ; CHECK-NOT: DBG_VALUE {{[0-9]+}}, $noreg, ![[T0_VAR1]] 127 ; CHECK-NOT: DBG_VALUE {{[0-9]+}}, $noreg, ![[T0_VAR3]] 128 bb.3: 129 ; predecessors: %bb.1, %bb.2 130 RETURN implicit-def dead $arguments 131... 132 133--- 134# var0: Its debug value is set once in bb.0 and valid throughout the function. 135# So a new DBG_VALUE will be added to the beginnings of all other BBs 136# (bb.1, bb.2, and bb.3). 137# var1: Its debug value is set in bb.0, but is reset to no info back later in 138# bb.0. So no DBG_VALUEs will be added in other BBs. 139# var2: Its debug value is set both in bb.1 and bb.2 with the same value (The 140# same kind (local) and same local index). bb.3 will have a new DBG_VALUE 141# representing that value. 142# var3: Its debug value is set both in bb.1 and bb.2 but with different values. 143# Both are locals, but their indices are different. bb.3 will NOT have a 144# new DBG_VALUE instruction because its predecessors don't agree on a 145# value. 146# var4: Its debug value is set both in bb.1 and bb.2 but with different values. 147# They have different kinds; one is a local and the other is a stack 148# operand. (Their index is the same, but it doesn't matter.) bb.3 will NOT 149# have a new DBG_VALUE instruction because its predecessors don't agree on 150# a value. 151# CHECK-LABEL: name: test_target_indices 152name: test_target_indices 153liveins: 154 - { reg: '$arguments' } 155body: | 156 bb.0: 157 successors: %bb.1, %bb.2 158 liveins: $arguments 159 DBG_VALUE target-index(wasm-local), $noreg, !15, !DIExpression(), debug-location !16 160 DBG_VALUE target-index(wasm-operand-stack) + 2, $noreg, !17, !DIExpression(), debug-location !16 161 %0:i32 = CONST_I32 1, implicit-def $arguments 162 DBG_VALUE $noreg, $noreg, !17, !DIExpression(), debug-location !16 163 BR_IF %bb.2, %0:i32, implicit-def $arguments 164 165 ; CHECK: bb.1: 166 ; CHECK: DBG_VALUE target-index(wasm-local), $noreg, ![[T1_VAR0]] 167 bb.1: 168 ; predecessors: %bb.0 169 successors: %bb.3 170 DBG_VALUE target-index(wasm-local) + 2, $noreg, !18, !DIExpression(), debug-location !16 171 DBG_VALUE target-index(wasm-local) + 3, $noreg, !19, !DIExpression(), debug-location !16 172 DBG_VALUE target-index(wasm-operand-stack) + 3, $noreg, !20, !DIExpression(), debug-location !16 173 BR %bb.3, implicit-def $arguments 174 175 ; CHECK: bb.2: 176 ; CHECK: DBG_VALUE target-index(wasm-local), $noreg, ![[T1_VAR0]] 177 bb.2: 178 ; predecessors: %bb.0 179 successors: %bb.3 180 DBG_VALUE target-index(wasm-local) + 2, $noreg, !18, !DIExpression(), debug-location !16 181 DBG_VALUE target-index(wasm-local) + 5, $noreg, !19, !DIExpression(), debug-location !16 182 DBG_VALUE target-index(wasm-local) + 3, $noreg, !20, !DIExpression(), debug-location !16 183 BR %bb.3, implicit-def $arguments 184 185 ; CHECK: bb.3: 186 ; CHECK-DAG: DBG_VALUE target-index(wasm-local), $noreg, ![[T1_VAR0]] 187 ; CHECK-DAG: DBG_VALUE target-index(wasm-local) + 2, $noreg, ![[T1_VAR2]] 188 ; CHECK-NOT: DBG_VALUE target-index(wasm-local){{.*}}, $noreg, ![[T1_VAR3]] 189 ; CHECK-NOT: DBG_VALUE target-index(wasm-local){{.*}}, $noreg, ![[T1_VAR4]] 190 bb.3: 191 ; predecessors: %bb.1, %bb.2 192 RETURN implicit-def dead $arguments 193... 194 195--- 196# bb.0 defines DBG_VALUEs for local index 2 and 3. The DBG_VALUE for local index 197# 2 is killed in bb.1 due to 'local.tee 2' there, and DBG_VALUE for local 198# index 3 is killed in bb.2 because there is 'local.set 3' there. As a result, 199# bb.3 shoudln't have any additional DBG_VALUEs added for those locals. 200# CHECK-LABEL: name: test_target_index_defs 201name: test_target_index_defs 202liveins: 203 - { reg: '$arguments' } 204body: | 205 bb.0: 206 successors: %bb.1, %bb.2 207 liveins: $arguments 208 DBG_VALUE target-index(wasm-local) + 2, $noreg, !22, !DIExpression(), debug-location !23 209 DBG_VALUE target-index(wasm-local) + 3, $noreg, !24, !DIExpression(), debug-location !23 210 %0:i32 = CONST_I32 1, implicit-def $arguments 211 BR_IF %bb.2, %0:i32, implicit-def $arguments 212 213 bb.1: 214 ; predecessors: %bb.0 215 successors: %bb.3 216 %0:i32 = CONST_I32 1, implicit-def $arguments 217 %1:i32 = LOCAL_TEE_I32 2, %0:i32, implicit-def $arguments 218 DROP_I32 killed %1:i32, implicit-def $arguments 219 BR %bb.3, implicit-def $arguments 220 221 bb.2: 222 ; predecessors: %bb.0 223 successors: %bb.3 224 %0:i32 = CONST_I32 1, implicit-def $arguments 225 LOCAL_SET_I32 3, %0:i32, implicit-def $arguments 226 BR %bb.3, implicit-def $arguments 227 228 ; CHECK: bb.3: 229 ; CHECK-NOT: DBG_VALUE target-index(wasm-local){{.*}} 230 bb.3: 231 ; predecessors: %bb.1, %bb.2 232 RETURN implicit-def dead $arguments 233... 234