[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
This revision was automatically updated to reflect the committed changes. Closed by commit rL290904: [OpenMP] Code cleanup for NVPTX OpenMP codegen (authored by arpith). Changed prior to commit: https://reviews.llvm.org/D28124?vs=82619=82931#toc Repository: rL LLVM https://reviews.llvm.org/D28124 Files: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp === --- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -20,53 +20,64 @@ using namespace clang; using namespace CodeGen; -/// \brief Get the GPU warp size. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) { +namespace { +enum OpenMPRTLFunctionNVPTX { + /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle, + /// kmp_int32 thread_limit); + OMPRTL_NVPTX__kmpc_kernel_init, +}; + +// NVPTX Address space +enum AddressSpace { + AddressSpaceShared = 3, +}; +} // namespace + +/// Get the GPU warp size. +static llvm::Value *getNVPTXWarpSize(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), llvm::None, "nvptx_warp_size"); } -/// \brief Get the id of the current thread on the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXThreadID(CodeGenFunction ) { +/// Get the id of the current thread on the GPU. +static llvm::Value *getNVPTXThreadID(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), llvm::None, "nvptx_tid"); } -// \brief Get the maximum number of threads in a block of the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXNumThreads(CodeGenFunction ) { +/// Get the maximum number of threads in a block of the GPU. +static llvm::Value *getNVPTXNumThreads(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), llvm::None, "nvptx_num_threads"); } -/// \brief Get barrier to synchronize all threads in a block. -void CGOpenMPRuntimeNVPTX::getNVPTXCTABarrier(CodeGenFunction ) { +/// Get barrier to synchronize all threads in a block. +static void getNVPTXCTABarrier(CodeGenFunction ) { CGBuilderTy = CGF.Builder; Bld.CreateCall(llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_barrier0)); + (), llvm::Intrinsic::nvvm_barrier0)); } -// \brief Synchronize all GPU threads in a block. -void CGOpenMPRuntimeNVPTX::syncCTAThreads(CodeGenFunction ) { - getNVPTXCTABarrier(CGF); -} +/// Synchronize all GPU threads in a block. +static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); } -/// \brief Get the thread id of the OMP master thread. +/// Get the thread id of the OMP master thread. /// The master thread id is the first thread (lane) of the last warp in the /// GPU block. Warp size is assumed to be some power of 2. /// Thread id is 0 indexed. /// E.g: If NumThreads is 33, master id is 32. /// If NumThreads is 64, master id is 32. /// If NumThreads is 1024, master id is 992. -llvm::Value *CGOpenMPRuntimeNVPTX::getMasterThreadID(CodeGenFunction ) { +static llvm::Value *getMasterThreadID(CodeGenFunction ) { CGBuilderTy = CGF.Builder; llvm::Value *NumThreads = getNVPTXNumThreads(CGF); @@ -77,19 +88,6 @@ Bld.CreateNot(Mask), "master_tid"); } -namespace { -enum OpenMPRTLFunctionNVPTX { - /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle, - /// kmp_int32 thread_limit); - OMPRTL_NVPTX__kmpc_kernel_init, -}; - -// NVPTX Address space -enum ADDRESS_SPACE { - ADDRESS_SPACE_SHARED = 3, -}; -} // namespace - CGOpenMPRuntimeNVPTX::WorkerFunctionState::WorkerFunctionState( CodeGenModule ) : WorkerFn(nullptr), CGFI(nullptr) { @@ -119,14 +117,14 @@ CGM.getModule(), CGM.Int32Ty, /*isConstant=*/false, llvm::GlobalValue::CommonLinkage, llvm::Constant::getNullValue(CGM.Int32Ty), "__omp_num_threads", 0, - llvm::GlobalVariable::NotThreadLocal, ADDRESS_SPACE_SHARED); + llvm::GlobalVariable::NotThreadLocal, AddressSpaceShared); ActiveWorkers->setAlignment(DL.getPrefTypeAlignment(CGM.Int32Ty)); WorkID = new llvm::GlobalVariable( CGM.getModule(), CGM.Int64Ty, /*isConstant=*/false, llvm::GlobalValue::CommonLinkage, llvm::Constant::getNullValue(CGM.Int64Ty), "__tgt_work_id", 0, - llvm::GlobalVariable::NotThreadLocal, ADDRESS_SPACE_SHARED); +
[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
ABataev added a comment. LG https://reviews.llvm.org/D28124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
arpith-jacob updated this revision to Diff 82619. arpith-jacob added a comment. Addressed comments in review to start function names with a lowercase letter and to fix the enum type name along with the enumerator name. https://reviews.llvm.org/D28124 Files: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp lib/CodeGen/CGOpenMPRuntimeNVPTX.h Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h === --- lib/CodeGen/CGOpenMPRuntimeNVPTX.h +++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h @@ -50,38 +50,6 @@ private: // - // NVPTX calls. - // - - /// \brief Get the GPU warp size. - llvm::Value *getNVPTXWarpSize(CodeGenFunction ); - - /// \brief Get the id of the current thread on the GPU. - llvm::Value *getNVPTXThreadID(CodeGenFunction ); - - // \brief Get the maximum number of threads in a block of the GPU. - llvm::Value *getNVPTXNumThreads(CodeGenFunction ); - - /// \brief Get barrier to synchronize all threads in a block. - void getNVPTXCTABarrier(CodeGenFunction ); - - // \brief Synchronize all GPU threads in a block. - void syncCTAThreads(CodeGenFunction ); - - // - // OMP calls. - // - - /// \brief Get the thread id of the OMP master thread. - /// The master thread id is the first thread (lane) of the last warp in the - /// GPU block. Warp size is assumed to be some power of 2. - /// Thread id is 0 indexed. - /// E.g: If NumThreads is 33, master id is 32. - /// If NumThreads is 64, master id is 32. - /// If NumThreads is 1024, master id is 992. - llvm::Value *getMasterThreadID(CodeGenFunction ); - - // // Private state and methods. // Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp === --- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -20,53 +20,64 @@ using namespace clang; using namespace CodeGen; -/// \brief Get the GPU warp size. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) { +namespace { +enum OpenMPRTLFunctionNVPTX { + /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle, + /// kmp_int32 thread_limit); + OMPRTL_NVPTX__kmpc_kernel_init, +}; + +// NVPTX Address space +enum AddressSpace { + AddressSpaceShared = 3, +}; +} // namespace + +/// Get the GPU warp size. +static llvm::Value *getNVPTXWarpSize(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), llvm::None, "nvptx_warp_size"); } -/// \brief Get the id of the current thread on the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXThreadID(CodeGenFunction ) { +/// Get the id of the current thread on the GPU. +static llvm::Value *getNVPTXThreadID(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), llvm::None, "nvptx_tid"); } -// \brief Get the maximum number of threads in a block of the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXNumThreads(CodeGenFunction ) { +/// Get the maximum number of threads in a block of the GPU. +static llvm::Value *getNVPTXNumThreads(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), llvm::None, "nvptx_num_threads"); } -/// \brief Get barrier to synchronize all threads in a block. -void CGOpenMPRuntimeNVPTX::getNVPTXCTABarrier(CodeGenFunction ) { +/// Get barrier to synchronize all threads in a block. +static void getNVPTXCTABarrier(CodeGenFunction ) { CGBuilderTy = CGF.Builder; Bld.CreateCall(llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_barrier0)); + (), llvm::Intrinsic::nvvm_barrier0)); } -// \brief Synchronize all GPU threads in a block. -void CGOpenMPRuntimeNVPTX::syncCTAThreads(CodeGenFunction ) { - getNVPTXCTABarrier(CGF); -} +/// Synchronize all GPU threads in a block. +static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); } -/// \brief Get the thread id of the OMP master thread. +/// Get the thread id of the OMP master thread. /// The master thread id is the first thread (lane) of the last warp in the /// GPU block. Warp size is assumed to be some power of 2. /// Thread id is 0 indexed. /// E.g: If NumThreads is 33, master id is 32. /// If NumThreads is 64, master id is 32. /// If NumThreads is 1024, master id is 992. -llvm::Value *CGOpenMPRuntimeNVPTX::getMasterThreadID(CodeGenFunction ) { +static llvm::Value *getMasterThreadID(CodeGenFunction ) { CGBuilderTy = CGF.Builder; llvm::Value *NumThreads = getNVPTXNumThreads(CGF); @@
[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
jlebar added inline comments. Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:31 +// NVPTX Address space +enum ADDRESS_SPACE { + ADDRESS_SPACE_SHARED = 3, Please fix enum typename name and the name of the enumerator: http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly https://reviews.llvm.org/D28124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
ABataev accepted this revision. ABataev added a comment. This revision is now accepted and ready to land. Function names must start with a lower case letter. LG for other changes https://reviews.llvm.org/D28124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D28124: [OpenMP] Code cleanup for NVPTX OpenMP codegen
arpith-jacob created this revision. arpith-jacob added reviewers: ABataev, sfantao, carlo.bertolli, kkwli0, caomhin. arpith-jacob added a subscriber: cfe-commits. Herald added a subscriber: jholewinski. This patch cleans up private methods for NVPTX OpenMP codegen. It converts private members to static functions to follow the coding style of CGOpenMPRuntime.cpp and declutter the header file. https://reviews.llvm.org/D28124 Files: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp lib/CodeGen/CGOpenMPRuntimeNVPTX.h Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h === --- lib/CodeGen/CGOpenMPRuntimeNVPTX.h +++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h @@ -50,38 +50,6 @@ private: // - // NVPTX calls. - // - - /// \brief Get the GPU warp size. - llvm::Value *getNVPTXWarpSize(CodeGenFunction ); - - /// \brief Get the id of the current thread on the GPU. - llvm::Value *getNVPTXThreadID(CodeGenFunction ); - - // \brief Get the maximum number of threads in a block of the GPU. - llvm::Value *getNVPTXNumThreads(CodeGenFunction ); - - /// \brief Get barrier to synchronize all threads in a block. - void getNVPTXCTABarrier(CodeGenFunction ); - - // \brief Synchronize all GPU threads in a block. - void syncCTAThreads(CodeGenFunction ); - - // - // OMP calls. - // - - /// \brief Get the thread id of the OMP master thread. - /// The master thread id is the first thread (lane) of the last warp in the - /// GPU block. Warp size is assumed to be some power of 2. - /// Thread id is 0 indexed. - /// E.g: If NumThreads is 33, master id is 32. - /// If NumThreads is 64, master id is 32. - /// If NumThreads is 1024, master id is 992. - llvm::Value *getMasterThreadID(CodeGenFunction ); - - // // Private state and methods. // Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp === --- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -20,76 +20,74 @@ using namespace clang; using namespace CodeGen; -/// \brief Get the GPU warp size. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) { +namespace { +enum OpenMPRTLFunctionNVPTX { + /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle, + /// kmp_int32 thread_limit); + OMPRTL_NVPTX__kmpc_kernel_init, +}; + +// NVPTX Address space +enum ADDRESS_SPACE { + ADDRESS_SPACE_SHARED = 3, +}; +} // namespace + +/// Get the GPU warp size. +static llvm::Value *GetNVPTXWarpSize(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize), llvm::None, "nvptx_warp_size"); } -/// \brief Get the id of the current thread on the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXThreadID(CodeGenFunction ) { +/// Get the id of the current thread on the GPU. +static llvm::Value *GetNVPTXThreadID(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x), llvm::None, "nvptx_tid"); } -// \brief Get the maximum number of threads in a block of the GPU. -llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXNumThreads(CodeGenFunction ) { +/// Get the maximum number of threads in a block of the GPU. +static llvm::Value *GetNVPTXNumThreads(CodeGenFunction ) { CGBuilderTy = CGF.Builder; return Bld.CreateCall( llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), + (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x), llvm::None, "nvptx_num_threads"); } -/// \brief Get barrier to synchronize all threads in a block. -void CGOpenMPRuntimeNVPTX::getNVPTXCTABarrier(CodeGenFunction ) { +/// Get barrier to synchronize all threads in a block. +static void GetNVPTXCTABarrier(CodeGenFunction ) { CGBuilderTy = CGF.Builder; Bld.CreateCall(llvm::Intrinsic::getDeclaration( - (), llvm::Intrinsic::nvvm_barrier0)); + (), llvm::Intrinsic::nvvm_barrier0)); } -// \brief Synchronize all GPU threads in a block. -void CGOpenMPRuntimeNVPTX::syncCTAThreads(CodeGenFunction ) { - getNVPTXCTABarrier(CGF); -} +/// Synchronize all GPU threads in a block. +static void SyncCTAThreads(CodeGenFunction ) { GetNVPTXCTABarrier(CGF); } -/// \brief Get the thread id of the OMP master thread. +/// Get the thread id of the OMP master thread. /// The master thread id is the first thread (lane) of the last warp in the /// GPU block. Warp size is assumed to be some power of 2. /// Thread id is 0 indexed. /// E.g: If NumThreads is 33, master id is 32. /// If NumThreads is 64, master id is 32. /// If NumThreads is 1024, master id is 992. -llvm::Value