Skip to content

Commit ef906f2

Browse files
committed
AMDGPU: Fix assertion when printing unreachable functions
Since 814a0ab, this would break if we had a function in the module that becomes dead in any codegen IR pass. The function wasn't deleted since it was initially used in dead code, but is detached from the call graph and doesn't appear in the PO traversal. Do a second walk over the module to populate the resources of any functions which weren't already processed.
1 parent a4834ad commit ef906f2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
125125
HasIndirectCall |= Info.HasIndirectCall;
126126
}
127127

128+
// It's possible we have unreachable functions in the module which weren't
129+
// visited by the PO traversal. Make sure we have some resource counts to
130+
// report.
131+
for (const auto &IT : CG) {
132+
const Function *F = IT.first;
133+
if (!F || F->isDeclaration())
134+
continue;
135+
136+
auto CI = CallGraphResourceInfo.insert(
137+
std::make_pair(F, SIFunctionResourceInfo()));
138+
if (!CI.second) // Skip already visited functions
139+
continue;
140+
141+
SIFunctionResourceInfo &Info = CI.first->second;
142+
MachineFunction *MF = MMI.getMachineFunction(*F);
143+
assert(MF && "function must have been generated already");
144+
Info = analyzeResourceUsage(*MF, TM);
145+
HasIndirectCall |= Info.HasIndirectCall;
146+
}
147+
128148
if (HasIndirectCall)
129149
propagateIndirectCallRegisterUsage();
130150

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -o - %s | FileCheck -check-prefix=GCN %s
2+
3+
; Make sure there's no assertion when trying to report the resource
4+
; usage for a function which becomes dead during codegen.
5+
6+
@gv.fptr0 = external hidden unnamed_addr addrspace(4) constant void()*, align 4
7+
8+
; GCN-LABEL: unreachable:
9+
; Function info:
10+
; codeLenInByte = 4
11+
define internal fastcc void @unreachable() {
12+
%fptr = load void()*, void()* addrspace(4)* @gv.fptr0
13+
call void %fptr()
14+
unreachable
15+
}
16+
17+
18+
; GCN-LABEL: entry:
19+
; GCN-NOT: s_swappc_b64
20+
; GCN: s_endpgm
21+
22+
; GCN: .amdhsa_private_segment_fixed_size 0
23+
; GCN: .amdhsa_uses_dynamic_stack 0
24+
define amdgpu_kernel void @entry() {
25+
bb0:
26+
br i1 false, label %bb1, label %bb2
27+
28+
bb1:
29+
tail call fastcc void @unreachable()
30+
unreachable
31+
32+
bb2:
33+
ret void
34+
}

0 commit comments

Comments
 (0)