LLVM 20.0.0git
AMDGPUArgumentUsageInfo.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10#include "AMDGPU.h"
12#include "SIRegisterInfo.h"
14#include "llvm/IR/Function.h"
17
18using namespace llvm;
19
20#define DEBUG_TYPE "amdgpu-argument-reg-usage-info"
21
23 "Argument Register Usage Information Storage", false, true)
24
27 if (!isSet()) {
28 OS << "<not set>\n";
29 return;
30 }
31
32 if (isRegister())
33 OS << "Reg " << printReg(getRegister(), TRI);
34 else
35 OS << "Stack offset " << getStackOffset();
36
37 if (isMasked()) {
38 OS << " & ";
40 }
41
42 OS << '\n';
43}
44
46
48
49// Hardcoded registers from fixed function ABI
52
54 return false;
55}
56
58 ArgInfoMap.clear();
59 return false;
60}
61
62// TODO: Print preload kernargs?
64 for (const auto &FI : ArgInfoMap) {
65 OS << "Arguments for " << FI.first->getName() << '\n'
66 << " PrivateSegmentBuffer: " << FI.second.PrivateSegmentBuffer
67 << " DispatchPtr: " << FI.second.DispatchPtr
68 << " QueuePtr: " << FI.second.QueuePtr
69 << " KernargSegmentPtr: " << FI.second.KernargSegmentPtr
70 << " DispatchID: " << FI.second.DispatchID
71 << " FlatScratchInit: " << FI.second.FlatScratchInit
72 << " PrivateSegmentSize: " << FI.second.PrivateSegmentSize
73 << " WorkGroupIDX: " << FI.second.WorkGroupIDX
74 << " WorkGroupIDY: " << FI.second.WorkGroupIDY
75 << " WorkGroupIDZ: " << FI.second.WorkGroupIDZ
76 << " WorkGroupInfo: " << FI.second.WorkGroupInfo
77 << " LDSKernelId: " << FI.second.LDSKernelId
78 << " PrivateSegmentWaveByteOffset: "
79 << FI.second.PrivateSegmentWaveByteOffset
80 << " ImplicitBufferPtr: " << FI.second.ImplicitBufferPtr
81 << " ImplicitArgPtr: " << FI.second.ImplicitArgPtr
82 << " WorkItemIDX " << FI.second.WorkItemIDX
83 << " WorkItemIDY " << FI.second.WorkItemIDY
84 << " WorkItemIDZ " << FI.second.WorkItemIDZ
85 << '\n';
86 }
87}
88
89std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
92 switch (Value) {
94 return std::tuple(PrivateSegmentBuffer ? &PrivateSegmentBuffer : nullptr,
95 &AMDGPU::SGPR_128RegClass, LLT::fixed_vector(4, 32));
96 }
98 return std::tuple(ImplicitBufferPtr ? &ImplicitBufferPtr : nullptr,
99 &AMDGPU::SGPR_64RegClass,
102 return std::tuple(WorkGroupIDX ? &WorkGroupIDX : nullptr,
103 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
105 return std::tuple(WorkGroupIDY ? &WorkGroupIDY : nullptr,
106 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
108 return std::tuple(WorkGroupIDZ ? &WorkGroupIDZ : nullptr,
109 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
111 return std::tuple(LDSKernelId ? &LDSKernelId : nullptr,
112 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
114 return std::tuple(
116 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
118 return {PrivateSegmentSize ? &PrivateSegmentSize : nullptr,
119 &AMDGPU::SGPR_32RegClass, LLT::scalar(32)};
121 return std::tuple(KernargSegmentPtr ? &KernargSegmentPtr : nullptr,
122 &AMDGPU::SGPR_64RegClass,
125 return std::tuple(ImplicitArgPtr ? &ImplicitArgPtr : nullptr,
126 &AMDGPU::SGPR_64RegClass,
129 return std::tuple(DispatchID ? &DispatchID : nullptr,
130 &AMDGPU::SGPR_64RegClass, LLT::scalar(64));
132 return std::tuple(FlatScratchInit ? &FlatScratchInit : nullptr,
133 &AMDGPU::SGPR_64RegClass, LLT::scalar(64));
135 return std::tuple(DispatchPtr ? &DispatchPtr : nullptr,
136 &AMDGPU::SGPR_64RegClass,
139 return std::tuple(QueuePtr ? &QueuePtr : nullptr, &AMDGPU::SGPR_64RegClass,
142 return std::tuple(WorkItemIDX ? &WorkItemIDX : nullptr,
143 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
145 return std::tuple(WorkItemIDY ? &WorkItemIDY : nullptr,
146 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
148 return std::tuple(WorkItemIDZ ? &WorkItemIDZ : nullptr,
149 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
150 }
151 llvm_unreachable("unexpected preloaded value type");
152}
153
157 = ArgDescriptor::createRegister(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3);
158 AI.DispatchPtr = ArgDescriptor::createRegister(AMDGPU::SGPR4_SGPR5);
159 AI.QueuePtr = ArgDescriptor::createRegister(AMDGPU::SGPR6_SGPR7);
160
161 // Do not pass kernarg segment pointer, only pass increment version in its
162 // place.
163 AI.ImplicitArgPtr = ArgDescriptor::createRegister(AMDGPU::SGPR8_SGPR9);
164 AI.DispatchID = ArgDescriptor::createRegister(AMDGPU::SGPR10_SGPR11);
165
166 // Skip FlatScratchInit/PrivateSegmentSize
167 AI.WorkGroupIDX = ArgDescriptor::createRegister(AMDGPU::SGPR12);
168 AI.WorkGroupIDY = ArgDescriptor::createRegister(AMDGPU::SGPR13);
169 AI.WorkGroupIDZ = ArgDescriptor::createRegister(AMDGPU::SGPR14);
170 AI.LDSKernelId = ArgDescriptor::createRegister(AMDGPU::SGPR15);
171
172 const unsigned Mask = 0x3ff;
173 AI.WorkItemIDX = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask);
174 AI.WorkItemIDY = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 10);
175 AI.WorkItemIDZ = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 20);
176 return AI;
177}
178
181 auto I = ArgInfoMap.find(&F);
182 if (I == ArgInfoMap.end())
184 return I->second;
185}
static StackOffset getStackOffset(const MachineFunction &MF, int64_t ObjectOffset)
aarch64 promote const
#define DEBUG_TYPE
Provides AMDGPU specific target descriptions.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
Interface definition for SIRegisterInfo.
raw_pwrite_stream & OS
static const AMDGPUFunctionArgInfo ExternFunctionInfo
static const AMDGPUFunctionArgInfo FixedABIFunctionInfo
const AMDGPUFunctionArgInfo & lookupFuncArgInfo(const Function &F) const
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:42
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
Definition: LowLevelType.h:57
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
Definition: LowLevelType.h:100
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static AMDGPUFunctionArgInfo fixedABILayout()
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(PreloadedValue Value) const
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)