2016-02-08 23:59:20 +08:00
|
|
|
//===---- CGOpenMPRuntimeNVPTX.cpp - Interface to OpenMP NVPTX Runtimes ---===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-02-08 23:59:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides a class for OpenMP runtime code generation specialized to NVPTX
|
2020-07-17 22:17:32 +08:00
|
|
|
// targets from generalized CGOpenMPRuntimeGPU class.
|
2016-02-08 23:59:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CGOpenMPRuntimeNVPTX.h"
|
2020-07-17 22:17:32 +08:00
|
|
|
#include "CGOpenMPRuntimeGPU.h"
|
2016-04-04 23:55:02 +08:00
|
|
|
#include "CodeGenFunction.h"
|
2019-12-10 08:11:56 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2018-03-14 22:17:45 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
2016-04-04 23:55:02 +08:00
|
|
|
#include "clang/AST/StmtOpenMP.h"
|
2018-03-14 22:17:45 +08:00
|
|
|
#include "clang/AST/StmtVisitor.h"
|
2018-11-02 22:54:07 +08:00
|
|
|
#include "clang/Basic/Cuda.h"
|
2018-03-14 22:17:45 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2019-12-11 23:55:26 +08:00
|
|
|
#include "llvm/IR/IntrinsicsNVPTX.h"
|
2016-02-08 23:59:20 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
[OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h
Summary:
The new OpenMPConstants.h is a location for all OpenMP related constants
(and helpers) to live.
This patch moves the directives there (the enum OpenMPDirectiveKind) and
rewires Clang to use the new location.
Initially part of D69785.
Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim
Subscribers: jholewinski, ppenzin, penzn, llvm-commits, cfe-commits, jfb, guansong, bollu, hiraditya, mgorny
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D69853
2019-11-05 12:00:49 +08:00
|
|
|
using namespace llvm::omp;
|
2016-02-08 23:59:20 +08:00
|
|
|
|
2020-07-17 22:17:32 +08:00
|
|
|
CGOpenMPRuntimeNVPTX::CGOpenMPRuntimeNVPTX(CodeGenModule &CGM)
|
|
|
|
: CGOpenMPRuntimeGPU(CGM) {
|
|
|
|
if (!CGM.getLangOpts().OpenMPIsDevice)
|
|
|
|
llvm_unreachable("OpenMP NVPTX can only handle device code.");
|
2018-09-21 22:22:53 +08:00
|
|
|
}
|
|
|
|
|
2020-07-17 22:17:32 +08:00
|
|
|
llvm::Value *CGOpenMPRuntimeNVPTX::getGPUWarpSize(CodeGenFunction &CGF) {
|
2017-08-14 23:01:03 +08:00
|
|
|
return CGF.EmitRuntimeCall(
|
2016-03-22 09:48:56 +08:00
|
|
|
llvm::Intrinsic::getDeclaration(
|
2017-01-04 04:19:56 +08:00
|
|
|
&CGF.CGM.getModule(), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize),
|
2017-08-14 23:01:03 +08:00
|
|
|
"nvptx_warp_size");
|
2016-03-22 09:48:56 +08:00
|
|
|
}
|
2020-08-03 13:29:48 +08:00
|
|
|
|
|
|
|
llvm::Value *CGOpenMPRuntimeNVPTX::getGPUThreadID(CodeGenFunction &CGF) {
|
|
|
|
CGBuilderTy &Bld = CGF.Builder;
|
|
|
|
llvm::Function *F;
|
|
|
|
F = llvm::Intrinsic::getDeclaration(
|
|
|
|
&CGF.CGM.getModule(), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x);
|
|
|
|
return Bld.CreateCall(F, llvm::None, "nvptx_tid");
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *CGOpenMPRuntimeNVPTX::getGPUNumThreads(CodeGenFunction &CGF) {
|
|
|
|
CGBuilderTy &Bld = CGF.Builder;
|
|
|
|
llvm::Function *F;
|
|
|
|
F = llvm::Intrinsic::getDeclaration(
|
|
|
|
&CGF.CGM.getModule(), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x);
|
|
|
|
return Bld.CreateCall(F, llvm::None, "nvptx_num_threads");
|
|
|
|
}
|