15constexpr unsigned OffsetGridDimX = 0;
16constexpr unsigned OffsetGridDimY = 1;
17constexpr unsigned OffsetGridDimZ = 2;
19inline Value *getGridDim(
Func &Fn,
unsigned Offset) {
22 constexpr int ConstantAddressSpace = 4;
27 FunctionCallee Callee =
28 M.getOrInsertFunction(
"llvm.amdgcn.implicitarg.ptr",
29 PointerType::get(Ctx, ConstantAddressSpace));
30 auto *Call = IRB.CreateCall(Callee);
31 auto *GEP = IRB.CreateInBoundsGEP(
32 IRB.getInt32Ty(), Call, {ConstantInt::get(IRB.getInt64Ty(), Offset)});
33 auto *Load = IRB.CreateLoad(IRB.getInt32Ty(), GEP);
39constexpr unsigned OffsetBlockDimX = 6;
40constexpr unsigned OffsetBlockDimY = 7;
41constexpr unsigned OffsetBlockDimZ = 8;
43inline Value *getBlockDim(
Func &Fn,
unsigned Offset) {
46 constexpr int ConstantAddressSpace = 4;
51 FunctionCallee Callee =
52 M.getOrInsertFunction(
"llvm.amdgcn.implicitarg.ptr",
53 PointerType::get(Ctx, ConstantAddressSpace));
54 auto *Call = IRB.CreateCall(Callee);
55 auto *GEP = IRB.CreateInBoundsGEP(
56 IRB.getInt16Ty(), Call, {ConstantInt::get(IRB.getInt64Ty(), Offset)});
57 auto *Load = IRB.CreateLoad(IRB.getInt16Ty(), GEP);
58 auto *Conv = IRB.CreateZExt(Load, IRB.getInt32Ty());
65inline Var &getThreadIdX(
Func &Fn) {
72 FunctionCallee Callee = M.getOrInsertFunction(
"llvm.amdgcn.workitem.id.x",
74 auto *Call = IRB.CreateCall(Callee);
80inline Var &getBlockIdX(
Func &Fn) {
87 FunctionCallee Callee = M.getOrInsertFunction(
"llvm.amdgcn.workgroup.id.x",
89 auto *Call = IRB.CreateCall(Callee);
95inline Var &getBlockDimX(
Func &Fn) {
100 Value *Conv = detail::getBlockDim(Fn, detail::OffsetBlockDimX);
106inline Var &getGridDimX(
Func &Fn) {
110 Value *Conv = detail::getGridDim(Fn, detail::OffsetGridDimX);
119#if PROTEUS_ENABLE_CUDA
121inline Var &getThreadIdX(
Func &Fn) {
128 FunctionCallee Callee = M.getOrInsertFunction(
"llvm.nvvm.read.ptx.sreg.tid.x",
130 auto *Call = IRB.CreateCall(Callee);
136inline Var &getBlockIdX(
Func &Fn) {
143 FunctionCallee Callee = M.getOrInsertFunction(
145 auto *Call = IRB.CreateCall(Callee);
151inline Var &getBlockDimX(
Func &Fn) {
158 FunctionCallee Callee = M.getOrInsertFunction(
160 auto *Call = IRB.CreateCall(Callee);
166inline Var &getGridDimX(
Func &Fn) {
173 FunctionCallee Callee = M.getOrInsertFunction(
175 auto *Call = IRB.CreateCall(Callee);