Skip to content

Commit ae88aa9

Browse files
authored
[LiveDebugValues] Disable spill tracking on AMDGPU (llvm#769)
2 parents bd802d4 + 6a1e082 commit ae88aa9

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ static cl::opt<unsigned>
156156
cl::desc("livedebugvalues-stack-ws-limit"),
157157
cl::init(250));
158158

159+
// Limit for the maximum number of stack slot indexes. On targets where this is
160+
// exceeded, this effectivly disables tracking debug locations across spills.
161+
// The spill tracking in MLocTracker performs quite poorly in terms of memory
162+
// and time on targets with a more complicated register file (FIXME).
163+
static cl::opt<unsigned>
164+
StackSlotIdxesLimit("livedebugvalues-max-stack-slot-idxes", cl::Hidden,
165+
cl::desc("livedebugvalues-max-stack-slot-idxes"),
166+
cl::init(128));
167+
159168
DbgOpID DbgOpID::UndefID = DbgOpID(0xffffffff);
160169

161170
/// Tracker for converting machine value locations and variable values into
@@ -1123,6 +1132,10 @@ void MLocTracker::writeRegMask(const MachineOperand *MO, unsigned CurBB,
11231132
}
11241133

11251134
std::optional<SpillLocationNo> MLocTracker::getOrTrackSpillLoc(SpillLoc L) {
1135+
// Disable spill tracking on targets with a large number of slot idxes.
1136+
if (NumSlotIdxes >= StackSlotIdxesLimit)
1137+
return std::nullopt;
1138+
11261139
SpillLocationNo SpillID(SpillLocs.idFor(L));
11271140

11281141
if (SpillID.id() == 0) {
@@ -3707,6 +3720,15 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
37073720
VTracker = nullptr;
37083721
TTracker = nullptr;
37093722

3723+
if (MTracker->NumSlotIdxes >= StackSlotIdxesLimit) {
3724+
LLVM_DEBUG(
3725+
dbgs() << "Disabling InstrRefBasedLDV spill tracking for "
3726+
<< MF.getName()
3727+
<< " since target has too many potential stack slot indexes ("
3728+
<< MTracker->NumSlotIdxes << ", limit is " << StackSlotIdxesLimit
3729+
<< ")\n");
3730+
}
3731+
37103732
SmallVector<MLocTransferMap, 32> MLocTransfer;
37113733
SmallVector<VLocTracker, 8> vlocs;
37123734
LiveInsT SavedLiveIns;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -run-pass livedebugvalues %s -o - -debug-only livedebugvalues 2>&1 | FileCheck %s
3+
4+
# Verify that spill tracking is disabled on amdgcn.
5+
6+
# CHECK: Disabling InstrRefBasedLDV spill tracking for kern since target has too many potential stack slot indexes
7+
8+
--- |
9+
define void @kern() #0 !dbg !9 {
10+
ret void, !dbg !15
11+
}
12+
13+
attributes #0 = { noinline nounwind optnone "target-cpu"="gfx1100" }
14+
15+
!llvm.dbg.cu = !{!0}
16+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
17+
!llvm.ident = !{!8}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 19.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
20+
!1 = !DIFile(filename: "t.cpp", directory: "/")
21+
!2 = !{i32 1, !"amdhsa_code_object_version", i32 500}
22+
!3 = !{i32 7, !"Dwarf Version", i32 5}
23+
!4 = !{i32 2, !"Debug Info Version", i32 3}
24+
!5 = !{i32 1, !"wchar_size", i32 4}
25+
!6 = !{i32 8, !"PIC Level", i32 2}
26+
!7 = !{i32 7, !"frame-pointer", i32 2}
27+
!8 = !{!"clang version 19.0.0"}
28+
!9 = distinct !DISubprogram(name: "kern", linkageName: "kern", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
29+
!10 = !DISubroutineType(types: !11)
30+
!11 = !{}
31+
!12 = !{!13}
32+
!13 = !DILocalVariable(name: "var", scope: !9, file: !1, line: 1, type: !14)
33+
!14 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed)
34+
!15 = !DILocation(line: 1, column: 1, scope: !9)
35+
36+
...
37+
---
38+
name: kern
39+
tracksRegLiveness: true
40+
debugInstrRef: true
41+
stack:
42+
- { id: 0, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4 }
43+
machineFunctionInfo:
44+
scratchRSrcReg: $sgpr0_sgpr1_sgpr2_sgpr3
45+
stackPtrOffsetReg: '$sgpr32'
46+
hasSpilledVGPRs: true
47+
body: |
48+
bb.0:
49+
; CHECK-LABEL: name: kern
50+
; CHECK: frame-setup CFI_INSTRUCTION escape 0x0f, 0x09, 0x90, 0x40, 0x94, 0x04, 0x36, 0x24, 0x36, 0xe9, 0x02
51+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION llvm_register_pair $pc_reg, $sgpr30, 32, $sgpr31, 32
52+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION undefined $vgpr0
53+
; CHECK-NEXT: DBG_INSTR_REF !13, !DIExpression(DIOpArg(0, i32)), dbg-instr-ref(1, 0), debug-location !15
54+
; CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DIOpArg(0, i32)), $noreg, debug-location !15
55+
; CHECK-NEXT: $vgpr0 = V_MOV_B32_e32 0, implicit $exec, debug-instr-number 1, debug-location !15
56+
; CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DIOpArg(0, i32)), $vgpr0, debug-location !15
57+
; CHECK-NEXT: SCRATCH_STORE_DWORD_SADDR killed $vgpr0, $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (store (s32) into %stack.0, addrspace 5)
58+
; CHECK-NEXT: S_NOP 0, debug-location !15
59+
; CHECK-NEXT: $vgpr0 = SCRATCH_LOAD_DWORD_SADDR $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (load (s32) from %stack.0, addrspace 5)
60+
; CHECK-NEXT: S_ENDPGM 0, debug-location !15
61+
frame-setup CFI_INSTRUCTION escape 0x0f, 0x09, 0x90, 0x40, 0x94, 0x04, 0x36, 0x24, 0x36, 0xe9, 0x02
62+
frame-setup CFI_INSTRUCTION llvm_register_pair $pc_reg, $sgpr30, 32, $sgpr31, 32
63+
frame-setup CFI_INSTRUCTION undefined $vgpr0
64+
DBG_INSTR_REF !13, !DIExpression(DIOpArg(0, i32)), dbg-instr-ref(1, 0), debug-location !15
65+
$vgpr0 = V_MOV_B32_e32 0, implicit $exec, debug-instr-number 1, debug-location !15
66+
SCRATCH_STORE_DWORD_SADDR killed $vgpr0, $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (store (s32) into %stack.0, addrspace 5)
67+
S_NOP 0, debug-location !15
68+
$vgpr0 = SCRATCH_LOAD_DWORD_SADDR $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (load (s32) from %stack.0, addrspace 5)
69+
S_ENDPGM 0, debug-location !15
70+
71+
...

0 commit comments

Comments
 (0)