20#include "llvm/IR/IntrinsicsNVPTX.h"
27#define DEBUG_TYPE "nvvm-intr-range"
46char NVVMIntrRange::ID = 0;
48 "Add !range metadata to NVVM intrinsics.",
false,
false)
53 if (
II->getMetadata(LLVMContext::MD_range))
59 if (
auto CurrentRange =
II->getRange())
69 } MaxBlockSize, MaxGridSize;
71 const unsigned MetadataNTID =
getReqNTID(
F).value_or(
72 getMaxNTID(
F).value_or(std::numeric_limits<unsigned>::max()));
74 MaxBlockSize.x = std::min(1024u, MetadataNTID);
75 MaxBlockSize.y = std::min(1024u, MetadataNTID);
76 MaxBlockSize.z = std::min(64u, MetadataNTID);
78 MaxGridSize.x = 0x7fffffff;
79 MaxGridSize.y = 0xffff;
80 MaxGridSize.z = 0xffff;
89 switch (
II->getIntrinsicID()) {
91 case Intrinsic::nvvm_read_ptx_sreg_tid_x:
92 Changed |= addRangeAttr(0, MaxBlockSize.x,
II);
94 case Intrinsic::nvvm_read_ptx_sreg_tid_y:
95 Changed |= addRangeAttr(0, MaxBlockSize.y,
II);
97 case Intrinsic::nvvm_read_ptx_sreg_tid_z:
98 Changed |= addRangeAttr(0, MaxBlockSize.z,
II);
102 case Intrinsic::nvvm_read_ptx_sreg_ntid_x:
103 Changed |= addRangeAttr(1, MaxBlockSize.x + 1,
II);
105 case Intrinsic::nvvm_read_ptx_sreg_ntid_y:
106 Changed |= addRangeAttr(1, MaxBlockSize.y + 1,
II);
108 case Intrinsic::nvvm_read_ptx_sreg_ntid_z:
109 Changed |= addRangeAttr(1, MaxBlockSize.z + 1,
II);
113 case Intrinsic::nvvm_read_ptx_sreg_ctaid_x:
114 Changed |= addRangeAttr(0, MaxGridSize.x,
II);
116 case Intrinsic::nvvm_read_ptx_sreg_ctaid_y:
117 Changed |= addRangeAttr(0, MaxGridSize.y,
II);
119 case Intrinsic::nvvm_read_ptx_sreg_ctaid_z:
120 Changed |= addRangeAttr(0, MaxGridSize.z,
II);
124 case Intrinsic::nvvm_read_ptx_sreg_nctaid_x:
125 Changed |= addRangeAttr(1, MaxGridSize.x + 1,
II);
127 case Intrinsic::nvvm_read_ptx_sreg_nctaid_y:
128 Changed |= addRangeAttr(1, MaxGridSize.y + 1,
II);
130 case Intrinsic::nvvm_read_ptx_sreg_nctaid_z:
131 Changed |= addRangeAttr(1, MaxGridSize.z + 1,
II);
135 case Intrinsic::nvvm_read_ptx_sreg_warpsize:
136 Changed |= addRangeAttr(32, 32 + 1,
II);
140 case Intrinsic::nvvm_read_ptx_sreg_laneid:
141 Changed |= addRangeAttr(0, 32,
II);
Expand Atomic instructions
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static bool runNVVMIntrRange(Function &F)
uint64_t IntrinsicInst * II
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Class for arbitrary precision integers.
A container for analyses that lazily runs them and caches their results.
This class represents a range of values.
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
A wrapper class for inspecting calls to intrinsic functions.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static 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.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
void initializeNVVMIntrRangePass(PassRegistry &)
FunctionPass * createNVVMIntrRangePass()
std::optional< unsigned > getReqNTID(const Function &F)
std::optional< unsigned > getMaxNTID(const Function &F)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)