@@ -3130,26 +3130,53 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
3130
3130
return ;
3131
3131
}
3132
3132
3133
- if (WorkGroupAttr *ExistingAttr = D->getAttr <WorkGroupAttr>()) {
3134
- ASTContext &Ctx = S.getASTContext ();
3135
- Optional<llvm::APSInt> XDimVal = XDimExpr->getIntegerConstantExpr (Ctx);
3136
- Optional<llvm::APSInt> YDimVal = YDimExpr->getIntegerConstantExpr (Ctx);
3137
- Optional<llvm::APSInt> ZDimVal = ZDimExpr->getIntegerConstantExpr (Ctx);
3138
- Optional<llvm::APSInt> ExistingXDimVal = ExistingAttr->getXDimVal (Ctx);
3139
- Optional<llvm::APSInt> ExistingYDimVal = ExistingAttr->getYDimVal (Ctx);
3140
- Optional<llvm::APSInt> ExistingZDimVal = ExistingAttr->getZDimVal (Ctx);
3141
-
3142
- // Compare attribute arguments value and warn for a mismatch.
3143
- if (ExistingXDimVal != XDimVal || ExistingYDimVal != YDimVal ||
3144
- ExistingZDimVal != ZDimVal) {
3145
- S.Diag (AL.getLoc (), diag::warn_duplicate_attribute) << AL;
3146
- S.Diag (ExistingAttr->getLocation (), diag::note_conflicting_attribute);
3133
+ ASTContext &Ctx = S.getASTContext ();
3134
+
3135
+ if (!XDimExpr->isValueDependent () && !YDimExpr->isValueDependent () &&
3136
+ !ZDimExpr->isValueDependent ()) {
3137
+ llvm::APSInt XDimVal, YDimVal, ZDimVal;
3138
+ ExprResult XDim = S.VerifyIntegerConstantExpression (XDimExpr, &XDimVal);
3139
+ ExprResult YDim = S.VerifyIntegerConstantExpression (YDimExpr, &YDimVal);
3140
+ ExprResult ZDim = S.VerifyIntegerConstantExpression (ZDimExpr, &ZDimVal);
3141
+
3142
+ if (XDim.isInvalid ())
3143
+ return ;
3144
+ XDimExpr = XDim.get ();
3145
+
3146
+ if (YDim.isInvalid ())
3147
+ return ;
3148
+ YDimExpr = YDim.get ();
3149
+
3150
+ if (ZDim.isInvalid ())
3151
+ return ;
3152
+ ZDimExpr = ZDim.get ();
3153
+
3154
+ if (const auto *A = D->getAttr <SYCLIntelNumSimdWorkItemsAttr>()) {
3155
+ int64_t NumSimdWorkItems =
3156
+ A->getValue ()->getIntegerConstantExpr (Ctx)->getSExtValue ();
3157
+
3158
+ if (!(XDimVal.getZExtValue () % NumSimdWorkItems == 0 ||
3159
+ YDimVal.getZExtValue () % NumSimdWorkItems == 0 ||
3160
+ ZDimVal.getZExtValue () % NumSimdWorkItems == 0 )) {
3161
+ S.Diag (A->getLocation (), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
3162
+ << A << AL;
3163
+ S.Diag (AL.getLoc (), diag::note_conflicting_attribute);
3164
+ return ;
3165
+ }
3166
+ }
3167
+ if (const auto *ExistingAttr = D->getAttr <WorkGroupAttr>()) {
3168
+ // Compare attribute arguments value and warn for a mismatch.
3169
+ if (ExistingAttr->getXDimVal (Ctx) != XDimVal ||
3170
+ ExistingAttr->getYDimVal (Ctx) != YDimVal ||
3171
+ ExistingAttr->getZDimVal (Ctx) != ZDimVal) {
3172
+ S.Diag (AL.getLoc (), diag::warn_duplicate_attribute) << AL;
3173
+ S.Diag (ExistingAttr->getLocation (), diag::note_conflicting_attribute);
3174
+ }
3147
3175
}
3176
+ if (!checkWorkGroupSizeValues (S, D, AL))
3177
+ return ;
3148
3178
}
3149
3179
3150
- if (!checkWorkGroupSizeValues (S, D, AL))
3151
- return ;
3152
-
3153
3180
S.addIntelTripleArgAttr <WorkGroupAttr>(D, AL, XDimExpr, YDimExpr, ZDimExpr);
3154
3181
}
3155
3182
@@ -3196,18 +3223,51 @@ static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
3196
3223
}
3197
3224
3198
3225
// Handles num_simd_work_items.
3199
- static void handleNumSimdWorkItemsAttr (Sema &S, Decl *D, const ParsedAttr &A ) {
3226
+ static void handleNumSimdWorkItemsAttr (Sema &S, Decl *D, const ParsedAttr &AL ) {
3200
3227
if (D->isInvalidDecl ())
3201
3228
return ;
3202
3229
3203
- Expr *E = A .getArgAsExpr (0 );
3230
+ Expr *E = AL .getArgAsExpr (0 );
3204
3231
3205
3232
if (D->getAttr <SYCLIntelNumSimdWorkItemsAttr>())
3206
- S.Diag (A .getLoc (), diag::warn_duplicate_attribute) << A ;
3233
+ S.Diag (AL .getLoc (), diag::warn_duplicate_attribute) << AL ;
3207
3234
3208
- S.CheckDeprecatedSYCLAttributeSpelling (A);
3235
+ S.CheckDeprecatedSYCLAttributeSpelling (AL);
3236
+
3237
+ if (!E->isValueDependent ()) {
3238
+ llvm::APSInt ArgVal;
3239
+ ExprResult ICE = S.VerifyIntegerConstantExpression (E, &ArgVal);
3209
3240
3210
- S.addIntelSingleArgAttr <SYCLIntelNumSimdWorkItemsAttr>(D, A, E);
3241
+ if (ICE.isInvalid ())
3242
+ return ;
3243
+
3244
+ E = ICE.get ();
3245
+ int64_t NumSimdWorkItems = ArgVal.getSExtValue ();
3246
+
3247
+ if (NumSimdWorkItems == 0 ) {
3248
+ S.Diag (E->getExprLoc (), diag::err_attribute_argument_is_zero)
3249
+ << AL << E->getSourceRange ();
3250
+ return ;
3251
+ }
3252
+
3253
+ if (const auto *A = D->getAttr <ReqdWorkGroupSizeAttr>()) {
3254
+ ASTContext &Ctx = S.getASTContext ();
3255
+ Optional<llvm::APSInt> XDimVal = A->getXDimVal (Ctx);
3256
+ Optional<llvm::APSInt> YDimVal = A->getYDimVal (Ctx);
3257
+ Optional<llvm::APSInt> ZDimVal = A->getZDimVal (Ctx);
3258
+
3259
+ if (!(XDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3260
+ YDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3261
+ ZDimVal->getZExtValue () % NumSimdWorkItems == 0 )) {
3262
+ S.Diag (AL.getLoc (), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
3263
+ << AL << A;
3264
+ S.Diag (A->getLocation (), diag::note_conflicting_attribute);
3265
+ return ;
3266
+ }
3267
+ }
3268
+ }
3269
+
3270
+ S.addIntelSingleArgAttr <SYCLIntelNumSimdWorkItemsAttr>(D, AL, E);
3211
3271
}
3212
3272
3213
3273
// Handles use_stall_enable_clusters
@@ -5967,14 +6027,13 @@ void Sema::addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &Attr,
5967
6027
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr (getASTContext ());
5968
6028
if (!ArgVal) {
5969
6029
Diag (E->getExprLoc (), diag::err_attribute_argument_type)
5970
- << Attr.getAttrName () << AANT_ArgumentIntegerConstant
5971
- << E->getSourceRange ();
6030
+ << Attr << AANT_ArgumentIntegerConstant << E->getSourceRange ();
5972
6031
return ;
5973
6032
}
5974
6033
int32_t ArgInt = ArgVal->getSExtValue ();
5975
6034
if (ArgInt < 0 ) {
5976
6035
Diag (E->getExprLoc (), diag::err_attribute_requires_positive_integer)
5977
- << Attr. getAttrName () << /* non-negative*/ 1 ;
6036
+ << Attr << /* non-negative*/ 1 ;
5978
6037
return ;
5979
6038
}
5980
6039
}
0 commit comments