Skip to content

Commit ee252b6

Browse files
authored
[LiveDebugValues] Disable spill tracking on AMDGPU (llvm#561)
The spill tracking in MLocTracker has quite poor performance on AMDGPU because of the large number of subregister indices. Futhermore, range extension doesn't even work on spills since AMDGPU currently doesn't implement is{LoadFrom,StoreTo}StackSlotPostFE. Disable it for now until we can come up with a better way of handling this. Fixes SWDEV-511880
2 parents 3df8911 + 3bd28c1 commit ee252b6

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
@@ -1122,6 +1131,10 @@ void MLocTracker::writeRegMask(const MachineOperand *MO, unsigned CurBB,
11221131
}
11231132

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

11271140
if (SpillID.id() == 0) {
@@ -3721,6 +3734,15 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
37213734
VTracker = nullptr;
37223735
TTracker = nullptr;
37233736

3737+
if (MTracker->NumSlotIdxes >= StackSlotIdxesLimit) {
3738+
LLVM_DEBUG(
3739+
dbgs() << "Disabling InstrRefBasedLDV spill tracking for "
3740+
<< MF.getName()
3741+
<< " since target has too many potential stack slot indexes ("
3742+
<< MTracker->NumSlotIdxes << ", limit is " << StackSlotIdxesLimit
3743+
<< ")\n");
3744+
}
3745+
37243746
SmallVector<MLocTransferMap, 32> MLocTransfer;
37253747
SmallVector<VLocTracker, 8> vlocs;
37263748
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)