From 5255df6b81a2e4b715da5cfa61ef9ff5f009be41 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Tue, 13 Jun 2023 21:38:09 -0700 Subject: [PATCH 01/12] [Driver] Disable PCH inclusion in SYCL device mode. --- .../clang/Basic/DiagnosticDriverKinds.td | 2 + clang/lib/Driver/ToolChains/Clang.cpp | 16 +++++- clang/test/Driver/pch-include-sycl.cpp | 54 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 clang/test/Driver/pch-include-sycl.cpp diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 6492f297ec075..f6e4d6979f963 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -355,6 +355,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error< "'%0' must be used in conjunction with '-fsycl' to enable offloading">; def err_drv_fsycl_with_c_type : Error< "'%0' must not be used in conjunction with '-fsycl', which expects C++ source">; +def err_drv_fsycl_with_pch : Error< + "Precompiled header generation is not supported with '-fsycl'">; def err_drv_fsycl_unsupported_with_opt : Error<"'%0' is not supported with '-fsycl'">; def err_drv_sycl_missing_amdgpu_arch : Error< diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 04142c69c4caf..df2d7138e7940 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1340,6 +1340,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, options::OPT_fno_pch_instantiate_templates, true)) CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates")); } + + bool SYCLDeviceOnly = + Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || + Args.hasArg(options::OPT_fsycl_device_only); + if (YcArg || YuArg) { StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue(); if (!isa(JA)) { @@ -1361,9 +1366,16 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, } bool RenderedImplicitInclude = false; + for (const Arg *A : Args.filtered(options::OPT_clang_i_Group)) { - if (A->getOption().matches(options::OPT_include) && - D.getProbePrecompiled()) { + // Emit an error when PCH file is used in SYCL device mode. + if ((A->getOption().matches(options::OPT_include) && + D.getProbePrecompiled()) || + A->getOption().matches(options::OPT_include_pch)) { + if (SYCLDeviceOnly) { + D.Diag(clang::diag::err_drv_fsycl_with_pch); + } + // Handling of gcc-style gch precompiled headers. bool IsFirstImplicitInclude = !RenderedImplicitInclude; RenderedImplicitInclude = true; diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp new file mode 100644 index 0000000000000..581bf40e097ed --- /dev/null +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -0,0 +1,54 @@ +// This test checks that an error is emitted when +// PCH(Precompiled Header) file is included in -fsycl mode. +// The PCH file is created without the -fsycl option. + +// RUN: touch %t.h + +// RUN: %clang -c -x c++-header %t.h + +// Linux +// -fsycl and -include +// RUN: %clang -fsycl -include %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-SYCL %s +// CHECK-SYCL: Precompiled header generation is not supported with '-fsycl' + +// -fsycl-device-only and -include +// RUN: %clang -fsycl-device-only -include %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY %s +// CHECK-DEVICE-ONLY: Precompiled header generation is not supported with '-fsycl' + +// -fsycl, -fsycl-device-only and -include +// RUN: %clang -fsycl -fsycl-device-only -include %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-BOTH %s +// CHECK-BOTH: Precompiled header generation is not supported with '-fsycl' + +// -fsycl and -include-pch +// RUN: %clang -fsycl -include-pch %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-SYCL-INCLUDE %s +// CHECK-SYCL-INCLUDE: Precompiled header generation is not supported with '-fsycl' + +// -fsycl-device-only and -include-pch +// RUN: %clang -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY-INCLUDE %s +// CHECK-DEVICE-ONLY-INCLUDE: Precompiled header generation is not supported with '-fsycl' + +// -fsycl,-fsycl-device-only and -include-pch +// RUN: %clang -fsycl -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-BOTH-INCLUDE %s +// CHECK-BOTH-INCLUDE: Precompiled header generation is not supported with '-fsycl' + +// Windows +// -fsycl +// RUN: %clang_cl -fsycl --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-YU %s +// CHECK-YU: Precompiled header generation is not supported with '-fsycl' + +// -fsycl-device-only +// RUN: %clang_cl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-YU-DEVICE %s +// CHECK-YU-DEVICE: Precompiled header generation is not supported with '-fsycl' + +// -fsycl and -fsycl-device-only +// RUN: %clang_cl -fsycl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-YU-BOTH %s +// CHECK-YU-BOTH: Precompiled header generation is not supported with '-fsycl' From bc4c6eb4d8e9a02b4df4a389f2f3a5c608c11591 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Wed, 14 Jun 2023 13:57:11 -0700 Subject: [PATCH 02/12] Fix error message. --- .../clang/Basic/DiagnosticDriverKinds.td | 4 ++-- clang/lib/Driver/ToolChains/Clang.cpp | 9 +++------ clang/test/Driver/pch-include-sycl.cpp | 18 +++++++++--------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index f6e4d6979f963..05460b75a1490 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -355,8 +355,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error< "'%0' must be used in conjunction with '-fsycl' to enable offloading">; def err_drv_fsycl_with_c_type : Error< "'%0' must not be used in conjunction with '-fsycl', which expects C++ source">; -def err_drv_fsycl_with_pch : Error< - "Precompiled header generation is not supported with '-fsycl'">; +def err_drv_pch_include_fsycl : Error< + "Precompiled header inclusion is not supported with '-fsycl'">; def err_drv_fsycl_unsupported_with_opt : Error<"'%0' is not supported with '-fsycl'">; def err_drv_sycl_missing_amdgpu_arch : Error< diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index df2d7138e7940..8d60a70c6f06f 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1341,10 +1341,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates")); } - bool SYCLDeviceOnly = - Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || - Args.hasArg(options::OPT_fsycl_device_only); - if (YcArg || YuArg) { StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue(); if (!isa(JA)) { @@ -1372,8 +1368,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, if ((A->getOption().matches(options::OPT_include) && D.getProbePrecompiled()) || A->getOption().matches(options::OPT_include_pch)) { - if (SYCLDeviceOnly) { - D.Diag(clang::diag::err_drv_fsycl_with_pch); + if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || + Args.hasArg(options::OPT_fsycl_device_only)) { + D.Diag(clang::diag::err_drv_pch_include_fsycl); } // Handling of gcc-style gch precompiled headers. diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index 581bf40e097ed..6a24cc58ea608 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -10,45 +10,45 @@ // -fsycl and -include // RUN: %clang -fsycl -include %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SYCL %s -// CHECK-SYCL: Precompiled header generation is not supported with '-fsycl' +// CHECK-SYCL: Precompiled header inclusion is not supported with '-fsycl' // -fsycl-device-only and -include // RUN: %clang -fsycl-device-only -include %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY %s -// CHECK-DEVICE-ONLY: Precompiled header generation is not supported with '-fsycl' +// CHECK-DEVICE-ONLY: Precompiled header inclusion is not supported with '-fsycl' // -fsycl, -fsycl-device-only and -include // RUN: %clang -fsycl -fsycl-device-only -include %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-BOTH %s -// CHECK-BOTH: Precompiled header generation is not supported with '-fsycl' +// CHECK-BOTH: Precompiled header inclusion is not supported with '-fsycl' // -fsycl and -include-pch // RUN: %clang -fsycl -include-pch %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SYCL-INCLUDE %s -// CHECK-SYCL-INCLUDE: Precompiled header generation is not supported with '-fsycl' +// CHECK-SYCL-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' // -fsycl-device-only and -include-pch // RUN: %clang -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY-INCLUDE %s -// CHECK-DEVICE-ONLY-INCLUDE: Precompiled header generation is not supported with '-fsycl' +// CHECK-DEVICE-ONLY-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' // -fsycl,-fsycl-device-only and -include-pch // RUN: %clang -fsycl -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-BOTH-INCLUDE %s -// CHECK-BOTH-INCLUDE: Precompiled header generation is not supported with '-fsycl' +// CHECK-BOTH-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' // Windows // -fsycl // RUN: %clang_cl -fsycl --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-YU %s -// CHECK-YU: Precompiled header generation is not supported with '-fsycl' +// CHECK-YU: Precompiled header inclusion is not supported with '-fsycl' // -fsycl-device-only // RUN: %clang_cl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-YU-DEVICE %s -// CHECK-YU-DEVICE: Precompiled header generation is not supported with '-fsycl' +// CHECK-YU-DEVICE: Precompiled header inclusion is not supported with '-fsycl' // -fsycl and -fsycl-device-only // RUN: %clang_cl -fsycl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-YU-BOTH %s -// CHECK-YU-BOTH: Precompiled header generation is not supported with '-fsycl' +// CHECK-YU-BOTH: Precompiled header inclusion is not supported with '-fsycl' From 2324c5615b7ddaff2e70cfc9a060230a367e7e42 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Thu, 15 Jun 2023 14:19:06 -0700 Subject: [PATCH 03/12] Enable PCH usage with fsycl in host compilation mode. --- clang/lib/Driver/ToolChains/Clang.cpp | 11 +++--- clang/test/Driver/pch-include-sycl.cpp | 46 ++++---------------------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 8d60a70c6f06f..2f9253d37f40d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1368,11 +1368,14 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, if ((A->getOption().matches(options::OPT_include) && D.getProbePrecompiled()) || A->getOption().matches(options::OPT_include_pch)) { - if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) || - Args.hasArg(options::OPT_fsycl_device_only)) { - D.Diag(clang::diag::err_drv_pch_include_fsycl); - } + // Enable PCH inclusion when performing host compilation with -fsycl. + if (JA.isOffloading(Action::OFK_SYCL) && + !JA.isDeviceOffloading(Action::OFK_SYCL)) + ; + // Disable PCH inclusion when performing device compilation with -fsycl. + else if (JA.isDeviceOffloading(Action::OFK_SYCL)) + break; // Handling of gcc-style gch precompiled headers. bool IsFirstImplicitInclude = !RenderedImplicitInclude; RenderedImplicitInclude = true; diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index 6a24cc58ea608..936ecc9652646 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -10,45 +10,11 @@ // -fsycl and -include // RUN: %clang -fsycl -include %t.h -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SYCL %s -// CHECK-SYCL: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl-device-only and -include -// RUN: %clang -fsycl-device-only -include %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY %s -// CHECK-DEVICE-ONLY: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl, -fsycl-device-only and -include -// RUN: %clang -fsycl -fsycl-device-only -include %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-BOTH %s -// CHECK-BOTH: Precompiled header inclusion is not supported with '-fsycl' +// CHECK-SYCL: -fsycl-is-host +// CHECK-SYCL-SAME: -include-pch // -fsycl and -include-pch -// RUN: %clang -fsycl -include-pch %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-SYCL-INCLUDE %s -// CHECK-SYCL-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl-device-only and -include-pch -// RUN: %clang -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-DEVICE-ONLY-INCLUDE %s -// CHECK-DEVICE-ONLY-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl,-fsycl-device-only and -include-pch -// RUN: %clang -fsycl -fsycl-device-only -include-pch %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-BOTH-INCLUDE %s -// CHECK-BOTH-INCLUDE: Precompiled header inclusion is not supported with '-fsycl' - -// Windows -// -fsycl -// RUN: %clang_cl -fsycl --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-YU %s -// CHECK-YU: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl-device-only -// RUN: %clang_cl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-YU-DEVICE %s -// CHECK-YU-DEVICE: Precompiled header inclusion is not supported with '-fsycl' - -// -fsycl and -fsycl-device-only -// RUN: %clang_cl -fsycl -fsycl-device-only --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-YU-BOTH %s -// CHECK-YU-BOTH: Precompiled header inclusion is not supported with '-fsycl' +// RUN: %clang -fsycl -include-pch %t.h.gch -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-PCH %s +// CHECK-PCH: -fsycl-is-host +// CHECK-PCH-SAME: -include-pch From 00f112d0cc0ac38c83e3eb2d93262248a0c52ade Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Thu, 15 Jun 2023 14:22:56 -0700 Subject: [PATCH 04/12] Remove diagnostic. --- clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 -- 1 file changed, 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 05460b75a1490..6492f297ec075 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -355,8 +355,6 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error< "'%0' must be used in conjunction with '-fsycl' to enable offloading">; def err_drv_fsycl_with_c_type : Error< "'%0' must not be used in conjunction with '-fsycl', which expects C++ source">; -def err_drv_pch_include_fsycl : Error< - "Precompiled header inclusion is not supported with '-fsycl'">; def err_drv_fsycl_unsupported_with_opt : Error<"'%0' is not supported with '-fsycl'">; def err_drv_sycl_missing_amdgpu_arch : Error< From f0e2e813fe8f33a6582ea74e236bbd91975929ca Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Fri, 16 Jun 2023 10:20:26 -0700 Subject: [PATCH 05/12] Fix int-footer test failure. --- clang/lib/Driver/ToolChains/Clang.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 2f9253d37f40d..5ca326b0bc666 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1374,7 +1374,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, !JA.isDeviceOffloading(Action::OFK_SYCL)) ; // Disable PCH inclusion when performing device compilation with -fsycl. - else if (JA.isDeviceOffloading(Action::OFK_SYCL)) + else if (JA.isDeviceOffloading(Action::OFK_SYCL) && + Args.hasArg(options::OPT_fno_sycl_use_footer)) break; // Handling of gcc-style gch precompiled headers. bool IsFirstImplicitInclude = !RenderedImplicitInclude; From 756fb8f3d22b8eba9e43c59a80187f4b05a1e280 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Fri, 16 Jun 2023 10:34:42 -0700 Subject: [PATCH 06/12] Add /Yu test case. --- clang/test/Driver/pch-include-sycl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index 936ecc9652646..6e3d3e8a7f7ae 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -18,3 +18,9 @@ // RUN: | FileCheck -check-prefix=CHECK-PCH %s // CHECK-PCH: -fsycl-is-host // CHECK-PCH-SAME: -include-pch + +// Windows +// RUN: %clang_cl -fsycl --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-YU %s +// CHECK-YU: -fsycl-is-host +// CHECK-YU-SAME: -include-pch \ No newline at end of file From 82b3b927df2b0ed657502a7b9fef797bd7a36aee Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Mon, 19 Jun 2023 20:51:02 -0700 Subject: [PATCH 07/12] Add check for -fsycl-is-device in test. --- clang/lib/Driver/ToolChains/Clang.cpp | 6 ++++-- clang/test/Driver/pch-include-sycl.cpp | 29 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 5ca326b0bc666..5bc73bf756382 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1343,7 +1343,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, if (YcArg || YuArg) { StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue(); - if (!isa(JA)) { + // Enable PCH inclusion when performing host compilation with -fsycl. + if (!isa(JA) && JA.isOffloading(Action::OFK_SYCL) && + !JA.isDeviceOffloading(Action::OFK_SYCL)) { CmdArgs.push_back("-include-pch"); CmdArgs.push_back(Args.MakeArgString(D.GetClPchPath( C, !ThroughHeader.empty() @@ -1375,7 +1377,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, ; // Disable PCH inclusion when performing device compilation with -fsycl. else if (JA.isDeviceOffloading(Action::OFK_SYCL) && - Args.hasArg(options::OPT_fno_sycl_use_footer)) + !Args.hasArg(options::OPT_fno_sycl_use_footer)) break; // Handling of gcc-style gch precompiled headers. bool IsFirstImplicitInclude = !RenderedImplicitInclude; diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index 6e3d3e8a7f7ae..94b5b7fff34de 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -1,5 +1,5 @@ -// This test checks that an error is emitted when -// PCH(Precompiled Header) file is included in -fsycl mode. +// This test checks that a PCH(Precompiled Header) file is +// included while performing host compilation in -fsycl mode. // The PCH file is created without the -fsycl option. // RUN: touch %t.h @@ -9,18 +9,25 @@ // Linux // -fsycl and -include // RUN: %clang -fsycl -include %t.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-SYCL %s -// CHECK-SYCL: -fsycl-is-host -// CHECK-SYCL-SAME: -include-pch +// RUN: | FileCheck -check-prefixes=CHECK-SYCL-HOST,CHECK-SYCL-DEVICE %s +// CHECK-SYCL-DEVICE: -fsycl-is-device +// CHECK-SYCL-DEVICE-NOT: -include-pch +// CHECK-SYCL-HOST: -fsycl-is-host +// CHECK-SYCL-HOST-SAME: -include-pch + // -fsycl and -include-pch // RUN: %clang -fsycl -include-pch %t.h.gch -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-PCH %s -// CHECK-PCH: -fsycl-is-host -// CHECK-PCH-SAME: -include-pch +// RUN: | FileCheck -check-prefixes=CHECK-PCH-HOST,CHECK-PCH-DEVICE %s +// CHECK-PCH-DEVICE: -fsycl-is-device +// CHECK-PCH-DEVICE-NOT: -include-pch +// CHECK-PCH-HOST: -fsycl-is-host +// CHECK-PCH-HOST-SAME: -include-pch // Windows // RUN: %clang_cl -fsycl --target=x86_64-unknown-linux-gnu /Yupchfile.h /FIpchfile.h -### %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-YU %s -// CHECK-YU: -fsycl-is-host -// CHECK-YU-SAME: -include-pch \ No newline at end of file +// RUN: | FileCheck -check-prefixes=CHECK-YU-HOST,CHECK-YU-DEVICE %s +// CHECK-YU-DEVICE: -fsycl-is-device +// CHECK-YU-DEVICE-NOT: -include-pch +// CHECK-YU-HOST: -fsycl-is-host +// CHECK-YU-HOST-SAME: -include-pch From 5418e18d238a39d1b324706f3374a5239d554e4b Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Wed, 21 Jun 2023 14:33:03 -0700 Subject: [PATCH 08/12] Include PCH file in SYCL host and non-SYCL compilation. --- clang/lib/Driver/ToolChains/Clang.cpp | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 5bc73bf756382..cab305b15dbee 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1343,9 +1343,15 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, if (YcArg || YuArg) { StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue(); - // Enable PCH inclusion when performing host compilation with -fsycl. - if (!isa(JA) && JA.isOffloading(Action::OFK_SYCL) && - !JA.isDeviceOffloading(Action::OFK_SYCL)) { + // If PCH file is available, include it while performing + // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). + // as well as in non-sycl mode. + bool NonSYCLCompilation = !JA.isOffloading(Action::OFK_SYCL); + bool SYCLHostCompilation = JA.isOffloading(Action::OFK_SYCL) && + !JA.isDeviceOffloading(Action::OFK_SYCL); + + if (!isa(JA) && + (NonSYCLCompilation || SYCLHostCompilation)) { CmdArgs.push_back("-include-pch"); CmdArgs.push_back(Args.MakeArgString(D.GetClPchPath( C, !ThroughHeader.empty() @@ -1371,14 +1377,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, D.getProbePrecompiled()) || A->getOption().matches(options::OPT_include_pch)) { - // Enable PCH inclusion when performing host compilation with -fsycl. - if (JA.isOffloading(Action::OFK_SYCL) && - !JA.isDeviceOffloading(Action::OFK_SYCL)) - ; - // Disable PCH inclusion when performing device compilation with -fsycl. - else if (JA.isDeviceOffloading(Action::OFK_SYCL) && - !Args.hasArg(options::OPT_fno_sycl_use_footer)) - break; // Handling of gcc-style gch precompiled headers. bool IsFirstImplicitInclude = !RenderedImplicitInclude; RenderedImplicitInclude = true; @@ -1398,8 +1396,15 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, FoundPCH = true; } } + // If PCH file is available, include it while performing + // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). + // as well as in non-sycl mode. + bool SYCLHostComp = JA.isOffloading(Action::OFK_SYCL) && + !JA.isDeviceOffloading(Action::OFK_SYCL); + + bool NonSYCLComp = !JA.isOffloading(Action::OFK_SYCL); - if (FoundPCH) { + if (FoundPCH && (SYCLHostComp || NonSYCLComp)) { if (IsFirstImplicitInclude) { A->claim(); CmdArgs.push_back("-include-pch"); @@ -1411,6 +1416,13 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, << A->getAsString(Args); } } + // No PCH file, but we still want to include the header file + // (-include dummy.h) in device compilation mode. + else if (JA.isDeviceOffloading(Action::OFK_SYCL) && + A->getOption().matches(options::OPT_include_pch)) { + continue; + } + } else if (A->getOption().matches(options::OPT_isystem_after)) { // Handling of paths which must come late. These entries are handled by // the toolchain itself after the resource dir is inserted in the right From 34ecd01ba3ce503492c2fb0a6a71d23b220434f5 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Wed, 21 Jun 2023 21:39:37 -0700 Subject: [PATCH 09/12] Add SYCLDeviceCompilation check. --- clang/lib/Driver/ToolChains/Clang.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index cab305b15dbee..6b6503f990b0c 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1346,12 +1346,10 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // If PCH file is available, include it while performing // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). // as well as in non-sycl mode. - bool NonSYCLCompilation = !JA.isOffloading(Action::OFK_SYCL); - bool SYCLHostCompilation = JA.isOffloading(Action::OFK_SYCL) && - !JA.isDeviceOffloading(Action::OFK_SYCL); + bool SYCLDeviceCompilation = JA.isOffloading(Action::OFK_SYCL) && + JA.isDeviceOffloading(Action::OFK_SYCL); - if (!isa(JA) && - (NonSYCLCompilation || SYCLHostCompilation)) { + if (!isa(JA) && !SYCLDeviceCompilation) { CmdArgs.push_back("-include-pch"); CmdArgs.push_back(Args.MakeArgString(D.GetClPchPath( C, !ThroughHeader.empty() @@ -1372,7 +1370,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, bool RenderedImplicitInclude = false; for (const Arg *A : Args.filtered(options::OPT_clang_i_Group)) { - // Emit an error when PCH file is used in SYCL device mode. if ((A->getOption().matches(options::OPT_include) && D.getProbePrecompiled()) || A->getOption().matches(options::OPT_include_pch)) { @@ -1399,12 +1396,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // If PCH file is available, include it while performing // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). // as well as in non-sycl mode. - bool SYCLHostComp = JA.isOffloading(Action::OFK_SYCL) && - !JA.isDeviceOffloading(Action::OFK_SYCL); - bool NonSYCLComp = !JA.isOffloading(Action::OFK_SYCL); + bool SYCLDeviceCompilation = JA.isOffloading(Action::OFK_SYCL) && + JA.isDeviceOffloading(Action::OFK_SYCL); - if (FoundPCH && (SYCLHostComp || NonSYCLComp)) { + if (FoundPCH && !SYCLDeviceCompilation) { if (IsFirstImplicitInclude) { A->claim(); CmdArgs.push_back("-include-pch"); From 6e63155b2ba4946858ee36fad284df06d15106d6 Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Fri, 23 Jun 2023 17:54:12 -0700 Subject: [PATCH 10/12] Update test. --- clang/test/Driver/pch-include-sycl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index 94b5b7fff34de..dac4802b673aa 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -4,7 +4,8 @@ // RUN: touch %t.h -// RUN: %clang -c -x c++-header %t.h +// PCH file. +// RUN: touch %t.h.gch // Linux // -fsycl and -include From ee9457c9444678b35aae5816171277ed3811435e Mon Sep 17 00:00:00 2001 From: srividya sundaram Date: Mon, 26 Jun 2023 09:37:26 -0700 Subject: [PATCH 11/12] Remove redundant code. --- clang/lib/Driver/ToolChains/Clang.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6b6503f990b0c..f17ae631c20ee 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1124,6 +1124,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, const InputInfoList &Inputs) const { const bool IsIAMCU = getToolChain().getTriple().isOSIAMCU(); const bool IsIntelFPGA = Args.hasArg(options::OPT_fintelfpga); + bool SYCLDeviceCompilation = JA.isOffloading(Action::OFK_SYCL) && + JA.isDeviceOffloading(Action::OFK_SYCL); CheckPreprocessingOptions(D, Args); @@ -1346,8 +1348,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // If PCH file is available, include it while performing // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). // as well as in non-sycl mode. - bool SYCLDeviceCompilation = JA.isOffloading(Action::OFK_SYCL) && - JA.isDeviceOffloading(Action::OFK_SYCL); if (!isa(JA) && !SYCLDeviceCompilation) { CmdArgs.push_back("-include-pch"); @@ -1397,9 +1397,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // host compilation (-fsycl-is-host) in SYCL mode (-fsycl). // as well as in non-sycl mode. - bool SYCLDeviceCompilation = JA.isOffloading(Action::OFK_SYCL) && - JA.isDeviceOffloading(Action::OFK_SYCL); - if (FoundPCH && !SYCLDeviceCompilation) { if (IsFirstImplicitInclude) { A->claim(); From fdafed160427cd0e5527e723957ae062c9df891f Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Tue, 27 Jun 2023 09:16:15 -0700 Subject: [PATCH 12/12] Update pch-include-sycl.cpp --- clang/test/Driver/pch-include-sycl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/test/Driver/pch-include-sycl.cpp b/clang/test/Driver/pch-include-sycl.cpp index dac4802b673aa..06b5b00048bd7 100644 --- a/clang/test/Driver/pch-include-sycl.cpp +++ b/clang/test/Driver/pch-include-sycl.cpp @@ -1,6 +1,5 @@ // This test checks that a PCH(Precompiled Header) file is // included while performing host compilation in -fsycl mode. -// The PCH file is created without the -fsycl option. // RUN: touch %t.h