1; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel -experimental-debug-variable-locations=false \ 2; RUN: | FileCheck %s --check-prefix=NORMAL \ 3; RUN: --implicit-check-not=debug-instr-number \ 4; RUN: --implicit-check-not=DBG_INSTR_REF 5; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \ 6; RUN: -experimental-debug-variable-locations -verify-machineinstrs \ 7; RUN: | FileCheck %s --check-prefix=INSTRREF \ 8; RUN: --implicit-check-not=DBG_VALUE 9; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \ 10; RUN: -experimental-debug-variable-locations -verify-machineinstrs \ 11; RUN: -fast-isel \ 12; RUN: | FileCheck %s --check-prefix=FASTISEL-INSTRREF \ 13; RUN: --implicit-check-not=DBG_VALUE 14 15;; Repeat tests using experimental debuginfo iterators. 16; RUN: llc --try-experimental-debuginfo-iterators %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel -experimental-debug-variable-locations=false \ 17; RUN: | FileCheck %s --check-prefix=NORMAL \ 18; RUN: --implicit-check-not=debug-instr-number \ 19; RUN: --implicit-check-not=DBG_INSTR_REF 20; RUN: llc --try-experimental-debuginfo-iterators %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \ 21; RUN: -experimental-debug-variable-locations -verify-machineinstrs \ 22; RUN: | FileCheck %s --check-prefix=INSTRREF \ 23; RUN: --implicit-check-not=DBG_VALUE 24; RUN: llc --try-experimental-debuginfo-iterators %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \ 25; RUN: -experimental-debug-variable-locations -verify-machineinstrs \ 26; RUN: -fast-isel \ 27; RUN: | FileCheck %s --check-prefix=FASTISEL-INSTRREF \ 28; RUN: --implicit-check-not=DBG_VALUE 29 30; NORMAL: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks", 31; NORMAL: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees", 32; INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks", 33; INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees", 34; FASTISEL-INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks", 35; FASTISEL-INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees", 36 37; Test that SelectionDAG produces DBG_VALUEs normally, but DBG_INSTR_REFs when 38; asked. 39 40; NORMAL-LABEL: name: foo 41 42; NORMAL: %[[REG0:[0-9]+]]:gr32 = ADD32rr 43; NORMAL-NEXT: DBG_VALUE %[[REG0]] 44; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG0]], 2 45; NORMAL-NEXT: %[[REG1:[0-9]+]]:gr32 = ADD32rr 46; NORMAL-NEXT: DBG_VALUE %[[REG1]] 47; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG1]], %[[REG0]] 48 49; Note that I'm baking in an assumption of one-based ordering here. We could 50; capture and check for the instruction numbers, we'd rely on machine verifier 51; ensuring there were no duplicates. 52 53; INSTRREF-LABEL: name: foo 54 55; INSTRREF: ADD32rr 56; INSTRREF-SAME: debug-instr-number 1 57; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0) 58; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0), 2 59; INSTRREF-NEXT: ADD32rr 60; INSTRREF-SAME: debug-instr-number 2 61; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0) 62; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0), dbg-instr-ref(1, 0) 63 64; Test that fast-isel will produce DBG_INSTR_REFs too, except for debug values 65; using DIArgList, which is not supported in FastIsel. 66 67; FASTISEL-INSTRREF-LABEL: name: foo 68 69; FASTISEL-INSTRREF: ADD32rr 70; FASTISEL-INSTRREF-SAME: debug-instr-number 1 71; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0) 72; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}} 73; FASTISEL-INSTRREF-NEXT: ADD32rr 74; FASTISEL-INSTRREF-SAME: debug-instr-number 2 75; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0) 76; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}} 77 78@glob32 = global i32 0 79@glob16 = global i16 0 80@glob8 = global i8 0 81 82declare void @llvm.dbg.value(metadata, metadata, metadata) 83declare void @llvm.dbg.declare(metadata, metadata, metadata) 84 85define i32 @foo(i32 %bar, i32 %baz, i32 %qux) !dbg !7 { 86entry: 87 %0 = add i32 %bar, %baz, !dbg !14 88 call void @llvm.dbg.value(metadata i32 %0, metadata !13, metadata !DIExpression()), !dbg !14 89 call void @llvm.dbg.value(metadata !DIArgList(i32 %0, i32 2), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !14 90 %1 = add i32 %0, %qux 91 call void @llvm.dbg.value(metadata i32 %1, metadata !13, metadata !DIExpression()), !dbg !14 92 call void @llvm.dbg.value(metadata !DIArgList(i32 %1, i32 %0), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !14 93 ret i32 %1, !dbg !14 94} 95 96; In the code below, isel produces a large number of copies between subregisters 97; to represent the gradually decreasing width of the argument. This gets 98; optimized away into three stores, but it's an objective of the instruction 99; referencing design that COPYs are not numbered: they move values, not define 100; them. Test that nothing is numbered, and instead that appropriate 101; substitutions with subregister details are recorded. 102 103; NORMAL-LABEL: name: bar 104 105; NORMAL: DBG_VALUE $rdi 106; NORMAL-NEXT: %0:gr64_with_sub_8bit = COPY $rdi 107; NORMAL-NEXT: DBG_VALUE %0, 108; NORMAL-NEXT: %1:gr32 = COPY %0.sub_32bit, 109; NORMAL-NEXT: DBG_VALUE %1 110; NORMAL: %3:gr16 = COPY %0.sub_16bit, 111; NORMAL-NEXT: DBG_VALUE %3 112; NORMAL: %5:gr8 = COPY %0.sub_8bit, 113; NORMAL-NEXT: DBG_VALUE %5 114 115; INSTRREF-LABEL: name: bar 116 117;; 118; INSTRREF: debugValueSubstitutions: 119; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 0, subreg: 6 } 120; INSTRREF-NEXT: - { srcinst: 4, srcop: 0, dstinst: 3, dstop: 0, subreg: 4 } 121; INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 1 } 122 123;; As a slight inefficiency today, multiple DBG_PHIs are created. 124 125; INSTRREF: DBG_PHI $rdi, 5 126; INSTRREF-NEXT: DBG_PHI $rdi, 3 127; INSTRREF-NEXT: DBG_PHI $rdi, 1 128;; Allow arguments to be specified by physreg DBG_VALUEs. 129; INSTRREF-NEXT: DBG_VALUE $rdi 130 131;; Don't test the location of these instr-refs, only that the three non-argument 132;; dbg.values become DBG_INSTR_REFs. We previously checked that these numbers 133;; get substituted, with appropriate subregister qualifiers. 134; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0) 135; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0) 136; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0) 137 138;; In fast-isel, we get four DBG_INSTR_REFs (compared to three and one 139;; DBG_VALUE with normal isel). We get additional substitutions as a result: 140 141; FASTISEL-INSTRREF: debugValueSubstitutions: 142; FASTISEL-INSTRREF-NEXT: - { srcinst: 3, srcop: 0, dstinst: 2, dstop: 0, subreg: 6 } 143; FASTISEL-INSTRREF-NEXT: - { srcinst: 5, srcop: 0, dstinst: 4, dstop: 0, subreg: 6 } 144; FASTISEL-INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 4 } 145; FASTISEL-INSTRREF-NEXT - { srcinst: 8, srcop: 0, dstinst: 7, dstop: 0, subreg: 6 } 146; FASTISEL-INSTRREF-NEXT - { srcinst: 9, srcop: 0, dstinst: 8, dstop: 0, subreg: 4 } 147; FASTISEL-INSTRREF-NEXT - { srcinst: 10, srcop: 0, dstinst: 9, dstop: 0, subreg: 1 } 148 149;; Those substitutions are anchored against these DBG_PHIs: 150 151; FASTISEL-INSTRREF: DBG_PHI $rdi, 7 152; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 4 153; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 2 154; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 1 155 156; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0) 157; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0) 158; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0) 159; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(10, 0) 160 161define i32 @bar(i64 %bar) !dbg !20 { 162entry: 163 call void @llvm.dbg.value(metadata i64 %bar, metadata !21, metadata !DIExpression()), !dbg !22 164 %0 = trunc i64 %bar to i32, !dbg !22 165 call void @llvm.dbg.value(metadata i32 %0, metadata !21, metadata !DIExpression()), !dbg !22 166 store i32 %0, ptr @glob32, !dbg !22 167 %1 = trunc i32 %0 to i16, !dbg !22 168 call void @llvm.dbg.value(metadata i16 %1, metadata !21, metadata !DIExpression()), !dbg !22 169 store i16 %1, ptr @glob16, !dbg !22 170 %2 = trunc i16 %1 to i8, !dbg !22 171 call void @llvm.dbg.value(metadata i8 %2, metadata !21, metadata !DIExpression()), !dbg !22 172 store i8 %2, ptr @glob8, !dbg !22 173 ret i32 0, !dbg !22 174} 175 176; Ensure that we can track copies back to physreg defs, and throw in a subreg 177; substitution for fun. The call to @xyzzy defines $rax, which gets copied to 178; a VReg, and then truncated by a subreg copy. We should be able to track 179; through the copies and walk back to the physreg def, labelling the CALL 180; instruction. We should also be able to do this even when the block layout is 181; crazily ordered. 182 183; NORMAL-LABEL: name: baz 184 185; NORMAL: CALL64pcrel32 target-flags(x86-plt) @xyzzy 186; NORMAL: %2:gr64 = COPY $rax, 187; NORMAL: %0:gr64 = COPY %2, 188; NORMAL-LABEL: bb.1.slippers: 189; NORMAL: DBG_VALUE %1 190; NORMAL-LABEL: bb.2.shoes: 191; NORMAL: %1:gr16 = COPY %0.sub_16bit 192 193; INSTRREF-LABEL: name: baz 194 195; INSTRREF: debugValueSubstitutions: 196; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 6, subreg: 4 } 197 198; INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-instr-number 1 199; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0) 200 201;; Fast-isel produces the same arrangement, a DBG_INSTR_REF pointing back to 202;; the call instruction. However: the operand numbers are different (6 for 203;; normal isel, 4 for fast-isel). This isn't because of debug-info differences, 204;; it's because normal isel implicit-defs the stack registers, and fast-isel 205;; does not. The meaning is the same. 206 207; FASTISEL-INSTRREF-LABEL: name: baz 208 209; FASTISEL-INSTRREF: debugValueSubstitutions: 210; FASTISEL-INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 4, subreg: 4 } 211 212; FASTISEL-INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-instr-number 1 213; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0) 214 215declare i64 @xyzzy() 216 217define i32 @baz() !dbg !30 { 218entry: 219 %foo = call i64 @xyzzy(), !dbg !32 220 br label %shoes 221 222slippers: 223 call void @llvm.dbg.value(metadata i16 %moo, metadata !31, metadata !DIExpression()), !dbg !32 224 store i16 %moo, ptr @glob16, !dbg !32 225 ret i32 0, !dbg !32 226 227shoes: 228 %moo = trunc i64 %foo to i16 229 br label %slippers 230} 231 232;; Test for dbg.declare of non-stack-slot Values. These turn up with NRVO and 233;; other ABI scenarios where something is technically in memory, but we don't 234;; refer to it relative to the stack pointer. We refer to these either with an 235;; indirect DBG_VALUE, or a DBG_INSTR_REF with DW_OP_deref prepended. 236;; 237;; Test an inlined dbg.declare in a different scope + block, to test behaviours 238;; where the debug intrinsic isn't in the first block. The normal-mode DBG_VALUE 239;; is hoisted into the entry block for that. This is fine because the variable 240;; location is never re-assigned. (FIXME: do we scope-trim / fail-to-propagate 241;; these hoisted locations later?). 242 243; NORMAL-LABEL: name: qux 244; 245; NORMAL: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(), 246; NORMAL-NEXT: %0:gr64 = COPY $rdi 247; NORMAL-NEXT: DBG_VALUE %0, 0, ![[SOCKS]], !DIExpression(), 248; NORMAL-NEXT: DBG_VALUE %0, 0, ![[KNEES]], !DIExpression(), 249 250;; In instruction referencing mode, the "real" argument becomes a DBG_VALUE, 251;; but the hoisted variable location from the inlined scope is a DBG_INSTR_REF. 252 253; INSTRREF-LABEL: name: qux 254 255; INSTRREF: DBG_PHI $rdi, 1 256; INSTRREF-NEXT: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(), 257; INSTRREF-NEXT: %0:gr64 = COPY $rdi 258; INSTRREF-NEXT: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0), 259 260; In fast-isel mode, neither variable are hoisted or forwarded to a physreg. 261 262; FASTISEL-INSTRREF-LABEL: name: qux 263 264; FASTISEL-INSTRREF: DBG_PHI $rdi, 1 265; FASTISEL-INSTRREF: DBG_INSTR_REF ![[SOCKS]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0), 266 267; FASTISEL-INSTRREF-LABEL: bb.1.lala: 268; FASTISEL-INSTRREF: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0), 269declare i64 @cheddar(ptr %arg) 270 271define void @qux(ptr noalias sret(i32) %agg.result) !dbg !40 { 272entry: 273 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !41, metadata !DIExpression()), !dbg !42 274 %foo = call i64 @cheddar(ptr %agg.result), !dbg !42 275 br label %lala 276 277lala: 278 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !45, metadata !DIExpression()), !dbg !44 279 ret void, !dbg !44 280} 281 282 283 284!llvm.dbg.cu = !{!0} 285!llvm.module.flags = !{!3, !4} 286 287!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) 288!1 = !DIFile(filename: "exprconflict.c", directory: "/home/jmorse") 289!2 = !{} 290!3 = !{i32 2, !"Dwarf Version", i32 4} 291!4 = !{i32 2, !"Debug Info Version", i32 3} 292!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 293!8 = !DISubroutineType(types: !9) 294!9 = !{!10, !10} 295!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 296!11 = !{!13} 297!13 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 6, type: !10) 298!14 = !DILocation(line: 1, scope: !7) 299!20 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 300!21 = !DILocalVariable(name: "xyzzy", scope: !20, file: !1, line: 6, type: !10) 301!22 = !DILocation(line: 1, scope: !20) 302!30 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 303!31 = !DILocalVariable(name: "xyzzy", scope: !30, file: !1, line: 6, type: !10) 304!32 = !DILocation(line: 1, scope: !30) 305!40 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 306!41 = !DILocalVariable(name: "socks", scope: !40, file: !1, line: 6, type: !10) 307!42 = !DILocation(line: 1, scope: !40) 308!43 = distinct !DISubprogram(name: "inlined", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 309!44 = !DILocation(line: 0, scope: !43, inlinedAt: !42) 310!45 = !DILocalVariable(name: "knees", scope: !43, file: !1, line: 6, type: !10) 311