19 #include "llvm/IR/IntrinsicsNVPTX.h" 24 #define DEBUG_TYPE "nvvm-intr-range" 37 } MaxBlockSize, MaxGridSize;
41 NVVMIntrRange() : NVVMIntrRange(NVVMIntrRangeSM) {}
42 NVVMIntrRange(
unsigned int SmVersion) :
FunctionPass(ID) {
43 MaxBlockSize.x = 1024;
44 MaxBlockSize.y = 1024;
47 MaxGridSize.x = SmVersion >= 30 ? 0x7fffffff : 0xffff;
48 MaxGridSize.y = 0xffff;
49 MaxGridSize.z = 0xffff;
59 return new NVVMIntrRange(SmVersion);
64 "Add !range metadata to NVVM intrinsics.",
false,
false)
68 static
bool addRangeMetadata(uint64_t Low, uint64_t
High,
CallInst *
C) {
91 switch (
Callee->getIntrinsicID()) {
93 case Intrinsic::nvvm_read_ptx_sreg_tid_x:
94 Changed |= addRangeMetadata(0, MaxBlockSize.x, Call);
96 case Intrinsic::nvvm_read_ptx_sreg_tid_y:
97 Changed |= addRangeMetadata(0, MaxBlockSize.y, Call);
99 case Intrinsic::nvvm_read_ptx_sreg_tid_z:
100 Changed |= addRangeMetadata(0, MaxBlockSize.z, Call);
104 case Intrinsic::nvvm_read_ptx_sreg_ntid_x:
105 Changed |= addRangeMetadata(1, MaxBlockSize.x+1, Call);
107 case Intrinsic::nvvm_read_ptx_sreg_ntid_y:
108 Changed |= addRangeMetadata(1, MaxBlockSize.y+1, Call);
110 case Intrinsic::nvvm_read_ptx_sreg_ntid_z:
111 Changed |= addRangeMetadata(1, MaxBlockSize.z+1, Call);
115 case Intrinsic::nvvm_read_ptx_sreg_ctaid_x:
116 Changed |= addRangeMetadata(0, MaxGridSize.x, Call);
118 case Intrinsic::nvvm_read_ptx_sreg_ctaid_y:
119 Changed |= addRangeMetadata(0, MaxGridSize.y, Call);
121 case Intrinsic::nvvm_read_ptx_sreg_ctaid_z:
122 Changed |= addRangeMetadata(0, MaxGridSize.z, Call);
126 case Intrinsic::nvvm_read_ptx_sreg_nctaid_x:
127 Changed |= addRangeMetadata(1, MaxGridSize.x+1, Call);
129 case Intrinsic::nvvm_read_ptx_sreg_nctaid_y:
130 Changed |= addRangeMetadata(1, MaxGridSize.y+1, Call);
132 case Intrinsic::nvvm_read_ptx_sreg_nctaid_z:
133 Changed |= addRangeMetadata(1, MaxGridSize.z+1, Call);
137 case Intrinsic::nvvm_read_ptx_sreg_warpsize:
138 Changed |= addRangeMetadata(32, 32+1, Call);
142 case Intrinsic::nvvm_read_ptx_sreg_laneid:
143 Changed |= addRangeMetadata(0, 32, Call);
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
This class represents a function call, abstracting a target machine's calling convention.
LLVMContext & getContext() const
Get the context in which this basic block lives.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void initializeNVVMIntrRangePass(PassRegistry &)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
This is an important class for using LLVM in a threaded context.
INITIALIZE_PASS(NVVMIntrRange, "nvvm-intr-range", "Add !range metadata to NVVM intrinsics.", false, false) static bool addRangeMetadata(uint64_t Low
This file contains the declarations for the subclasses of Constant, which represent the different fla...
FunctionPass class - This class is used to implement most global optimizations.
Class to represent integer types.
static cl::opt< unsigned > NVVMIntrRangeSM("nvvm-intr-range-sm", cl::init(20), cl::Hidden, cl::desc("SM variant"))
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
amdgpu Simplify well known AMD library false FunctionCallee Callee
FunctionPass * createNVVMIntrRangePass(unsigned int SmVersion)
static IntegerType * getInt32Ty(LLVMContext &C)
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
inst_range instructions(Function *F)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
const BasicBlock * getParent() const