Skip to content

Commit d46580c

Browse files
authored
[LiveDebugValues] Disable spill tracking on AMDGPU (llvm#775)
2 parents 6d27f9d + 711a357 commit d46580c

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
# REQUIRES: asserts
5+
6+
# Verify that spill tracking is disabled on amdgcn.
7+
8+
# CHECK: Disabling InstrRefBasedLDV spill tracking for kern since target has too many potential stack slot indexes
9+
10+
--- |
11+
define void @kern() #0 !dbg !9 {
12+
ret void, !dbg !15
13+
}
14+
15+
attributes #0 = { noinline nounwind optnone "target-cpu"="gfx1100" }
16+
17+
!llvm.dbg.cu = !{!0}
18+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
19+
!llvm.ident = !{!8}
20+
21+
!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)
22+
!1 = !DIFile(filename: "t.cpp", directory: "/")
23+
!2 = !{i32 1, !"amdhsa_code_object_version", i32 500}
24+
!3 = !{i32 7, !"Dwarf Version", i32 5}
25+
!4 = !{i32 2, !"Debug Info Version", i32 3}
26+
!5 = !{i32 1, !"wchar_size", i32 4}
27+
!6 = !{i32 8, !"PIC Level", i32 2}
28+
!7 = !{i32 7, !"frame-pointer", i32 2}
29+
!8 = !{!"clang version 19.0.0"}
30+
!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)
31+
!10 = !DISubroutineType(types: !11)
32+
!11 = !{}
33+
!12 = !{!13}
34+
!13 = !DILocalVariable(name: "var", scope: !9, file: !1, line: 1, type: !14)
35+
!14 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed)
36+
!15 = !DILocation(line: 1, column: 1, scope: !9)
37+
38+
...
39+
---
40+
name: kern
41+
tracksRegLiveness: true
42+
debugInstrRef: true
43+
stack:
44+
- { id: 0, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4 }
45+
machineFunctionInfo:
46+
scratchRSrcReg: $sgpr0_sgpr1_sgpr2_sgpr3
47+
stackPtrOffsetReg: '$sgpr32'
48+
hasSpilledVGPRs: true
49+
body: |
50+
bb.0:
51+
; CHECK-LABEL: name: kern
52+
; CHECK: frame-setup CFI_INSTRUCTION escape 0x0f, 0x09, 0x90, 0x40, 0x94, 0x04, 0x36, 0x24, 0x36, 0xe9, 0x02
53+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION llvm_register_pair $pc_reg, $sgpr30, 32, $sgpr31, 32
54+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION undefined $vgpr0
55+
; CHECK-NEXT: DBG_INSTR_REF !13, !DIExpression(DIOpArg(0, i32)), dbg-instr-ref(1, 0), debug-location !15
56+
; CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DIOpArg(0, i32)), $noreg, debug-location !15
57+
; CHECK-NEXT: $vgpr0 = V_MOV_B32_e32 0, implicit $exec, debug-instr-number 1, debug-location !15
58+
; CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DIOpArg(0, i32)), $vgpr0, debug-location !15
59+
; 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)
60+
; CHECK-NEXT: S_NOP 0, debug-location !15
61+
; 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)
62+
; CHECK-NEXT: S_ENDPGM 0, debug-location !15
63+
frame-setup CFI_INSTRUCTION escape 0x0f, 0x09, 0x90, 0x40, 0x94, 0x04, 0x36, 0x24, 0x36, 0xe9, 0x02
64+
frame-setup CFI_INSTRUCTION llvm_register_pair $pc_reg, $sgpr30, 32, $sgpr31, 32
65+
frame-setup CFI_INSTRUCTION undefined $vgpr0
66+
DBG_INSTR_REF !13, !DIExpression(DIOpArg(0, i32)), dbg-instr-ref(1, 0), debug-location !15
67+
$vgpr0 = V_MOV_B32_e32 0, implicit $exec, debug-instr-number 1, debug-location !15
68+
SCRATCH_STORE_DWORD_SADDR killed $vgpr0, $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (store (s32) into %stack.0, addrspace 5)
69+
S_NOP 0, debug-location !15
70+
$vgpr0 = SCRATCH_LOAD_DWORD_SADDR $sgpr32, 0, 0, implicit $exec, implicit $flat_scr, debug-location !15 :: (load (s32) from %stack.0, addrspace 5)
71+
S_ENDPGM 0, debug-location !15
72+
73+
...

0 commit comments

Comments
 (0)