Skip to content

Commit e343510

Browse files
committed
[SYCL] Enable Open CL types required for implementing the SYCL headers.
This patch implements a few of the OpenCL types for SYCL, however doesn't bother handling semantic analysis as these are not intended to be used anywhere but in the SYCL implementation. Signed-off-by: Erich Keane <[email protected]> Differential Revision: https://reviews.llvm.org/D77220
1 parent b20e9f4 commit e343510

File tree

11 files changed

+781
-8
lines changed

11 files changed

+781
-8
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,15 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
14231423
InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
14241424
InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel);
14251425

1426+
if (LangOpts.SYCLIsDevice) {
1427+
InitBuiltinType(OCLSamplerTy, BuiltinType::OCLSampler);
1428+
InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent);
1429+
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1430+
InitBuiltinType(SingletonId, BuiltinType::Id);
1431+
#include "clang/Basic/OpenCLImageTypes.def"
1432+
#undef IMAGE_TYPE
1433+
}
1434+
14261435
if (LangOpts.OpenCL) {
14271436
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
14281437
InitBuiltinType(SingletonId, BuiltinType::Id);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO,
139139

140140
if (LangOpts.ObjC)
141141
createObjCRuntime();
142-
if (LangOpts.OpenCL)
142+
if (LangOpts.OpenCL || LangOpts.SYCLIsDevice)
143143
createOpenCLRuntime();
144144
if (LangOpts.OpenMP)
145145
createOpenMPRuntime();

clang/lib/Sema/Sema.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ void Sema::Initialize() {
317317
addImplicitTypedef("size_t", Context.getSizeType());
318318
}
319319

320+
if (getLangOpts().SYCLIsDevice) {
321+
addImplicitTypedef("__ocl_sampler_t", Context.OCLSamplerTy);
322+
addImplicitTypedef("__ocl_event_t", Context.OCLEventTy);
323+
#define SEMA_STRINGIZE(s) #s
324+
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
325+
addImplicitTypedef(SEMA_STRINGIZE(__ocl_##ImgType##_##Suffix##_t), \
326+
Context.SingletonId);
327+
#include "clang/Basic/OpenCLImageTypes.def"
328+
#undef SEMA_STRINGIZE
329+
}
330+
320331
// Initialize predefined OpenCL types and supported extensions and (optional)
321332
// core features.
322333
if (getLangOpts().OpenCL) {

clang/lib/Sema/SemaInit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5579,9 +5579,10 @@ static bool TryOCLSamplerInitialization(Sema &S,
55795579
InitializationSequence &Sequence,
55805580
QualType DestType,
55815581
Expr *Initializer) {
5582-
if (!S.getLangOpts().OpenCL || !DestType->isSamplerT() ||
5582+
if ((!S.getLangOpts().OpenCL && !S.getLangOpts().SYCLIsDevice) ||
5583+
!DestType->isSamplerT() ||
55835584
(!Initializer->isIntegerConstantExpr(S.Context) &&
5584-
!Initializer->getType()->isSamplerT()))
5585+
!Initializer->getType()->isSamplerT()))
55855586
return false;
55865587

55875588
Sequence.AddOCLSamplerInitStep(DestType);

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class Util {
6363
/// Checks whether given clang type is a full specialization of the SYCL
6464
/// accessor class.
6565
static bool isSyclAccessorType(const QualType &Ty);
66+
/// Checks whether given clang type is a full specialization of the SYCL
67+
/// sampler class.
68+
static bool isSyclSamplerType(const QualType &Ty);
6669

6770
/// Checks whether given clang type is declared in the given hierarchy of
6871
/// declaration contexts.
@@ -258,7 +261,8 @@ static CompoundStmt *CreateOpenCLKernelBody(Sema &S,
258261
CXXRecordDecl *CRD = FieldType->getAsCXXRecordDecl();
259262
InitializedEntity Entity =
260263
InitializedEntity::InitializeMember(Field, &VarEntity);
261-
if (Util::isSyclAccessorType(FieldType)) {
264+
if (Util::isSyclAccessorType(FieldType) ||
265+
Util::isSyclSamplerType(FieldType)) {
262266
// Initialize kernel object field with the default constructor and
263267
// construct a call of __init method.
264268
InitializationKind InitKind =
@@ -369,7 +373,7 @@ static void buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj,
369373
// and add parameter decriptor for them properly.
370374
for (const auto *Fld : KernelObj->fields()) {
371375
QualType ArgTy = Fld->getType();
372-
if (Util::isSyclAccessorType(ArgTy))
376+
if (Util::isSyclAccessorType(ArgTy) || Util::isSyclSamplerType(ArgTy))
373377
createSpecialSYCLObjParamDesc(Fld, ArgTy);
374378
else if (ArgTy->isStructureOrClassType())
375379
CreateAndAddPrmDsc(Fld, ArgTy);
@@ -455,6 +459,15 @@ bool Util::isSyclAccessorType(const QualType &Ty) {
455459
return matchQualifiedTypeName(Ty, Scopes);
456460
}
457461

462+
bool Util::isSyclSamplerType(const QualType &Ty) {
463+
static const std::array<DeclContextDesc, 3> Scopes = {
464+
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
465+
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
466+
Util::DeclContextDesc{clang::Decl::Kind::CXXRecord,
467+
"sampler"}};
468+
return matchQualifiedTypeName(Ty, Scopes);
469+
}
470+
458471
bool Util::matchQualifiedTypeName(const QualType &Ty,
459472
ArrayRef<Util::DeclContextDesc> Scopes) {
460473
// The idea: check the declaration context chain starting from the type

0 commit comments

Comments
 (0)