Skip to content

Commit

Permalink
[AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF p…
Browse files Browse the repository at this point in the history
…ass (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
  • Loading branch information
JanekvO authored Sep 30, 2024
1 parent 3c85102 commit c897c13
Show file tree
Hide file tree
Showing 37 changed files with 1,566 additions and 485 deletions.
2 changes: 1 addition & 1 deletion clang/test/Frontend/amdgcn-machine-analysis-remarks.cl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx908 -Rpass-analysis=kernel-resource-usage -S -O0 -verify %s -o /dev/null

// expected-remark@+10 {{Function Name: foo}}
// expected-remark@+9 {{ SGPRs: 13}}
// expected-remark@+9 {{ TotalSGPRs: 13}}
// expected-remark@+8 {{ VGPRs: 10}}
// expected-remark@+7 {{ AGPRs: 12}}
// expected-remark@+6 {{ ScratchSize [bytes/lane]: 0}}
Expand Down
49 changes: 49 additions & 0 deletions llvm/docs/AMDGPUUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,55 @@ As part of the AMDGPU MC layer, AMDGPU provides the following target specific

=================== ================= ========================================================

Function Resource Usage
-----------------------

A function's resource usage depends on each of its callees' resource usage. The
expressions used to denote resource usage reflect this by propagating each
callees' equivalent expressions. Said expressions are emitted as symbols by the
compiler when compiling to either assembly or object format and should not be
overwritten or redefined.

The following describes all emitted function resource usage symbols:

.. table:: Function Resource Usage:
:name: function-usage-table

===================================== ========= ========================================= ===============================================================================
Symbol Type Description Example
===================================== ========= ========================================= ===============================================================================
<function_name>.num_vgpr Integer Number of VGPRs used by <function_name>, .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
worst case of itself and its callees'
VGPR use
<function_name>.num_agpr Integer Number of AGPRs used by <function_name>, .set foo.num_agpr, max(35, bar.num_agpr)
worst case of itself and its callees'
AGPR use
<function_name>.numbered_sgpr Integer Number of SGPRs used by <function_name>, .set foo.num_sgpr, 21
worst case of itself and its callees'
SGPR use (without any of the implicitly
used SGPRs)
<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)
<function_name>, expression is the
locally used stack size + the worst case
callee
<function_name>.uses_vcc Bool Whether <function_name>, or any of its .set foo.uses_vcc, or(0, bar.uses_vcc)
callees, uses vcc
<function_name>.uses_flat_scratch Bool Whether <function_name>, or any of its .set foo.uses_flat_scratch, 1
callees, uses flat scratch or not
<function_name>.has_dyn_sized_stack Bool Whether <function_name>, or any of its .set foo.has_dyn_sized_stack, 1
callees, is dynamically sized
<function_name>.has_recursion Bool Whether <function_name>, or any of its .set foo.has_recursion, 0
callees, contains recursion
<function_name>.has_indirect_call Bool Whether <function_name>, or any of its .set foo.has_indirect_call, max(0, bar.has_indirect_call)
callees, contains an indirect call
===================================== ========= ========================================= ===============================================================================

Futhermore, three symbols are additionally emitted describing the compilation
unit's worst case (i.e, maxima) ``num_vgpr``, ``num_agpr``, and
``numbered_sgpr`` which may be referenced and used by the aforementioned
symbolic expressions. These three symbols are ``amdgcn.max_num_vgpr``,
``amdgcn.max_num_agpr``, and ``amdgcn.max_num_sgpr``.

.. _amdgpu-elf-code-object:

ELF Code Object
Expand Down
Loading

0 comments on commit c897c13

Please sign in to comment.