Skip to content

Commit eb02d3c

Browse files
committed
[SYCL] Fix builtins address space type
This patch fixes the `core/GroupAsyncCopy.cl` and `ocl/prefetch.cl` lit tests in `libclc`. These started failing with the introduction of the SYCL address spaces in #3634. The issue is that the builtins are declared with the SYCL address spaces in the tablegen so when used in an OpenCL setting it ends up with address space mismatches between things like `opencl_global` and `sycl_global`. These two were the only tests affected because they're also the only tested builtins that do not have generic address space variants in tablegen, the other tests would just fall back on the generic address space variants. With this patch the builtins should automatically get the appropriate version of the address space depending on the context.
1 parent e8f2166 commit eb02d3c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

clang/include/clang/Basic/AddressSpaces.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@ inline bool isPtrSizeAddressSpace(LangAS AS) {
8787
AS == LangAS::ptr64);
8888
}
8989

90+
inline LangAS getLangASasSYCLLangAS(LangAS AS) {
91+
switch (AS) {
92+
case LangAS::opencl_global:
93+
return LangAS::sycl_global;
94+
case LangAS::opencl_global_device:
95+
return LangAS::sycl_global_device;
96+
case LangAS::opencl_global_host:
97+
return LangAS::sycl_global_host;
98+
case LangAS::opencl_local:
99+
return LangAS::sycl_local;
100+
case LangAS::opencl_private:
101+
return LangAS::sycl_private;
102+
default:
103+
return AS;
104+
}
105+
}
106+
107+
inline LangAS getLangASasOpenCLLangAS(LangAS AS) {
108+
switch (AS) {
109+
case LangAS::sycl_global:
110+
return LangAS::opencl_global;
111+
case LangAS::sycl_global_device:
112+
return LangAS::opencl_global_device;
113+
case LangAS::sycl_global_host:
114+
return LangAS::opencl_global_host;
115+
case LangAS::sycl_local:
116+
return LangAS::opencl_local;
117+
case LangAS::sycl_private:
118+
return LangAS::opencl_private;
119+
default:
120+
return AS;
121+
}
122+
}
123+
90124
} // namespace clang
91125

92126
#endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H

clang/utils/TableGen/ClangProgModelBuiltinEmitter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,10 @@ static QualType getOpenCLTypedefType(Sema &S, llvm::StringRef Name);
958958
// [const|volatile] pointers, so this is ok to do it as a last step.
959959
if (Ty.IsPointer != 0) {
960960
for (unsigned Index = 0; Index < QT.size(); Index++) {
961-
QT[Index] = Context.getAddrSpaceQualType(QT[Index], Ty.AS);
961+
QT[Index] = Context.getAddrSpaceQualType(
962+
QT[Index], S.getLangOpts().SYCLIsDevice
963+
? getLangASasSYCLLangAS(Ty.AS)
964+
: getLangASasOpenCLLangAS(Ty.AS));
962965
QT[Index] = Context.getPointerType(QT[Index]);
963966
}
964967
}

0 commit comments

Comments
 (0)