40 #define DEBUG_TYPE "amdgpu-annotate-kernel-features" 58 bool doInitialization(
CallGraph &CG)
override;
62 return "AMDGPU Annotate Kernel Features";
71 static bool visitConstantExprsRecursively(
84 "Add AMDGPU function attributes",
false,
false)
89 return SrcAS == AS.LOCAL_ADDRESS || SrcAS == AS.PRIVATE_ADDRESS;
97 bool AMDGPUAnnotateKernelFeatures::visitConstantExpr(
const ConstantExpr *CE,
99 if (CE->
getOpcode() == Instruction::AddrSpaceCast) {
107 bool AMDGPUAnnotateKernelFeatures::visitConstantExprsRecursively(
112 if (!ConstantExprVisited.
insert(EntryC).second)
118 while (!Stack.
empty()) {
122 if (
const auto *CE = dyn_cast<ConstantExpr>(C)) {
123 if (visitConstantExpr(CE, AS))
133 if (!ConstantExprVisited.
insert(OpC).second)
152 case Intrinsic::amdgcn_workitem_id_x:
153 NonKernelOnly =
true;
154 return "amdgpu-work-item-id-x";
155 case Intrinsic::amdgcn_workgroup_id_x:
156 NonKernelOnly =
true;
157 return "amdgpu-work-group-id-x";
158 case Intrinsic::amdgcn_workitem_id_y:
159 case Intrinsic::r600_read_tidig_y:
160 return "amdgpu-work-item-id-y";
161 case Intrinsic::amdgcn_workitem_id_z:
162 case Intrinsic::r600_read_tidig_z:
163 return "amdgpu-work-item-id-z";
164 case Intrinsic::amdgcn_workgroup_id_y:
165 case Intrinsic::r600_read_tgid_y:
166 return "amdgpu-work-group-id-y";
167 case Intrinsic::amdgcn_workgroup_id_z:
168 case Intrinsic::r600_read_tgid_z:
169 return "amdgpu-work-group-id-z";
170 case Intrinsic::amdgcn_dispatch_ptr:
171 return "amdgpu-dispatch-ptr";
172 case Intrinsic::amdgcn_dispatch_id:
173 return "amdgpu-dispatch-id";
174 case Intrinsic::amdgcn_kernarg_segment_ptr:
175 return "amdgpu-kernarg-segment-ptr";
176 case Intrinsic::amdgcn_implicitarg_ptr:
177 return "amdgpu-implicitarg-ptr";
178 case Intrinsic::amdgcn_queue_ptr:
179 case Intrinsic::trap:
180 case Intrinsic::debugtrap:
182 return "amdgpu-queue-ptr";
199 bool &NeedQueuePtr) {
202 {
"amdgpu-work-item-id-x" },
203 {
"amdgpu-work-item-id-y" },
204 {
"amdgpu-work-item-id-z" },
205 {
"amdgpu-work-group-id-x" },
206 {
"amdgpu-work-group-id-y" },
207 {
"amdgpu-work-group-id-z" },
208 {
"amdgpu-dispatch-ptr" },
209 {
"amdgpu-dispatch-id" },
210 {
"amdgpu-kernarg-segment-ptr" },
211 {
"amdgpu-implicitarg-ptr" }
214 if (
handleAttr(Parent, Callee,
"amdgpu-queue-ptr"))
221 bool AMDGPUAnnotateKernelFeatures::addFeatureAttributes(
Function &
F) {
227 bool Changed =
false;
228 bool NeedQueuePtr =
false;
229 bool HaveCall =
false;
251 bool NonKernelOnly =
false;
253 NonKernelOnly, NeedQueuePtr);
254 if (!AttrName.
empty() && (IsFunc || !NonKernelOnly)) {
255 F.addFnAttr(AttrName);
261 if (NeedQueuePtr || HasApertureRegs)
271 for (
const Use &U :
I.operands()) {
276 if (visitConstantExprsRecursively(OpC, ConstantExprVisited, AS)) {
285 F.addFnAttr(
"amdgpu-queue-ptr");
292 if (HasFlat && !IsFunc && HaveCall) {
293 F.addFnAttr(
"amdgpu-flat-scratch");
300 bool AMDGPUAnnotateKernelFeatures::runOnSCC(
CallGraphSCC &SCC) {
304 bool Changed =
false;
310 Changed |= addFeatureAttributes(*F);
316 bool AMDGPUAnnotateKernelFeatures::doInitialization(
CallGraph &CG) {
317 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
327 return new AMDGPUAnnotateKernelFeatures();
Pass interface - Implemented by all 'passes'.
void push_back(const T &Elt)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
unsigned getSrcAddressSpace() const
Returns the address space of the pointer operand.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
bool hasApertureRegs() const
AMDGPU specific subclass of TargetSubtarget.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
AMDGPUAS getAMDGPUAS(const Module &M)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
This defines the Use class.
A node in the call graph for a module.
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
Module & getModule() const
Returns the module the call graph corresponds to.
This class represents a conversion between pointers from one address space to another.
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
A Use represents the edge between a Value definition and its users.
Pass * createAMDGPUAnnotateKernelFeaturesPass()
const CallGraph & getCallGraph()
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static bool castRequiresQueuePtr(const AddrSpaceCastInst *ASC, const AMDGPUAS &AS)
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
static void copyFeaturesToFunction(Function &Parent, const Function &Callee, bool &NeedQueuePtr)
LLVM Basic Block Representation.
This is an important base class in LLVM.
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.
bool isEntryFunctionCC(CallingConv::ID CC)
char & AMDGPUAnnotateKernelFeaturesID
Represent the analysis usage information of a pass.
Triple - Helper class for working with autoconf configuration names.
bool hasFlatAddressSpace() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
INITIALIZE_PASS(AMDGPUAnnotateKernelFeatures, DEBUG_TYPE, "Add AMDGPU function attributes", false, false) static bool castRequiresQueuePtr(unsigned SrcAS
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD T pop_back_val()
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void setPreservesAll()
Set by analyses that do not transform their input at all.
static bool handleAttr(Function &Parent, const Function &Callee, StringRef Name)
The basic data container for the call graph of a Module of IR.
LLVM_NODISCARD bool empty() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Primary interface to the complete machine description for the target machine.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
StringRef - Represent a constant reference to a string, i.e.
static StringRef intrinsicToAttrName(Intrinsic::ID ID, bool &NonKernelOnly, bool &IsQueuePtr)