Skip to content

Commit 2d8aab2

Browse files
JanekvOronlieb
authored andcommitted
[AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (llvm#102913)
Reland: Converts AMDGPUResourceUsageAnalysis pass from Module to MachineFunction pass. Moves function resource info propagation to to MC layer (through helpers in AMDGPUMCResourceInfo) by generating MCExprs for every function resource which the emitters have been prepped for. Fixes llvm#64863 Change-Id: I180c941a1535be646144960ff62e4cf24a5aa1da
1 parent 5e95e34 commit 2d8aab2

35 files changed

+1377
-423
lines changed

clang/test/Frontend/amdgcn-machine-analysis-remarks.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx908 -Rpass-analysis=kernel-resource-usage -S -O0 -verify %s -o /dev/null
33

44
// expected-remark@+10 {{Function Name: foo}}
5-
// expected-remark@+9 {{ SGPRs: 13}}
5+
// expected-remark@+9 {{ TotalSGPRs: 13}}
66
// expected-remark@+8 {{ VGPRs: 10}}
77
// expected-remark@+7 {{ AGPRs: 12}}
88
// expected-remark@+6 {{ ScratchSize [bytes/lane]: 0}}

llvm/docs/AMDGPUUsage.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,55 @@ As part of the AMDGPU MC layer, AMDGPU provides the following target specific
17581758

17591759
=================== ================= ========================================================
17601760

1761+
Function Resource Usage
1762+
-----------------------
1763+
1764+
A function's resource usage depends on each of its callees' resource usage. The
1765+
expressions used to denote resource usage reflect this by propagating each
1766+
callees' equivalent expressions. Said expressions are emitted as symbols by the
1767+
compiler when compiling to either assembly or object format and should not be
1768+
overwritten or redefined.
1769+
1770+
The following describes all emitted function resource usage symbols:
1771+
1772+
.. table:: Function Resource Usage:
1773+
:name: function-usage-table
1774+
1775+
===================================== ========= ========================================= ===============================================================================
1776+
Symbol Type Description Example
1777+
===================================== ========= ========================================= ===============================================================================
1778+
<function_name>.num_vgpr Integer Number of VGPRs used by <function_name>, .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
1779+
worst case of itself and its callees'
1780+
VGPR use
1781+
<function_name>.num_agpr Integer Number of AGPRs used by <function_name>, .set foo.num_agpr, max(35, bar.num_agpr)
1782+
worst case of itself and its callees'
1783+
AGPR use
1784+
<function_name>.numbered_sgpr Integer Number of SGPRs used by <function_name>, .set foo.num_sgpr, 21
1785+
worst case of itself and its callees'
1786+
SGPR use (without any of the implicitly
1787+
used SGPRs)
1788+
<function_name>.private_seg_size Integer Total stack size required for .set foo.private_seg_size, 16+max(bar.private_seg_size, baz.private_seg_size)
1789+
<function_name>, expression is the
1790+
locally used stack size + the worst case
1791+
callee
1792+
<function_name>.uses_vcc Bool Whether <function_name>, or any of its .set foo.uses_vcc, or(0, bar.uses_vcc)
1793+
callees, uses vcc
1794+
<function_name>.uses_flat_scratch Bool Whether <function_name>, or any of its .set foo.uses_flat_scratch, 1
1795+
callees, uses flat scratch or not
1796+
<function_name>.has_dyn_sized_stack Bool Whether <function_name>, or any of its .set foo.has_dyn_sized_stack, 1
1797+
callees, is dynamically sized
1798+
<function_name>.has_recursion Bool Whether <function_name>, or any of its .set foo.has_recursion, 0
1799+
callees, contains recursion
1800+
<function_name>.has_indirect_call Bool Whether <function_name>, or any of its .set foo.has_indirect_call, max(0, bar.has_indirect_call)
1801+
callees, contains an indirect call
1802+
===================================== ========= ========================================= ===============================================================================
1803+
1804+
Futhermore, three symbols are additionally emitted describing the compilation
1805+
unit's worst case (i.e, maxima) ``num_vgpr``, ``num_agpr``, and
1806+
``numbered_sgpr`` which may be referenced and used by the aforementioned
1807+
symbolic expressions. These three symbols are ``amdgcn.max_num_vgpr``,
1808+
``amdgcn.max_num_agpr``, and ``amdgcn.max_num_sgpr``.
1809+
17611810
.. _amdgpu-elf-code-object:
17621811

17631812
ELF Code Object

0 commit comments

Comments
 (0)