-
Notifications
You must be signed in to change notification settings - Fork 768
[SYCL] Enable OpenCL diagnostics for sampler in SYCL mode #167
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6347,6 +6347,26 @@ NamedDecl *Sema::ActOnVariableDeclarator( | |
return nullptr; | ||
} | ||
|
||
if (R->isSamplerT()) { | ||
// OpenCL v1.2 s6.9.b p4: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment looks stange. We implement some OpenCL restrictions but not only for OpenCL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I can't find any restrictions for sampler in SYCL spec. I think we can leave comment describes that SYCL re-uses OpenCL types so these restrictions applied for SYCL too but it's not necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: the restriction is enabled for all languages, which allows sampler type. I don't think explicitly mentioning SYCL here is good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. So, why we are explicitly mentioning OpenCL here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the place where the behavior of this type is defined. |
||
// The sampler type cannot be used with the __local and __global address | ||
// space qualifiers. | ||
if (R.getAddressSpace() == LangAS::opencl_local || | ||
R.getAddressSpace() == LangAS::opencl_global) { | ||
Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace); | ||
} | ||
|
||
// OpenCL v1.2 s6.12.14.1: | ||
// A global sampler must be declared with either the constant address | ||
// space qualifier or with the const qualifier. | ||
if (DC->isTranslationUnit() && | ||
!(R.getAddressSpace() == LangAS::opencl_constant || | ||
R.isConstQualified())) { | ||
Diag(D.getIdentifierLoc(), diag::err_opencl_nonconst_global_sampler); | ||
D.setInvalidType(); | ||
} | ||
} | ||
|
||
if (getLangOpts().OpenCL) { | ||
// OpenCL v2.0 s6.9.b - Image type can only be used as a function argument. | ||
// OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function | ||
|
@@ -6392,26 +6412,6 @@ NamedDecl *Sema::ActOnVariableDeclarator( | |
} | ||
} | ||
|
||
if (R->isSamplerT()) { | ||
// OpenCL v1.2 s6.9.b p4: | ||
// The sampler type cannot be used with the __local and __global address | ||
// space qualifiers. | ||
if (R.getAddressSpace() == LangAS::opencl_local || | ||
R.getAddressSpace() == LangAS::opencl_global) { | ||
Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace); | ||
} | ||
|
||
// OpenCL v1.2 s6.12.14.1: | ||
// A global sampler must be declared with either the constant address | ||
// space qualifier or with the const qualifier. | ||
if (DC->isTranslationUnit() && | ||
!(R.getAddressSpace() == LangAS::opencl_constant || | ||
R.isConstQualified())) { | ||
Diag(D.getIdentifierLoc(), diag::err_opencl_nonconst_global_sampler); | ||
D.setInvalidType(); | ||
} | ||
} | ||
|
||
// OpenCL v1.2 s6.9.r: | ||
// The event type cannot be used with the __local, __constant and __global | ||
// address space qualifiers. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5319,9 +5319,9 @@ static bool TryOCLSamplerInitialization(Sema &S, | |
InitializationSequence &Sequence, | ||
QualType DestType, | ||
Expr *Initializer) { | ||
if (!S.getLangOpts().OpenCL || !DestType->isSamplerT() || | ||
if (!DestType->isSamplerT() || | ||
(!Initializer->isIntegerConstantExpr(S.Context) && | ||
!Initializer->getType()->isSamplerT())) | ||
!Initializer->getType()->isSamplerT())) | ||
return false; | ||
|
||
Sequence.AddOCLSamplerInitStep(DestType); | ||
|
@@ -5634,6 +5634,9 @@ void InitializationSequence::InitializeFrom(Sema &S, | |
bool allowObjCWritebackConversion = S.getLangOpts().ObjCAutoRefCount && | ||
Entity.isParameterKind(); | ||
|
||
if (TryOCLSamplerInitialization(S, *this, DestType, Initializer)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, could you please clarify: why do you need this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To enable sampler initialization diagnostics in SYCL mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I didn't see why it can't work on old place. I will expand hidden code next time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Event type diagnostics should be enabled separately. |
||
return; | ||
|
||
// We're at the end of the line for C: it's either a write-back conversion | ||
// or it's a C assignment. There's no need to check anything else. | ||
if (!S.getLangOpts().CPlusPlus) { | ||
|
@@ -5643,9 +5646,6 @@ void InitializationSequence::InitializeFrom(Sema &S, | |
return; | ||
} | ||
|
||
if (TryOCLSamplerInitialization(S, *this, DestType, Initializer)) | ||
return; | ||
|
||
if (TryOCLZeroOpaqueTypeInitialization(S, *this, DestType, Initializer)) | ||
return; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2322,7 +2322,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, | |
// OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported. | ||
// OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported. | ||
// OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported. | ||
if (getLangOpts().OpenCL) { | ||
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the logic:
Can't we remove getLangOpts checks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. |
||
const QualType ArrType = Context.getBaseElementType(T); | ||
if (ArrType->isBlockPointerType() || ArrType->isPipeType() || | ||
ArrType->isSamplerT() || ArrType->isImageType()) { | ||
|
@@ -4409,7 +4409,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, | |
// OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used. | ||
// OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used. | ||
// OpenCL v2.0 s6.12.5 - Pointers to Blocks are not allowed. | ||
if (LangOpts.OpenCL) { | ||
if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) { | ||
if (T->isImageType() || T->isSamplerT() || T->isPipeType() || | ||
T->isBlockPointerType()) { | ||
S.Diag(D.getIdentifierLoc(), diag::err_opencl_pointer_to_type) << T; | ||
|
@@ -4607,7 +4607,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, | |
} | ||
} | ||
|
||
if (LangOpts.OpenCL) { | ||
if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) { | ||
// OpenCL v2.0 s6.12.5 - A block cannot be the return value of a | ||
// function. | ||
if (T->isBlockPointerType() || T->isImageType() || T->isSamplerT() || | ||
|
@@ -4619,7 +4619,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, | |
// OpenCL doesn't support variadic functions and blocks | ||
// (s6.9.e and s6.12.5 OpenCL v2.0) except for printf. | ||
// We also allow here any toolchain reserved identifiers. | ||
// FIXME: Use deferred diagnostics engine to skip host side issues. | ||
if (FTI.isVariadic && | ||
!LangOpts.SYCLIsDevice && | ||
!(D.getIdentifier() && | ||
((D.getIdentifier()->getName() == "printf" && | ||
(LangOpts.OpenCLCPlusPlus || LangOpts.OpenCLVersion >= 120)) || | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we guard this code under
if (getLangOpts().SYCLIsDevice || getLangOpts().OpenCL)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sampler type is enabled only for OpenCL and SYCL modes, so if
R->isSamplerT()
returnstrue
, we know thatgetLangOpts().SYCLIsDevice || getLangOpts().OpenCL
is alsotrue
.There might be some other environments which might be interested in enabling this data type, so if they what to disable this diagnostics they will have to extend the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this code already was under
if (getLangOpts().OpenCL)
, maybe this if could help to understand this code in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AnastasiaStulova asked for applying changes like this as removing redundant checks should speed-up compilation.