Skip to content

Commit a4685ba

Browse files
author
Artem Gindinson
committed
[NFC] Move macro initialization to device FE
Signed-off-by: Artem Gindinson <[email protected]>
1 parent ee4dc64 commit a4685ba

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,21 +4676,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46764676
if (HasFPGA)
46774677
CmdArgs.push_back("-fsycl-disable-range-rounding");
46784678

4679-
const auto &DeviceTriple = getToolChain().getTriple();
4680-
const auto &DeviceSubArch = DeviceTriple.getSubArch();
46814679
// Enable generation of USM address spaces for FPGA.
46824680
// __ENABLE_USM_ADDR_SPACE__ will be used during compilation of SYCL headers
4683-
if (DeviceSubArch == llvm::Triple::SPIRSubArch_fpga)
4681+
if (getToolChain().getTriple().getSubArch() ==
4682+
llvm::Triple::SPIRSubArch_fpga)
46844683
CmdArgs.push_back("-D__ENABLE_USM_ADDR_SPACE__");
46854684

4686-
// Use native FP atomics on supported targets by default.
4687-
// TODO: Currently, only OpenCL CPU and Intel GPU support the functions.
4688-
// Allow other targets through check once/if support for
4689-
// SPV_EXT_shader_atomic_float* extensions lands there.
4690-
if (DeviceTriple.isSPIR() &&
4691-
DeviceSubArch != llvm::Triple::SPIRSubArch_fpga)
4692-
CmdArgs.push_back("-DSYCL_USE_NATIVE_FP_ATOMICS");
4693-
46944685
// Add any options that are needed specific to SYCL offload while
46954686
// performing the host side compilation.
46964687
if (!IsSYCLOffloadDevice) {

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,14 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11791179
Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
11801180
Builder.defineMacro("SYCL_EXTERNAL", "__attribute__((sycl_device))");
11811181

1182-
if (TI.getTriple().isNVPTX()) {
1183-
Builder.defineMacro("__SYCL_NVPTX__", "1");
1182+
const llvm::Triple &DeviceTriple = TI.getTriple();
1183+
if (DeviceTriple.isNVPTX()) {
1184+
Builder.defineMacro("__SYCL_NVPTX__", "1");
1185+
}
1186+
const llvm::Triple::SubArchType DeviceSubArch = DeviceTriple.getSubArch();
1187+
if (DeviceTriple.isSPIR() &&
1188+
DeviceSubArch != llvm::Triple::SPIRSubArch_fpga) {
1189+
Builder.defineMacro("SYCL_USE_NATIVE_FP_ATOMICS");
11841190
}
11851191
}
11861192
if (LangOpts.SYCLUnnamedLambda)

clang/test/Driver/sycl-offload-fp-atomics.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -E -dM \
2+
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS %s
3+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_gen-unknown-unknown-sycldevice -E -dM \
4+
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS %s
5+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_x86_64-unknown-unknown-sycldevice -E -dM \
6+
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS %s
7+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_fpga-unknown-unknown-sycldevice -E -dM \
8+
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS-NEG %s
9+
// RUN: %clang_cc1 %s -fsycl-is-device -triple nvptx64-nvidia-nvcl-sycldevice -E -dM \
10+
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS-NEG %s
11+
12+
// CHECK-SYCL-FP-ATOMICS: #define SYCL_USE_NATIVE_FP_ATOMICS
13+
// CHECK-SYCL-FP-ATOMICS-NEG-NOT: #define SYCL_USE_NATIVE_FP_ATOMICS

0 commit comments

Comments
 (0)