1 //==- AMDGPUArgumentrUsageInfo.h - Function Arg Usage Info -------*- C++ -*-==//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUARGUMENTUSAGEINFO_H
10 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUARGUMENTUSAGEINFO_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/CodeGen/Register.h"
14 #include "llvm/Pass.h"
21 class TargetRegisterClass
;
22 class TargetRegisterInfo
;
24 struct ArgDescriptor
{
26 friend struct AMDGPUFunctionArgInfo
;
27 friend class AMDGPUArgumentUsageInfo
;
34 // Bitmask to locate argument within the register.
41 ArgDescriptor(unsigned Val
= 0, unsigned Mask
= ~0u, bool IsStack
= false,
43 : Reg(Val
), Mask(Mask
), IsStack(IsStack
), IsSet(IsSet
) {}
45 static ArgDescriptor
createRegister(Register Reg
, unsigned Mask
= ~0u) {
46 return ArgDescriptor(Reg
, Mask
, false, true);
49 static ArgDescriptor
createStack(unsigned Offset
, unsigned Mask
= ~0u) {
50 return ArgDescriptor(Offset
, Mask
, true, true);
53 static ArgDescriptor
createArg(const ArgDescriptor
&Arg
, unsigned Mask
) {
54 return ArgDescriptor(Arg
.Reg
, Mask
, Arg
.IsStack
, Arg
.IsSet
);
61 explicit operator bool() const {
65 bool isRegister() const {
69 MCRegister
getRegister() const {
74 unsigned getStackOffset() const {
79 unsigned getMask() const {
83 bool isMasked() const {
87 void print(raw_ostream
&OS
, const TargetRegisterInfo
*TRI
= nullptr) const;
90 inline raw_ostream
&operator<<(raw_ostream
&OS
, const ArgDescriptor
&Arg
) {
95 struct KernArgPreloadDescriptor
: public ArgDescriptor
{
96 KernArgPreloadDescriptor() {}
97 SmallVector
<MCRegister
> Regs
;
100 struct AMDGPUFunctionArgInfo
{
102 enum PreloadedValue
{
104 PRIVATE_SEGMENT_BUFFER
= 0,
107 KERNARG_SEGMENT_PTR
= 3,
109 FLAT_SCRATCH_INIT
= 5,
110 LDS_KERNEL_ID
= 6, // LLVM internal, not part of the ABI
114 PRIVATE_SEGMENT_WAVE_BYTE_OFFSET
= 14,
115 IMPLICIT_BUFFER_PTR
= 15,
116 IMPLICIT_ARG_PTR
= 16,
117 PRIVATE_SEGMENT_SIZE
= 17,
123 FIRST_VGPR_VALUE
= WORKITEM_ID_X
127 // Kernel input registers setup for the HSA ABI in allocation order.
129 // User SGPRs in kernels
130 // XXX - Can these require argument spills?
131 ArgDescriptor PrivateSegmentBuffer
;
132 ArgDescriptor DispatchPtr
;
133 ArgDescriptor QueuePtr
;
134 ArgDescriptor KernargSegmentPtr
;
135 ArgDescriptor DispatchID
;
136 ArgDescriptor FlatScratchInit
;
137 ArgDescriptor PrivateSegmentSize
;
138 ArgDescriptor LDSKernelId
;
140 // System SGPRs in kernels.
141 ArgDescriptor WorkGroupIDX
;
142 ArgDescriptor WorkGroupIDY
;
143 ArgDescriptor WorkGroupIDZ
;
144 ArgDescriptor WorkGroupInfo
;
145 ArgDescriptor PrivateSegmentWaveByteOffset
;
147 // Pointer with offset from kernargsegmentptr to where special ABI arguments
148 // are passed to callable functions.
149 ArgDescriptor ImplicitArgPtr
;
151 // Input registers for non-HSA ABI
152 ArgDescriptor ImplicitBufferPtr
;
154 // VGPRs inputs. For entry functions these are either v0, v1 and v2 or packed
155 // into v0, 10 bits per dimension if packed-tid is set.
156 ArgDescriptor WorkItemIDX
;
157 ArgDescriptor WorkItemIDY
;
158 ArgDescriptor WorkItemIDZ
;
160 // Map the index of preloaded kernel arguments to its descriptor.
161 SmallDenseMap
<int, KernArgPreloadDescriptor
> PreloadKernArgs
{};
163 std::tuple
<const ArgDescriptor
*, const TargetRegisterClass
*, LLT
>
164 getPreloadedValue(PreloadedValue Value
) const;
166 static AMDGPUFunctionArgInfo
fixedABILayout();
169 class AMDGPUArgumentUsageInfo
: public ImmutablePass
{
171 DenseMap
<const Function
*, AMDGPUFunctionArgInfo
> ArgInfoMap
;
176 static const AMDGPUFunctionArgInfo ExternFunctionInfo
;
177 static const AMDGPUFunctionArgInfo FixedABIFunctionInfo
;
179 AMDGPUArgumentUsageInfo() : ImmutablePass(ID
) { }
181 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
182 AU
.setPreservesAll();
185 bool doInitialization(Module
&M
) override
;
186 bool doFinalization(Module
&M
) override
;
188 void print(raw_ostream
&OS
, const Module
*M
= nullptr) const override
;
190 void setFuncArgInfo(const Function
&F
, const AMDGPUFunctionArgInfo
&ArgInfo
) {
191 ArgInfoMap
[&F
] = ArgInfo
;
194 const AMDGPUFunctionArgInfo
&lookupFuncArgInfo(const Function
&F
) const;
197 } // end namespace llvm