diff options
author | Justin Lebar <jlebar@google.com> | 2016-10-08 22:15:58 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-10-08 22:15:58 +0000 |
commit | 67a78a6cc021344d295e4f42603bdef601502e14 (patch) | |
tree | 7e67b2fd6802b872e448914ecdeac00042f41d45 /clang/lib/Sema/SemaCUDA.cpp | |
parent | 9adc7c8b4a624a9b5424ade22ccd85544238e503 (diff) | |
download | bcm5719-llvm-67a78a6cc021344d295e4f42603bdef601502e14.tar.gz bcm5719-llvm-67a78a6cc021344d295e4f42603bdef601502e14.zip |
[CUDA] Add #pragma clang force_cuda_host_device_{begin,end} pragmas.
Summary:
These cause us to consider all functions in-between to be __host__
__device__.
You can nest these pragmas; you just can't have more 'end's than
'begin's.
Reviewers: rsmith
Subscribers: tra, jhen, cfe-commits
Differential Revision: https://reviews.llvm.org/D24975
llvm-svn: 283677
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCUDA.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index cb7019242f1..d6c0606674e 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -23,6 +23,19 @@ #include "llvm/ADT/SmallVector.h" using namespace clang; +void Sema::PushForceCUDAHostDevice() { + assert(getLangOpts().CUDA && "Should only be called during CUDA compilation"); + ForceCUDAHostDeviceDepth++; +} + +bool Sema::PopForceCUDAHostDevice() { + assert(getLangOpts().CUDA && "Should only be called during CUDA compilation"); + if (ForceCUDAHostDeviceDepth == 0) + return false; + ForceCUDAHostDeviceDepth--; + return true; +} + ExprResult Sema::ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc) { @@ -441,9 +454,23 @@ bool Sema::isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *DD) { // * a __device__ function with this signature was already declared, in which // case in which case we output an error, unless the __device__ decl is in a // system header, in which case we leave the constexpr function unattributed. +// +// In addition, all function decls are treated as __host__ __device__ when +// ForceCUDAHostDeviceDepth > 0 (corresponding to code within a +// #pragma clang force_cuda_host_device_begin/end +// pair). void Sema::maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *NewD, const LookupResult &Previous) { assert(getLangOpts().CUDA && "Should only be called during CUDA compilation"); + + if (ForceCUDAHostDeviceDepth > 0) { + if (!NewD->hasAttr<CUDAHostAttr>()) + NewD->addAttr(CUDAHostAttr::CreateImplicit(Context)); + if (!NewD->hasAttr<CUDADeviceAttr>()) + NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context)); + return; + } + if (!getLangOpts().CUDAHostDeviceConstexpr || !NewD->isConstexpr() || NewD->isVariadic() || NewD->hasAttr<CUDAHostAttr>() || NewD->hasAttr<CUDADeviceAttr>() || NewD->hasAttr<CUDAGlobalAttr>()) |