Files
clang-p2996/llvm/test/DebugInfo/MIR/InstrRef/phi-through-regalloc.mir
Jeremy Morse 8496fc2ec8 [DebugInstrRef][1/3] Track PHI values through register allocation
This patch introduces "DBG_PHI" instructions, a marker of where a PHI
instruction used to be, before PHI elimination. Under the instruction
referencing model, we want to know where every value in the function is
defined -- and a PHI, even if implicit, is such a place.

Just like instruction numbers, we can use this to identify a value to be
used as a variable value, but we don't need to know what instruction
defines that value, for example:

bb1:
   DBG_PHI $rax, 1
   [... more insts ... ]
bb2:
   DBG_INSTR_REF 1, 0, !1234, !DIExpression()

This specifies that on entry to bb1, whatever value is in $rax is known
as value number one -- and the later DBG_INSTR_REF marks the position
where variable !1234 should take on value number one.

PHI locations are stored in MachineFunction for the duration of the
regalloc phase in the DebugPHIPositions map. The map is populated by
PHIElimination, and then flushed back into the instruction stream by
virtregrewriter. A small amount of maintenence is needed in
LiveDebugVariables to account for registers being split, but only for
individual positions, not for entire ranges of blocks.

Differential Revision: https://reviews.llvm.org/D86812
2021-05-26 20:24:00 +01:00

135 lines
5.5 KiB
YAML

# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
# RUN: -experimental-debug-variable-locations \
# RUN: -run-pass=phi-node-elimination,livedebugvars,greedy,virtregrewriter \
# RUN: | FileCheck %s
#
# This test checks that for a very simple PHI, we produce a corresponding
# DBG_PHI instruction, that a DBG_INSTR_REF refers to. Tests the path through
# phi-node-elimination, live debug variables, and then placement after register
# allocation.
#
# Original code, compiled with only -mem2reg, then fed to llc -stop-before...
#
# int ext(int);
# int foo(int bar, int baz) {
# int either = 0;
# if (ext(0))
# either = bar;
# else
# either = baz;
#
# return either;
# }
#
--- |
; ModuleID = 'promoted.ll'
source_filename = "test.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define dso_local i32 @foo(i32 %bar, i32 %baz) !dbg !7 {
entry:
call void @llvm.dbg.value(metadata i32 %bar, metadata !11, metadata !DIExpression()), !dbg !12
call void @llvm.dbg.value(metadata i32 %baz, metadata !13, metadata !DIExpression()), !dbg !12
call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression()), !dbg !12
%call = call i32 @ext(i32 0), !dbg !15
%tobool = icmp ne i32 %call, 0, !dbg !15
br i1 %tobool, label %if.end, label %if.else, !dbg !17
if.else: ; preds = %entry
call void @llvm.dbg.value(metadata i32 %baz, metadata !14, metadata !DIExpression()), !dbg !12
br label %if.end
if.end: ; preds = %entry, %if.else
%either.0 = phi i32 [ %baz, %if.else ], [ %bar, %entry ], !dbg !18
call void @llvm.dbg.value(metadata i32 %either.0, metadata !14, metadata !DIExpression()), !dbg !12
ret i32 %either.0, !dbg !19
}
declare dso_local i32 @ext(i32)
; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.value(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: ".")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"."}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10, !10, !10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 2, type: !10)
!12 = !DILocation(line: 0, scope: !7)
!13 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 2, type: !10)
!14 = !DILocalVariable(name: "either", scope: !7, file: !1, line: 3, type: !10)
!15 = !DILocation(line: 4, column: 7, scope: !16)
!16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 7)
!17 = !DILocation(line: 4, column: 7, scope: !7)
!18 = !DILocation(line: 0, scope: !16)
!19 = !DILocation(line: 9, column: 3, scope: !7)
...
---
name: foo
alignment: 16
tracksRegLiveness: true
registers:
- { id: 0, class: gr32 }
- { id: 1, class: gr32 }
- { id: 2, class: gr32 }
- { id: 3, class: gr32 }
- { id: 4, class: gr32 }
liveins:
- { reg: '$edi', virtual-reg: '%1' }
- { reg: '$esi', virtual-reg: '%2' }
frameInfo:
maxAlignment: 1
hasCalls: true
machineFunctionInfo: {}
body: |
bb.0.entry:
successors: %bb.2(0x50000000), %bb.1(0x30000000)
liveins: $edi, $esi
DBG_VALUE $edi, $noreg, !11, !DIExpression(), debug-location !12
DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !12
%2:gr32 = COPY killed $esi
DBG_VALUE %2, $noreg, !13, !DIExpression(), debug-location !12
%1:gr32 = COPY killed $edi
DBG_VALUE %1, $noreg, !11, !DIExpression(), debug-location !12
DBG_VALUE 0, $noreg, !14, !DIExpression(), debug-location !12
ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
%3:gr32 = MOV32r0 implicit-def dead $eflags
$edi = COPY killed %3, debug-location !15
CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit killed $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
%4:gr32 = COPY killed $eax, debug-location !15
TEST32rr killed %4, %4, implicit-def $eflags, debug-location !15
JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !17
JMP_1 %bb.1, debug-location !17
bb.1.if.else:
DBG_VALUE %2, $noreg, !14, !DIExpression(), debug-location !12
; CHECK-LABEL: bb.2.if.end:
bb.2.if.end:
%0:gr32 = PHI %1, %bb.0, %2, %bb.1, debug-instr-number 1, debug-location !18
DBG_INSTR_REF 1, 0, !14, !DIExpression(), debug-location !12
; CHECK: DBG_PHI $ebp, 1
; CHECK: DBG_INSTR_REF 1, 0
$eax = COPY killed %0, debug-location !19
; Confirm that %0 is allocated in $ebp,
; CHECK: $eax = COPY killed renamable $ebp
RET 0, killed $eax, debug-location !19
...