diff options
author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2023-11-16 08:42:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 08:42:54 -0500 |
commit | 27e6e4a4d0e3296cebad8db577ec0469a286795e (patch) | |
tree | 49f7b49ab9cca163c827277f560660d1bcc6e19d /clang/lib/Sema/SemaCUDA.cpp | |
parent | ea84897ba3e7727a3aa3fbd6d84b6b4ab573c70d (diff) | |
download | llvm-27e6e4a4d0e3296cebad8db577ec0469a286795e.zip llvm-27e6e4a4d0e3296cebad8db577ec0469a286795e.tar.gz llvm-27e6e4a4d0e3296cebad8db577ec0469a286795e.tar.bz2 |
[CUDA][HIP] make trivial ctor/dtor host device (#72394)
Make trivial ctor/dtor implicitly host device functions so that they can
be used to initialize file-scope
device variables to match nvcc behavior.
Fixes: https://github.com/llvm/llvm-project/issues/72261
Fixes: SWDEV-432412
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCUDA.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index 318174f..b94f448 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -772,6 +772,22 @@ void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD, NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context)); } +// If a trivial ctor/dtor has no host/device +// attributes, make it implicitly host device function. +void Sema::maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD) { + bool IsTrivialCtor = false; + if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) + IsTrivialCtor = isEmptyCudaConstructor(SourceLocation(), CD); + bool IsTrivialDtor = false; + if (auto *DD = dyn_cast<CXXDestructorDecl>(FD)) + IsTrivialDtor = isEmptyCudaDestructor(SourceLocation(), DD); + if ((IsTrivialCtor || IsTrivialDtor) && !FD->hasAttr<CUDAHostAttr>() && + !FD->hasAttr<CUDADeviceAttr>()) { + FD->addAttr(CUDAHostAttr::CreateImplicit(Context)); + FD->addAttr(CUDADeviceAttr::CreateImplicit(Context)); + } +} + // TODO: `__constant__` memory may be a limited resource for certain targets. // A safeguard may be needed at the end of compilation pipeline if // `__constant__` memory usage goes beyond limit. |