Skip to content

[SYCL] Set preprocessor macros in integration header #4823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,24 +486,10 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__FAST_RELAXED_MATH__");
}

if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) {
// SYCL Version is set to a value when building SYCL applications
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017) {
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "201707");
} else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");

if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost)
if (LangOpts.SYCLValueFitInMaxInt)
Builder.defineMacro("__SYCL_ID_QUERIES_FIT_IN_INT__");

// Set __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ macro for
// both host and device compilations if -fsycl-disable-range-rounding
// flag is used.
if (LangOpts.SYCLDisableRangeRounding)
Builder.defineMacro("__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__");
}

if (LangOpts.DeclareSPIRVBuiltins) {
Builder.defineMacro("__SPIRV_BUILTIN_DECLARATIONS__");
}
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4747,6 +4747,19 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
Policy.SuppressUnwrittenScope = true;
SYCLFwdDeclEmitter FwdDeclEmitter(O, S.getLangOpts());

// Predefines which need to be set for custom host compilation
// must be defined in integration header.
if (S.getLangOpts().getSYCLVersion() == LangOptions::SYCL_2017) {
O << "#define CL_SYCL_LANGUAGE_VERSION 121\n";
O << "#define SYCL_LANGUAGE_VERSION 201707\n";
} else if (S.LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
O << "#define SYCL_LANGUAGE_VERSION 202001\n";

if (S.getLangOpts().SYCLDisableRangeRounding)
O << "#define __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ 1\n";

O << "\n";

if (SpecConsts.size() > 0) {
O << "// Forward declarations of templated spec constant types:\n";
for (const auto &SC : SpecConsts)
Expand Down
29 changes: 29 additions & 0 deletions clang/test/CodeGenSYCL/integration_header_ppmacros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -sycl-std=2020 -fsycl-int-header=%t.h %s
// RUN: FileCheck -input-file=%t.h %s --check-prefix=CHECK-SYCL2020
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -sycl-std=2017 -fsycl-int-header=%t.h %s
// RUN: FileCheck -input-file=%t.h %s --check-prefix=CHECK-SYCL2017
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -fsycl-disable-range-rounding -fsycl-int-header=%t.h %s
// RUN: FileCheck -input-file=%t.h %s --check-prefix=CHECK-RANGE
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -fsycl-int-header=%t.h %s
// RUN: FileCheck -input-file=%t.h %s --check-prefix=CHECK-NO-RANGE

// Test verifying predefines which need to be set for host and device compilation.
// Preprocessor macros which are required when using custom host compiler must be
// defined in integration header.

#include "Inputs/sycl.hpp"

int main() {
cl::sycl::kernel_single_task<class first_kernel>([]() {});
}

// CHECK-SYCL2020: #define SYCL_LANGUAGE_VERSION 202001
// CHECK-SYCL2020-NOT: #define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL2020-NOT: #define SYCL_LANGUAGE_VERSION 201707

// CHECK-SYCL2017: #define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL2017: #define SYCL_LANGUAGE_VERSION 201707
// CHECK-SYCL2017-NOT: #define SYCL_LANGUAGE_VERSION 202001

// CHECK-RANGE: #define __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ 1
// CHECK-NO-RANGE-NOT: #define __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ 1
28 changes: 0 additions & 28 deletions clang/test/Preprocessor/predefined-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,3 @@
// 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 -fsycl-is-device \
// RUN: -triple spir64-unknown-unknown -fsycl-disable-range-rounding -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-RANGE

// RUN: %clang_cc1 %s -E -dM -fsycl-is-device \
// RUN: -triple spir64_fpga-unknown-unknown -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-NO-RANGE

// RUN: %clang_cc1 %s -E -dM -fsycl-is-device -fsycl-disable-range-rounding \
// RUN: -triple spir64_fpga-unknown-unknown -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-RANGE

// RUN: %clang_cc1 %s -E -dM -fsycl-is-device -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-NO-RANGE

// RUN: %clang_cc1 %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-NO-RANGE

// RUN: %clang_cc1 %s -E -dM -fsycl-is-host \
// RUN: -triple x86_64-unknown-linux-gnu -fsycl-disable-range-rounding -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-RANGE

// RUN: %clang_cc1 %s -E -dM -fsycl-is-host -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-NO-RANGE

// CHECK-RANGE: #define __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ 1
// CHECK-NO-RANGE-NOT: #define __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ 1
26 changes: 6 additions & 20 deletions clang/test/Preprocessor/sycl-macro.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
// RUN: %clang_cc1 %s -E -dM | FileCheck %s
// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-SYCL-ID %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-host -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-host -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-host -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-DEVICE %s
// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-SYCL-FIT-IN-INT %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-host -E -dM | FileCheck --check-prefix=CHECK-SYCL-FIT-IN-INT %s
// RUN: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-SYCL-FIT-IN-INT %s
// RUNx: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -E -dM -fms-compatibility | FileCheck --check-prefix=CHECK-MSVC %s
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-NO-SYCL_FIT_IN_INT %s
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck --check-prefix=CHECK-NO-SYCL-FIT-IN-INT %s

// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-NOT:#define SYCL_EXTERNAL
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL-STD:#define SYCL_LANGUAGE_VERSION 201707
// CHECK-SYCL-STD:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001

// CHECK-SYCL-STD-DEVICE:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-SYCL-STD-DEVICE:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
// CHECK-SYCL-FIT-IN-INT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-MSVC-NOT: __GNUC__
// CHECK-MSVC-NOT: __STDC__
// CHECK-MSVC: #define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
// CHECK-SYCL-ID:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
// CHECK-NO-SYCL-FIT-IN-INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1