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/IR/Function.h"
14 #include "llvm/Pass.h"
22 class TargetRegisterClass
;
23 class TargetRegisterInfo
;
25 struct ArgDescriptor
{
27 friend struct AMDGPUFunctionArgInfo
;
28 friend class AMDGPUArgumentUsageInfo
;
38 ArgDescriptor(unsigned Val
= 0, bool IsStack
= false, bool IsSet
= false)
39 : Register(Val
), IsStack(IsStack
), IsSet(IsSet
) {}
41 static ArgDescriptor
createRegister(unsigned Reg
) {
42 return ArgDescriptor(Reg
, false, true);
45 static ArgDescriptor
createStack(unsigned Reg
) {
46 return ArgDescriptor(Reg
, true, true);
53 explicit operator bool() const {
57 bool isRegister() const {
61 unsigned getRegister() const {
66 unsigned getStackOffset() const {
71 void print(raw_ostream
&OS
, const TargetRegisterInfo
*TRI
= nullptr) const;
74 inline raw_ostream
&operator<<(raw_ostream
&OS
, const ArgDescriptor
&Arg
) {
79 struct AMDGPUFunctionArgInfo
{
82 PRIVATE_SEGMENT_BUFFER
= 0,
85 KERNARG_SEGMENT_PTR
= 3,
87 FLAT_SCRATCH_INIT
= 5,
91 PRIVATE_SEGMENT_WAVE_BYTE_OFFSET
= 14,
92 IMPLICIT_BUFFER_PTR
= 15,
93 IMPLICIT_ARG_PTR
= 16,
99 FIRST_VGPR_VALUE
= WORKITEM_ID_X
102 // Kernel input registers setup for the HSA ABI in allocation order.
104 // User SGPRs in kernels
105 // XXX - Can these require argument spills?
106 ArgDescriptor PrivateSegmentBuffer
;
107 ArgDescriptor DispatchPtr
;
108 ArgDescriptor QueuePtr
;
109 ArgDescriptor KernargSegmentPtr
;
110 ArgDescriptor DispatchID
;
111 ArgDescriptor FlatScratchInit
;
112 ArgDescriptor PrivateSegmentSize
;
114 // System SGPRs in kernels.
115 ArgDescriptor WorkGroupIDX
;
116 ArgDescriptor WorkGroupIDY
;
117 ArgDescriptor WorkGroupIDZ
;
118 ArgDescriptor WorkGroupInfo
;
119 ArgDescriptor PrivateSegmentWaveByteOffset
;
121 // Pointer with offset from kernargsegmentptr to where special ABI arguments
122 // are passed to callable functions.
123 ArgDescriptor ImplicitArgPtr
;
125 // Input registers for non-HSA ABI
126 ArgDescriptor ImplicitBufferPtr
= 0;
128 // VGPRs inputs. These are always v0, v1 and v2 for entry functions.
129 ArgDescriptor WorkItemIDX
;
130 ArgDescriptor WorkItemIDY
;
131 ArgDescriptor WorkItemIDZ
;
133 std::pair
<const ArgDescriptor
*, const TargetRegisterClass
*>
134 getPreloadedValue(PreloadedValue Value
) const;
137 class AMDGPUArgumentUsageInfo
: public ImmutablePass
{
139 static const AMDGPUFunctionArgInfo ExternFunctionInfo
;
140 DenseMap
<const Function
*, AMDGPUFunctionArgInfo
> ArgInfoMap
;
145 AMDGPUArgumentUsageInfo() : ImmutablePass(ID
) { }
147 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
148 AU
.setPreservesAll();
151 bool doInitialization(Module
&M
) override
;
152 bool doFinalization(Module
&M
) override
;
154 void print(raw_ostream
&OS
, const Module
*M
= nullptr) const override
;
156 void setFuncArgInfo(const Function
&F
, const AMDGPUFunctionArgInfo
&ArgInfo
) {
157 ArgInfoMap
[&F
] = ArgInfo
;
160 const AMDGPUFunctionArgInfo
&lookupFuncArgInfo(const Function
&F
) const {
161 auto I
= ArgInfoMap
.find(&F
);
162 if (I
== ArgInfoMap
.end()) {
163 assert(F
.isDeclaration());
164 return ExternFunctionInfo
;
171 } // end namespace llvm