Coverage Report

Created: 2021-09-21 08:58

/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/Frontend/OpenMP/OMPGridValues.h"
24
#include "llvm/IR/IntrinsicsAMDGPU.h"
25
26
using namespace clang;
27
using namespace CodeGen;
28
using namespace llvm::omp;
29
30
CGOpenMPRuntimeAMDGCN::CGOpenMPRuntimeAMDGCN(CodeGenModule &CGM)
31
11
    : CGOpenMPRuntimeGPU(CGM) {
32
11
  if (!CGM.getLangOpts().OpenMPIsDevice)
33
0
    llvm_unreachable("OpenMP AMDGCN can only handle device code.");
34
11
}
35
36
0
llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUWarpSize(CodeGenFunction &CGF) {
37
0
  CGBuilderTy &Bld = CGF.Builder;
38
  // return constant compile-time target-specific warp size
39
0
  unsigned WarpSize = CGF.getTarget().getGridValue().GV_Warp_Size;
40
0
  return Bld.getInt32(WarpSize);
41
0
}
42
43
0
llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUThreadID(CodeGenFunction &CGF) {
44
0
  CGBuilderTy &Bld = CGF.Builder;
45
0
  llvm::Function *F =
46
0
      CGF.CGM.getIntrinsic(llvm::Intrinsic::amdgcn_workitem_id_x);
47
0
  return Bld.CreateCall(F, llvm::None, "nvptx_tid");
48
0
}
49
50
0
llvm::Value *CGOpenMPRuntimeAMDGCN::getGPUNumThreads(CodeGenFunction &CGF) {
51
0
  CGBuilderTy &Bld = CGF.Builder;
52
0
  llvm::Module *M = &CGF.CGM.getModule();
53
0
  const char *LocSize = "__kmpc_amdgcn_gpu_num_threads";
54
0
  llvm::Function *F = M->getFunction(LocSize);
55
0
  if (!F) {
56
0
    F = llvm::Function::Create(
57
0
        llvm::FunctionType::get(CGF.Int32Ty, llvm::None, false),
58
0
        llvm::GlobalVariable::ExternalLinkage, LocSize, &CGF.CGM.getModule());
59
0
  }
60
0
  return Bld.CreateCall(F, llvm::None, "nvptx_num_threads");
61
0
}