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"
11#include "AMDGPUTargetMachine.h"
13#include "SIRegisterInfo.h"
15#include "llvm/IR/Function.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "amdgpu-argument-reg-usage-info"
22
24 "Argument Register Usage Information Storage", false, true)
25
28 if (!isSet()) {
29 OS << "<not set>\n";
30 return;
31 }
32
33 if (isRegister())
34 OS << "Reg " << printReg(getRegister(), TRI);
35 else
36 OS << "Stack offset " << getStackOffset();
37
38 if (isMasked()) {
39 OS << " & ";
41 }
42
43 OS << '\n';
44}
45
47
49
50// Hardcoded registers from fixed function ABI
53
55 return false;
56}
57
59 ArgInfoMap.clear();
60 return false;
61}
62
63// TODO: Print preload kernargs?
65 for (const auto &FI : ArgInfoMap) {
66 OS << "Arguments for " << FI.first->getName() << '\n'
67 << " PrivateSegmentBuffer: " << FI.second.PrivateSegmentBuffer
68 << " DispatchPtr: " << FI.second.DispatchPtr
69 << " QueuePtr: " << FI.second.QueuePtr
70 << " KernargSegmentPtr: " << FI.second.KernargSegmentPtr
71 << " DispatchID: " << FI.second.DispatchID
72 << " FlatScratchInit: " << FI.second.FlatScratchInit
73 << " PrivateSegmentSize: " << FI.second.PrivateSegmentSize
74 << " WorkGroupIDX: " << FI.second.WorkGroupIDX
75 << " WorkGroupIDY: " << FI.second.WorkGroupIDY
76 << " WorkGroupIDZ: " << FI.second.WorkGroupIDZ
77 << " WorkGroupInfo: " << FI.second.WorkGroupInfo
78 << " LDSKernelId: " << FI.second.LDSKernelId
79 << " PrivateSegmentWaveByteOffset: "
80 << FI.second.PrivateSegmentWaveByteOffset
81 << " ImplicitBufferPtr: " << FI.second.ImplicitBufferPtr
82 << " ImplicitArgPtr: " << FI.second.ImplicitArgPtr
83 << " WorkItemIDX " << FI.second.WorkItemIDX
84 << " WorkItemIDY " << FI.second.WorkItemIDY
85 << " WorkItemIDZ " << FI.second.WorkItemIDZ
86 << '\n';
87 }
88}
89
90std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
93 switch (Value) {
95 return std::tuple(PrivateSegmentBuffer ? &PrivateSegmentBuffer : nullptr,
96 &AMDGPU::SGPR_128RegClass, LLT::fixed_vector(4, 32));
97 }
99 return std::tuple(ImplicitBufferPtr ? &ImplicitBufferPtr : nullptr,
100 &AMDGPU::SGPR_64RegClass,
103 return std::tuple(WorkGroupIDX ? &WorkGroupIDX : nullptr,
104 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
106 return std::tuple(WorkGroupIDY ? &WorkGroupIDY : nullptr,
107 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
109 return std::tuple(WorkGroupIDZ ? &WorkGroupIDZ : nullptr,
110 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
112 return std::tuple(LDSKernelId ? &LDSKernelId : nullptr,
113 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
115 return std::tuple(
117 &AMDGPU::SGPR_32RegClass, LLT::scalar(32));
119 return {PrivateSegmentSize ? &PrivateSegmentSize : nullptr,
120 &AMDGPU::SGPR_32RegClass, LLT::scalar(32)};
122 return std::tuple(KernargSegmentPtr ? &KernargSegmentPtr : nullptr,
123 &AMDGPU::SGPR_64RegClass,
126 return std::tuple(ImplicitArgPtr ? &ImplicitArgPtr : nullptr,
127 &AMDGPU::SGPR_64RegClass,
130 return std::tuple(DispatchID ? &DispatchID : nullptr,
131 &AMDGPU::SGPR_64RegClass, LLT::scalar(64));
133 return std::tuple(FlatScratchInit ? &FlatScratchInit : nullptr,
134 &AMDGPU::SGPR_64RegClass, LLT::scalar(64));
136 return std::tuple(DispatchPtr ? &DispatchPtr : nullptr,
137 &AMDGPU::SGPR_64RegClass,
140 return std::tuple(QueuePtr ? &QueuePtr : nullptr, &AMDGPU::SGPR_64RegClass,
143 return std::tuple(WorkItemIDX ? &WorkItemIDX : nullptr,
144 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
146 return std::tuple(WorkItemIDY ? &WorkItemIDY : nullptr,
147 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
149 return std::tuple(WorkItemIDZ ? &WorkItemIDZ : nullptr,
150 &AMDGPU::VGPR_32RegClass, LLT::scalar(32));
151 }
152 llvm_unreachable("unexpected preloaded value type");
153}
154
158 = ArgDescriptor::createRegister(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3);
159 AI.DispatchPtr = ArgDescriptor::createRegister(AMDGPU::SGPR4_SGPR5);
160 AI.QueuePtr = ArgDescriptor::createRegister(AMDGPU::SGPR6_SGPR7);
161
162 // Do not pass kernarg segment pointer, only pass increment version in its
163 // place.
164 AI.ImplicitArgPtr = ArgDescriptor::createRegister(AMDGPU::SGPR8_SGPR9);
165 AI.DispatchID = ArgDescriptor::createRegister(AMDGPU::SGPR10_SGPR11);
166
167 // Skip FlatScratchInit/PrivateSegmentSize
168 AI.WorkGroupIDX = ArgDescriptor::createRegister(AMDGPU::SGPR12);
169 AI.WorkGroupIDY = ArgDescriptor::createRegister(AMDGPU::SGPR13);
170 AI.WorkGroupIDZ = ArgDescriptor::createRegister(AMDGPU::SGPR14);
171 AI.LDSKernelId = ArgDescriptor::createRegister(AMDGPU::SGPR15);
172
173 const unsigned Mask = 0x3ff;
174 AI.WorkItemIDX = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask);
175 AI.WorkItemIDY = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 10);
176 AI.WorkItemIDZ = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 20);
177 return AI;
178}
179
182 auto I = ArgInfoMap.find(&F);
183 if (I == ArgInfoMap.end())
185 return I->second;
186}
static StackOffset getStackOffset(const MachineFunction &MF, int64_t ObjectOffset)
aarch64 promote const
#define DEBUG_TYPE
Provides AMDGPU specific target descriptions.
The AMDGPU TargetMachine interface definition for hw codegen targets.
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)