[clang] d55f05d - [CUDA][HIP] Add pre-defined macro `__CLANG_RDC__`
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 7 15:09:55 PST 2021
Author: Yaxun (Sam) Liu
Date: 2021-12-07T18:08:16-05:00
New Revision: d55f05d9f7dc8aa0468a9db19d84671acf05823a
URL: https://github.com/llvm/llvm-project/commit/d55f05d9f7dc8aa0468a9db19d84671acf05823a
DIFF: https://github.com/llvm/llvm-project/commit/d55f05d9f7dc8aa0468a9db19d84671acf05823a.diff
LOG: [CUDA][HIP] Add pre-defined macro `__CLANG_RDC__`
nvcc defines __CUDACC_RDC__ for both host and
device compilation when -rdc=true is specified
(https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-identification-macro)
This patch defines __CLANG_RDC__ when -fgpu-rdc
is specified for CUDA/HIP.
Reviewed by: Artem Belevich
Differential Revision: https://reviews.llvm.org/D114812
Added:
Modified:
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/predefined-macros.c
Removed:
################################################################################
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 0c153446142ef..629f991106616 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -500,8 +500,12 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
// 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__");
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
index 46dd76b6fc567..2304eb82b50df 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/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
More information about the cfe-commits
mailing list