27 #define DEBUG_TYPE "amdgpu-lower-kernel-attributes" 44 class AMDGPULowerKernelAttributes :
public ModulePass {
50 AMDGPULowerKernelAttributes() :
ModulePass(ID) {}
54 bool doInitialization(
Module &M)
override;
55 bool runOnModule(
Module &M)
override;
58 return "AMDGPU Kernel Attributes";
68 bool AMDGPULowerKernelAttributes::doInitialization(
Module &M) {
73 bool AMDGPULowerKernelAttributes::processUse(
CallInst *CI) {
79 const bool HasUniformWorkGroupSize =
82 if (!HasReqdWorkGroupSize && !HasUniformWorkGroupSize)
85 Value *WorkGroupSizeX =
nullptr;
86 Value *WorkGroupSizeY =
nullptr;
87 Value *WorkGroupSizeZ =
nullptr;
89 Value *GridSizeX =
nullptr;
90 Value *GridSizeY =
nullptr;
91 Value *GridSizeZ =
nullptr;
106 if (!BCI || !BCI->hasOneUse())
117 case WORKGROUP_SIZE_X:
119 WorkGroupSizeX =
Load;
121 case WORKGROUP_SIZE_Y:
123 WorkGroupSizeY =
Load;
125 case WORKGROUP_SIZE_Z:
127 WorkGroupSizeZ =
Load;
166 bool MadeChange =
false;
167 Value *WorkGroupSizes[3] = { WorkGroupSizeX, WorkGroupSizeY, WorkGroupSizeZ };
168 Value *GridSizes[3] = { GridSizeX, GridSizeY, GridSizeZ };
170 for (
int I = 0; HasUniformWorkGroupSize &&
I < 3; ++
I) {
171 Value *GroupSize = WorkGroupSizes[
I];
172 Value *GridSize = GridSizes[
I];
173 if (!GroupSize || !GridSize)
181 for (
User *ZextUser : ZextGroupSize->
users()) {
187 auto GroupIDIntrin = I == 0 ?
188 m_Intrinsic<Intrinsic::amdgcn_workgroup_id_x>() :
189 (I == 1 ? m_Intrinsic<Intrinsic::amdgcn_workgroup_id_y>() :
190 m_Intrinsic<Intrinsic::amdgcn_workgroup_id_z>());
201 if (HasReqdWorkGroupSize) {
203 = mdconst::extract<ConstantInt>(MD->getOperand(I));
208 SI->replaceAllUsesWith(ZextGroupSize);
217 if (!HasReqdWorkGroupSize)
221 for (
int I = 0; I < 3; ++
I) {
222 Value *GroupSize = WorkGroupSizes[
I];
226 ConstantInt *KnownSize = mdconst::extract<ConstantInt>(MD->getOperand(I));
239 bool AMDGPULowerKernelAttributes::runOnModule(
Module &M) {
243 Function *DispatchPtr =
Mod->getFunction(DispatchPtrName);
247 bool MadeChange =
false;
250 for (
auto *U : DispatchPtr->
users()) {
252 if (HandledUses.
insert(CI).second) {
262 "AMDGPU IR optimizations",
false,
false)
266 char AMDGPULowerKernelAttributes::
ID = 0;
269 return new AMDGPULowerKernelAttributes();
A parsed version of the target data layout string in and methods for querying it. ...
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
This class represents zero extension of integer types.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
This class represents a function call, abstracting a target machine's calling convention.
ModulePass * createAMDGPULowerKernelAttributesPass()
An instruction for reading from memory.
bool match(Val *V, const Pattern &P)
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
This class represents the LLVM 'select' instruction.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Type * getType() const
All values are typed, get the type of this value.
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
This class represents a no-op cast from one type to another.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Represent the analysis usage information of a pass.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
The AMDGPU TargetMachine interface definition for hw codgen targets.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This is the shared class of boolean and integer constants.
The access may modify the value stored in memory.
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< user_iterator > users()
StringRef getValueAsString() const
Return the attribute's value as a string.
const Function * getParent() const
Return the enclosing method, or null if none.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
LLVM Value Representation.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
INITIALIZE_PASS_BEGIN(AMDGPULowerKernelAttributes, DEBUG_TYPE, "AMDGPU IR optimizations", false, false) INITIALIZE_PASS_END(AMDGPULowerKernelAttributes
StringRef - Represent a constant reference to a string, i.e.
unsigned getNumOperands() const
Return number of MDNode operands.
Statically lint checks LLVM IR
const BasicBlock * getParent() const
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)