/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- CGOpenMPRuntimeAMDGCN.cpp - Interface to OpenMP AMDGCN Runtimes --===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This provides a class for OpenMP runtime code generation specialized to |
10 | | // AMDGCN targets from generalized CGOpenMPRuntimeGPU class. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "CGOpenMPRuntimeAMDGCN.h" |
15 | | #include "CGOpenMPRuntimeGPU.h" |
16 | | #include "CodeGenFunction.h" |
17 | | #include "clang/AST/Attr.h" |
18 | | #include "clang/AST/DeclOpenMP.h" |
19 | | #include "clang/AST/StmtOpenMP.h" |
20 | | #include "clang/AST/StmtVisitor.h" |
21 | | #include "clang/Basic/Cuda.h" |
22 | | #include "llvm/ADT/SmallPtrSet.h" |
23 | | #include "llvm/IR/IntrinsicsAMDGPU.h" |
24 | | |
25 | | using namespace clang; |
26 | | using namespace CodeGen; |
27 | | using namespace llvm::omp; |
28 | | |
29 | | CGOpenMPRuntimeAMDGCN::CGOpenMPRuntimeAMDGCN(CodeGenModule &CGM) |
30 | 3 | : CGOpenMPRuntimeGPU(CGM) { |
31 | 3 | if (!CGM.getLangOpts().OpenMPIsDevice) |
32 | 0 | llvm_unreachable("OpenMP AMDGCN can only handle device code."); |
33 | 3 | } |
34 | | |
35 | 9 | llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUWarpSize(CodeGenFunction &CGF) { |
36 | 9 | CGBuilderTy &Bld = CGF.Builder; |
37 | | // return constant compile-time target-specific warp size |
38 | 9 | unsigned WarpSize = CGF.getTarget().getGridValue(llvm::omp::GV_Warp_Size); |
39 | 9 | return Bld.getInt32(WarpSize); |
40 | 9 | } |
41 | | |
42 | 6 | llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUThreadID(CodeGenFunction &CGF) { |
43 | 6 | CGBuilderTy &Bld = CGF.Builder; |
44 | 6 | llvm::Function *F = |
45 | 6 | CGF.CGM.getIntrinsic(llvm::Intrinsic::amdgcn_workitem_id_x); |
46 | 6 | return Bld.CreateCall(F, llvm::None, "nvptx_tid"); |
47 | 6 | } |
48 | | |
49 | 10 | llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUNumThreads(CodeGenFunction &CGF) { |
50 | 10 | CGBuilderTy &Bld = CGF.Builder; |
51 | 10 | llvm::Module *M = &CGF.CGM.getModule(); |
52 | 10 | const char *LocSize = "__kmpc_amdgcn_gpu_num_threads"; |
53 | 10 | llvm::Function *F = M->getFunction(LocSize); |
54 | 10 | if (!F) { |
55 | 3 | F = llvm::Function::Create( |
56 | 3 | llvm::FunctionType::get(CGF.Int32Ty, llvm::None, false), |
57 | 3 | llvm::GlobalVariable::ExternalLinkage, LocSize, &CGF.CGM.getModule()); |
58 | 3 | } |
59 | 10 | return Bld.CreateCall(F, llvm::None, "nvptx_num_threads"); |
60 | 10 | } |