Skip to content

Commit 358581c

Browse files
committed
[AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (llvm#102913)
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 [AMDGPU] Fix stack size metadata for functions with direct and indirect calls (llvm#110828) When a function has an external call, it should still use the stack sizes of direct, known, calls to calculate its own stack size [AMDGPU] Fix resource usage information for unnamed functions (llvm#115320) Resource usage information would try to overwrite unnamed functions if there are multiple within the same compilation unit. This aims to either use the `MCSymbol` assigned to the unnamed function (i.e., `CurrentFnSym`), or, rematerialize the `MCSymbol` for the unnamed function. Reapply [AMDGPU] Avoid resource propagation for recursion through multiple functions (llvm#112251) I was wrong last patch. I viewed the `Visited` set purely as a possible recursion deterrent where functions calling a callee multiple times are handled elsewhere. This doesn't consider cases where a function is called multiple times by different callers still part of the same call graph. New test shows the aforementioned case. Reapplies llvm#111004, fixes llvm#115562. [AMDGPU] Newly added test modified for recent SGPR use change (llvm#116427) Mistimed rebase for llvm#112251 which added new tests which did not consider the changes introduced in llvm#112403 yet Change-Id: I4dfe6a1b679137e080a6d2b44016347ea704b014
1 parent 55f7329 commit 358581c

39 files changed

+900
-437
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
@@ -1818,6 +1818,55 @@ As part of the AMDGPU MC layer, AMDGPU provides the following target specific
18181818

18191819
=================== ================= ========================================================
18201820

1821+
Function Resource Usage
1822+
-----------------------
1823+
1824+
A function's resource usage depends on each of its callees' resource usage. The
1825+
expressions used to denote resource usage reflect this by propagating each
1826+
callees' equivalent expressions. Said expressions are emitted as symbols by the
1827+
compiler when compiling to either assembly or object format and should not be
1828+
overwritten or redefined.
1829+
1830+
The following describes all emitted function resource usage symbols:
1831+
1832+
.. table:: Function Resource Usage:
1833+
:name: function-usage-table
1834+
1835+
===================================== ========= ========================================= ===============================================================================
1836+
Symbol Type Description Example
1837+
===================================== ========= ========================================= ===============================================================================
1838+
<function_name>.num_vgpr Integer Number of VGPRs used by <function_name>, .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
1839+
worst case of itself and its callees'
1840+
VGPR use
1841+
<function_name>.num_agpr Integer Number of AGPRs used by <function_name>, .set foo.num_agpr, max(35, bar.num_agpr)
1842+
worst case of itself and its callees'
1843+
AGPR use
1844+
<function_name>.numbered_sgpr Integer Number of SGPRs used by <function_name>, .set foo.num_sgpr, 21
1845+
worst case of itself and its callees'
1846+
SGPR use (without any of the implicitly
1847+
used SGPRs)
1848+
<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)
1849+
<function_name>, expression is the
1850+
locally used stack size + the worst case
1851+
callee
1852+
<function_name>.uses_vcc Bool Whether <function_name>, or any of its .set foo.uses_vcc, or(0, bar.uses_vcc)
1853+
callees, uses vcc
1854+
<function_name>.uses_flat_scratch Bool Whether <function_name>, or any of its .set foo.uses_flat_scratch, 1
1855+
callees, uses flat scratch or not
1856+
<function_name>.has_dyn_sized_stack Bool Whether <function_name>, or any of its .set foo.has_dyn_sized_stack, 1
1857+
callees, is dynamically sized
1858+
<function_name>.has_recursion Bool Whether <function_name>, or any of its .set foo.has_recursion, 0
1859+
callees, contains recursion
1860+
<function_name>.has_indirect_call Bool Whether <function_name>, or any of its .set foo.has_indirect_call, max(0, bar.has_indirect_call)
1861+
callees, contains an indirect call
1862+
===================================== ========= ========================================= ===============================================================================
1863+
1864+
Futhermore, three symbols are additionally emitted describing the compilation
1865+
unit's worst case (i.e, maxima) ``num_vgpr``, ``num_agpr``, and
1866+
``numbered_sgpr`` which may be referenced and used by the aforementioned
1867+
symbolic expressions. These three symbols are ``amdgcn.max_num_vgpr``,
1868+
``amdgcn.max_num_agpr``, and ``amdgcn.max_num_sgpr``.
1869+
18211870
.. _amdgpu-elf-code-object:
18221871

18231872
ELF Code Object

0 commit comments

Comments
 (0)