20#include "llvm/IR/IntrinsicsNVPTX.h"
26#define DEBUG_TYPE "nvvm-intr-range"
45char NVVMIntrRange::ID = 0;
47 "Add !range metadata to NVVM intrinsics.",
false,
false)
52 if (
II->getMetadata(LLVMContext::MD_range))
58 if (
auto CurrentRange =
II->getRange())
68 } MaxBlockSize, MaxGridSize;
70 const unsigned MetadataNTID =
getReqNTID(
F).value_or(
71 getMaxNTID(
F).value_or(std::numeric_limits<unsigned>::max()));
73 MaxBlockSize.x = std::min(1024u, MetadataNTID);
74 MaxBlockSize.y = std::min(1024u, MetadataNTID);
75 MaxBlockSize.z = std::min(64u, MetadataNTID);
77 MaxGridSize.x = 0x7fffffff;
78 MaxGridSize.y = 0xffff;
79 MaxGridSize.z = 0xffff;
88 switch (
II->getIntrinsicID()) {
90 case Intrinsic::nvvm_read_ptx_sreg_tid_x:
91 Changed |= addRangeAttr(0, MaxBlockSize.x,
II);
93 case Intrinsic::nvvm_read_ptx_sreg_tid_y:
94 Changed |= addRangeAttr(0, MaxBlockSize.y,
II);
96 case Intrinsic::nvvm_read_ptx_sreg_tid_z:
97 Changed |= addRangeAttr(0, MaxBlockSize.z,
II);
101 case Intrinsic::nvvm_read_ptx_sreg_ntid_x:
102 Changed |= addRangeAttr(1, MaxBlockSize.x + 1,
II);
104 case Intrinsic::nvvm_read_ptx_sreg_ntid_y:
105 Changed |= addRangeAttr(1, MaxBlockSize.y + 1,
II);
107 case Intrinsic::nvvm_read_ptx_sreg_ntid_z:
108 Changed |= addRangeAttr(1, MaxBlockSize.z + 1,
II);
112 case Intrinsic::nvvm_read_ptx_sreg_ctaid_x:
113 Changed |= addRangeAttr(0, MaxGridSize.x,
II);
115 case Intrinsic::nvvm_read_ptx_sreg_ctaid_y:
116 Changed |= addRangeAttr(0, MaxGridSize.y,
II);
118 case Intrinsic::nvvm_read_ptx_sreg_ctaid_z:
119 Changed |= addRangeAttr(0, MaxGridSize.z,
II);
123 case Intrinsic::nvvm_read_ptx_sreg_nctaid_x:
124 Changed |= addRangeAttr(1, MaxGridSize.x + 1,
II);
126 case Intrinsic::nvvm_read_ptx_sreg_nctaid_y:
127 Changed |= addRangeAttr(1, MaxGridSize.y + 1,
II);
129 case Intrinsic::nvvm_read_ptx_sreg_nctaid_z:
130 Changed |= addRangeAttr(1, MaxGridSize.z + 1,
II);
134 case Intrinsic::nvvm_read_ptx_sreg_warpsize:
135 Changed |= addRangeAttr(32, 32 + 1,
II);
139 case Intrinsic::nvvm_read_ptx_sreg_laneid:
140 Changed |= addRangeAttr(0, 32,
II);
Expand Atomic instructions
This header defines various interfaces for pass management in LLVM.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static bool runNVVMIntrRange(Function &F)
uint64_t IntrinsicInst * II
#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)