40 #define DEBUG_TYPE "amdgpu-annotate-kernel-features" 57 bool doInitialization(
CallGraph &CG)
override;
61 return "AMDGPU Annotate Kernel Features";
70 static bool visitConstantExprsRecursively(
82 "Add AMDGPU function attributes",
false,
false)
94 bool AMDGPUAnnotateKernelFeatures::visitConstantExpr(
const ConstantExpr *CE) {
95 if (CE->
getOpcode() == Instruction::AddrSpaceCast) {
103 bool AMDGPUAnnotateKernelFeatures::visitConstantExprsRecursively(
107 if (!ConstantExprVisited.
insert(EntryC).second)
113 while (!Stack.
empty()) {
117 if (
const auto *CE = dyn_cast<ConstantExpr>(C)) {
118 if (visitConstantExpr(CE))
128 if (!ConstantExprVisited.
insert(OpC).second)
148 NonKernelOnly =
true;
149 return "amdgpu-work-item-id-x";
151 NonKernelOnly =
true;
152 return "amdgpu-work-group-id-x";
155 return "amdgpu-work-item-id-y";
158 return "amdgpu-work-item-id-z";
161 return "amdgpu-work-group-id-y";
164 return "amdgpu-work-group-id-z";
166 return "amdgpu-dispatch-ptr";
168 return "amdgpu-dispatch-id";
170 return "amdgpu-kernarg-segment-ptr";
172 return "amdgpu-implicitarg-ptr";
177 return "amdgpu-queue-ptr";
194 bool &NeedQueuePtr) {
197 {
"amdgpu-work-item-id-x" },
198 {
"amdgpu-work-item-id-y" },
199 {
"amdgpu-work-item-id-z" },
200 {
"amdgpu-work-group-id-x" },
201 {
"amdgpu-work-group-id-y" },
202 {
"amdgpu-work-group-id-z" },
203 {
"amdgpu-dispatch-ptr" },
204 {
"amdgpu-dispatch-id" },
205 {
"amdgpu-kernarg-segment-ptr" },
206 {
"amdgpu-implicitarg-ptr" }
209 if (
handleAttr(Parent, Callee,
"amdgpu-queue-ptr"))
216 bool AMDGPUAnnotateKernelFeatures::addFeatureAttributes(
Function &
F) {
222 bool Changed =
false;
223 bool NeedQueuePtr =
false;
224 bool HaveCall =
false;
246 bool NonKernelOnly =
false;
248 NonKernelOnly, NeedQueuePtr);
249 if (!AttrName.
empty() && (IsFunc || !NonKernelOnly)) {
250 F.addFnAttr(AttrName);
256 if (NeedQueuePtr || HasApertureRegs)
266 for (
const Use &U :
I.operands()) {
271 if (visitConstantExprsRecursively(OpC, ConstantExprVisited)) {
280 F.addFnAttr(
"amdgpu-queue-ptr");
287 if (HasFlat && !IsFunc && HaveCall) {
288 F.addFnAttr(
"amdgpu-flat-scratch");
295 bool AMDGPUAnnotateKernelFeatures::runOnSCC(
CallGraphSCC &SCC) {
299 bool Changed =
false;
305 Changed |= addFeatureAttributes(*F);
311 bool AMDGPUAnnotateKernelFeatures::doInitialization(
CallGraph &CG) {
312 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
321 return new AMDGPUAnnotateKernelFeatures();
Pass interface - Implemented by all 'passes'.
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.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
Address space for private memory.
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
A Use represents the edge between a Value definition and its users.
Pass * createAMDGPUAnnotateKernelFeaturesPass()
const CallGraph & getCallGraph()
static bool castRequiresQueuePtr(const AddrSpaceCastInst *ASC)
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.
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.
Address space for local memory.
Triple - Helper class for working with autoconf configuration names.
bool hasFlatAddressSpace() const
INITIALIZE_PASS(AMDGPUAnnotateKernelFeatures, DEBUG_TYPE, "Add AMDGPU function attributes", false, false) static bool castRequiresQueuePtr(unsigned SrcAS)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
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)