LLVM 22.0.0git
AMDGPUArgumentUsageInfo.h
Go to the documentation of this file.
1//==- AMDGPUArgumentrUsageInfo.h - Function Arg Usage Info -------*- C++ -*-==//
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
9#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUARGUMENTUSAGEINFO_H
10#define LLVM_LIB_TARGET_AMDGPU_AMDGPUARGUMENTUSAGEINFO_H
11
13#include "llvm/ADT/DenseMap.h"
15#include "llvm/IR/PassManager.h"
16#include "llvm/Pass.h"
17#include "llvm/PassRegistry.h"
18#include <variant>
19
20namespace llvm {
21
23
24class Function;
25class LLT;
26class raw_ostream;
29
31private:
32 friend struct AMDGPUFunctionArgInfo;
34
35 std::variant<std::monostate, MCRegister, unsigned> Val;
36
37 // Bitmask to locate argument within the register.
38 unsigned Mask;
39
40public:
41 ArgDescriptor(unsigned Mask = ~0u) : Mask(Mask) {}
42
43 static ArgDescriptor createRegister(Register Reg, unsigned Mask = ~0u) {
44 ArgDescriptor Ret(Mask);
45 Ret.Val = Reg.asMCReg();
46 return Ret;
47 }
48
49 static ArgDescriptor createStack(unsigned Offset, unsigned Mask = ~0u) {
50 ArgDescriptor Ret(Mask);
51 Ret.Val = Offset;
52 return Ret;
53 }
54
55 static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask) {
56 // Copy the descriptor, then change the mask.
57 ArgDescriptor Ret(Arg);
58 Ret.Mask = Mask;
59 return Ret;
60 }
61
62 bool isSet() const { return !std::holds_alternative<std::monostate>(Val); }
63
64 explicit operator bool() const {
65 return isSet();
66 }
67
68 bool isRegister() const { return std::holds_alternative<MCRegister>(Val); }
69
70 MCRegister getRegister() const { return std::get<MCRegister>(Val); }
71
72 unsigned getStackOffset() const { return std::get<unsigned>(Val); }
73
74 unsigned getMask() const {
75 // None of the target SGPRs or VGPRs are expected to have a 'zero' mask.
76 assert(Mask && "Invalid mask.");
77 return Mask;
78 }
79
80 bool isMasked() const {
81 return Mask != ~0u;
82 }
83
84 void print(raw_ostream &OS, const TargetRegisterInfo *TRI = nullptr) const;
85};
86
88 Arg.print(OS);
89 return OS;
90}
91
96
98 // clang-format off
129 // clang-format on
130
131 // Kernel input registers setup for the HSA ABI in allocation order.
132
133 // User SGPRs in kernels
134 // XXX - Can these require argument spills?
143
144 // System SGPRs in kernels.
150
151 // Pointer with offset from kernargsegmentptr to where special ABI arguments
152 // are passed to callable functions.
154
155 // Input registers for non-HSA ABI
157
158 // VGPRs inputs. For entry functions these are either v0, v1 and v2 or packed
159 // into v0, 10 bits per dimension if packed-tid is set.
163
164 // Map the index of preloaded kernel arguments to its descriptor.
166 // The first user SGPR allocated for kernarg preloading.
168
169 std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
171
173};
174
176private:
178
179public:
182
183 void print(raw_ostream &OS, const Module *M = nullptr) const;
184
185 void clear() { ArgInfoMap.clear(); }
186
188 ArgInfoMap[&F] = ArgInfo;
189 }
190
192
193 bool invalidate(Module &M, const PreservedAnalyses &PA,
194 ModuleAnalysisManager::Invalidator &Inv);
195};
196
198 std::unique_ptr<AMDGPUArgumentUsageInfo> AUIP;
199
200public:
201 static char ID;
202
207
209 const AMDGPUArgumentUsageInfo &getArgUsageInfo() const { return *AUIP; }
210
211 void getAnalysisUsage(AnalysisUsage &AU) const override {
212 AU.setPreservesAll();
213 }
214
215 bool doInitialization(Module &M) override {
216 AUIP = std::make_unique<AMDGPUArgumentUsageInfo>();
217 return false;
218 }
219
220 bool doFinalization(Module &M) override {
221 AUIP->clear();
222 return false;
223 }
224
225 void print(raw_ostream &OS, const Module *M = nullptr) const override {
226 AUIP->print(OS, M);
227 }
228};
229
231 : public AnalysisInfoMixin<AMDGPUArgumentUsageAnalysis> {
233 static AnalysisKey Key;
234
235public:
237
239};
240
241} // end namespace llvm
242
243#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
Register Reg
Register const TargetRegisterInfo * TRI
AMDGPUArgumentUsageInfo run(Module &M, ModuleAnalysisManager &)
const AMDGPUArgumentUsageInfo & getArgUsageInfo() const
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
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 ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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
void setFuncArgInfo(const Function &F, const AMDGPUFunctionArgInfo &ArgInfo)
bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ImmutablePass(char &pid)
Definition Pass.h:287
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
void initializeAMDGPUArgumentUsageInfoWrapperLegacyPass(PassRegistry &)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
SmallDenseMap< int, KernArgPreloadDescriptor > PreloadKernArgs
static AMDGPUFunctionArgInfo fixedABILayout()
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(PreloadedValue Value) const
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
static ArgDescriptor createStack(unsigned Offset, unsigned Mask=~0u)
MCRegister getRegister() const
static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask)
ArgDescriptor(unsigned Mask=~0u)
void print(raw_ostream &OS, const TargetRegisterInfo *TRI=nullptr) const
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
unsigned getStackOffset() const
Helper struct shared between Function Specialization and SCCP Solver.
Definition SCCPSolver.h:42