[PATCH] D114812: [CUDA][HIP] Add pre-defined macro `__CLANG_RDC__`
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 6 15:23:20 PST 2021
yaxunl updated this revision to Diff 392205.
yaxunl retitled this revision from "[HIP] Add pre-defined macro `__HIPCC_RDC__`" to "[CUDA][HIP] Add pre-defined macro `__CLANG_RDC__`".
yaxunl edited the summary of this revision.
Herald added a subscriber: carlosgalvezp.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114812/new/
https://reviews.llvm.org/D114812
Files:
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/predefined-macros.c
Index: clang/test/Preprocessor/predefined-macros.c
===================================================================
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -224,17 +224,47 @@
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
-// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP
-// CHECK-HIP-NOT: #define __CUDA_ARCH__
// CHECK-HIP: #define __HIPCC__ 1
-// CHECK-HIP-NOT: #define __HIP_DEVICE_COMPILE__ 1
// CHECK-HIP: #define __HIP__ 1
+// RUN: %clang_cc1 %s -E -dM -o - -x cuda -triple x86_64-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CUDA-NEG
+// CHECK-CUDA-NEG-NOT: #define __CLANG_RDC__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-NEG
+// CHECK-HIP-NEG-NOT: #define __CUDA_ARCH__
+// CHECK-HIP-NEG-NOT: #define __HIP_DEVICE_COMPILE__ 1
+// CHECK-HIP-NEG-NOT: #define __CLANG_RDC__ 1
+
// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \
// RUN: -fcuda-is-device \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-DEV
-// CHECK-HIP-DEV-NOT: #define __CUDA_ARCH__
// CHECK-HIP-DEV: #define __HIPCC__ 1
// CHECK-HIP-DEV: #define __HIP_DEVICE_COMPILE__ 1
// CHECK-HIP-DEV: #define __HIP__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x cuda -triple nvptx \
+// RUN: -fcuda-is-device \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CUDA-DEV-NEG
+// CHECK-CUDA-DEV-NEG-NOT: #define __CLANG_RDC__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \
+// RUN: -fcuda-is-device \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-DEV-NEG
+// CHECK-HIP-DEV-NEG-NOT: #define __CUDA_ARCH__
+// CHECK-HIP-DEV-NEG-NOT: #define __CLANG_RDC__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x cuda -triple x86_64-unknown-linux-gnu \
+// RUN: -fgpu-rdc | FileCheck %s --check-prefix=CHECK-RDC
+// RUN: %clang_cc1 %s -E -dM -o - -x cuda -triple nvptx \
+// RUN: -fgpu-rdc -fcuda-is-device \
+// RUN: | FileCheck %s --check-prefix=CHECK-RDC
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
+// RUN: -fgpu-rdc | FileCheck %s --check-prefix=CHECK-RDC
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \
+// RUN: -fgpu-rdc -fcuda-is-device \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-RDC
+// CHECK-RDC: #define __CLANG_RDC__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -500,8 +500,12 @@
// Not "standard" per se, but available even with the -undef flag.
if (LangOpts.AsmPreprocessor)
Builder.defineMacro("__ASSEMBLER__");
- if (LangOpts.CUDA && !LangOpts.HIP)
- Builder.defineMacro("__CUDA__");
+ if (LangOpts.CUDA) {
+ if (LangOpts.GPURelocatableDeviceCode)
+ Builder.defineMacro("__CLANG_RDC__");
+ if (!LangOpts.HIP)
+ Builder.defineMacro("__CUDA__");
+ }
if (LangOpts.HIP) {
Builder.defineMacro("__HIP__");
Builder.defineMacro("__HIPCC__");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114812.392205.patch
Type: text/x-patch
Size: 3436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211206/34799cc3/attachment.bin>
More information about the cfe-commits
mailing list