Skip to content

Commit 881724f

Browse files
author
Erich Keane
authored
[SYCL] Don't emit #include's for int-footer if it is empty.
This apparently causes some self-build issues and some potential regressions, so it is useful to make sure that includes don't happen unless we really need them.
1 parent 55a1b08 commit 881724f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,9 +4983,8 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
49834983
Policy.SuppressTypedefs = true;
49844984
Policy.SuppressUnwrittenScope = true;
49854985

4986-
OS << "#include <CL/sycl/detail/defines_elementary.hpp>\n";
4987-
49884986
llvm::SmallSet<const VarDecl *, 8> VisitedSpecConstants;
4987+
bool EmittedFirstSpecConstant = false;
49894988

49904989
// Used to uniquely name the 'shim's as we generate the names in each
49914990
// anonymous namespace.
@@ -5002,6 +5001,12 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
50025001
if (llvm::find(VisitedSpecConstants, VD) != VisitedSpecConstants.end())
50035002
continue;
50045003

5004+
// We only want to emit the #includes if we have a spec-constant that needs
5005+
// them, so emit this one on the first time through the loop.
5006+
if (!EmittedFirstSpecConstant)
5007+
OS << "#include <CL/sycl/detail/defines_elementary.hpp>\n";
5008+
EmittedFirstSpecConstant = true;
5009+
50055010
VisitedSpecConstants.insert(VD);
50065011
std::string TopShim = EmitSpecIdShims(OS, ShimCounter, Policy, VD);
50075012
OS << "__SYCL_INLINE_NAMESPACE(cl) {\n";
@@ -5027,7 +5032,8 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
50275032
OS << "} // __SYCL_INLINE_NAMESPACE(cl)\n";
50285033
}
50295034

5030-
OS << "#include <CL/sycl/detail/spec_const_integration.hpp>\n";
5035+
if (EmittedFirstSpecConstant)
5036+
OS << "#include <CL/sycl/detail/spec_const_integration.hpp>\n";
50315037

50325038
return true;
50335039
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -fsycl-int-footer=%t.h %s -emit-llvm -o %t.ll
2+
// RUN: FileCheck -input-file=%t.h %s --allow-empty
3+
4+
// CHECK-NOT: #include <CL/sycl/detail/defines_elementary.hpp>
5+
// CHECK-NOT: #include <CL/sycl/detail/spec_const_integration.hpp>

0 commit comments

Comments
 (0)