| 1 | //===--- GlobalDecl.cpp - Global declaration holder -------------*- C++ -*-===// |
|---|---|
| 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 | // GlobalDecl.h is included very widely, so these members are defined here to |
| 10 | // keep the OpenMP and OpenACC declaration hierarchies, the generated attribute |
| 11 | // classes, and the template declaration hierarchy out of it. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/GlobalDecl.h" |
| 16 | |
| 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/DeclOpenACC.h" |
| 19 | #include "clang/AST/DeclOpenMP.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | |
| 22 | using namespace clang; |
| 23 | |
| 24 | GlobalDecl::GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); } |
| 25 | GlobalDecl::GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); } |
| 26 | GlobalDecl::GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); } |
| 27 | GlobalDecl::GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); } |
| 28 | |
| 29 | bool GlobalDecl::hasCUDAGlobalAttr(const Decl *D) { |
| 30 | return D->hasAttr<CUDAGlobalAttr>(); |
| 31 | } |
| 32 | |
| 33 | bool GlobalDecl::isKernelReference(const Decl *D) { |
| 34 | if (const auto *FD = dyn_cast<FunctionDecl>(Val: D)) |
| 35 | return FD->isReferenceableKernel(); |
| 36 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(Val: D)) |
| 37 | return FTD->getTemplatedDecl()->hasAttr<CUDAGlobalAttr>(); |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | KernelReferenceKind |
| 42 | GlobalDecl::getDefaultKernelReference(const FunctionDecl *D) { |
| 43 | return (D->hasAttr<DeviceKernelAttr>() || D->getLangOpts().CUDAIsDevice) |
| 44 | ? KernelReferenceKind::Kernel |
| 45 | : KernelReferenceKind::Stub; |
| 46 | } |
| 47 |