Skip to content

Commit 3da22a2

Browse files
committed
Merge remote-tracking branch 'intel_llvm/sycl' into public_vklochkov_reduction_2020
2 parents 0cdf646 + 78a0b19 commit 3da22a2

File tree

14 files changed

+486
-147
lines changed

14 files changed

+486
-147
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,8 +2421,8 @@ device kernel, the attribute is not ignored and it is propagated to the kernel.
24212421
If the`` intel::reqd_work_group_size`` or ``cl::reqd_work_group_size``
24222422
attribute is specified on a declaration along with a
24232423
intel::num_simd_work_items attribute, the work group size attribute
2424-
arguments must all be evenly divisible by the argument specified in
2425-
the ``intel::num_simd_work_items`` attribute.
2424+
argument (the first argument) must be evenly divisible by the argument specified
2425+
in the ``intel::num_simd_work_items`` attribute.
24262426

24272427
.. code-block:: c++
24282428

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4296,7 +4296,10 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Optio
42964296
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
42974297
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
42984298
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">, ShouldParseIf<fsycl.KeyPath>, AutoNormalizeEnum;
4299-
defm sycl_esimd: OptInFFlag<"sycl-explicit-simd", "Enable", "Disable", " SYCL explicit SIMD extension.", [CC1Option,CoreOption], LangOpts<"SYCLExplicitSIMD">>;
4299+
defm sycl_esimd: BoolFOption<"sycl-explicit-simd",
4300+
LangOpts<"SYCLExplicitSIMD">, DefaultFalse,
4301+
PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,
4302+
BothFlags<[NoArgumentUnused, CoreOption], " SYCL explicit SIMD extension.">>;
43004303
defm sycl_early_optimizations : OptOutFFlag<"sycl-early-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler", [CoreOption]>;
43014304
def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
43024305
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,8 +3471,6 @@ class Sema final {
34713471
EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D,
34723472
const EnforceTCBLeafAttr &AL);
34733473

3474-
SYCLIntelLoopFuseAttr *
3475-
mergeSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E);
34763474
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
34773475
AvailabilityMergeKind AMK = AMK_Redeclaration);
34783476
void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
@@ -10232,6 +10230,10 @@ class Sema final {
1023210230
Expr *E);
1023310231
SYCLIntelNoGlobalWorkOffsetAttr *MergeSYCLIntelNoGlobalWorkOffsetAttr(
1023410232
Decl *D, const SYCLIntelNoGlobalWorkOffsetAttr &A);
10233+
void AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
10234+
Expr *E);
10235+
SYCLIntelLoopFuseAttr *
10236+
MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A);
1023510237

1023610238
/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
1023710239
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
@@ -10286,8 +10288,6 @@ class Sema final {
1028610288
/// addSYCLIntelPipeIOAttr - Adds a pipe I/O attribute to a particular
1028710289
/// declaration.
1028810290
void addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &CI, Expr *ID);
10289-
void addSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
10290-
Expr *E);
1029110291

1029210292
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type);
1029310293
bool checkAllowedSYCLInitializer(VarDecl *VD,

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
983983

984984
if (getLangOpts().SYCLIsDevice && D) {
985985
if (const auto *A = D->getAttr<SYCLIntelLoopFuseAttr>()) {
986-
Expr *E = A->getValue();
986+
const auto *CE = cast<ConstantExpr>(A->getValue());
987+
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
987988
llvm::Metadata *AttrMDArgs[] = {
988-
llvm::ConstantAsMetadata::get(Builder.getInt32(
989-
E->getIntegerConstantExpr(D->getASTContext())->getZExtValue())),
989+
llvm::ConstantAsMetadata::get(
990+
Builder.getInt32(ArgVal->getZExtValue())),
990991
llvm::ConstantAsMetadata::get(
991992
A->isIndependent() ? Builder.getInt32(1) : Builder.getInt32(0))};
992993
Fn->setMetadata("loop_fuse",

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,8 +2612,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
26122612
NewAttr = S.mergeImportModuleAttr(D, *IMA);
26132613
else if (const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(Attr))
26142614
NewAttr = S.mergeImportNameAttr(D, *INA);
2615-
else if (const auto *LFA = dyn_cast<SYCLIntelLoopFuseAttr>(Attr))
2616-
NewAttr = S.mergeSYCLIntelLoopFuseAttr(D, *LFA, LFA->getValue());
2615+
else if (const auto *A = dyn_cast<SYCLIntelLoopFuseAttr>(Attr))
2616+
NewAttr = S.MergeSYCLIntelLoopFuseAttr(D, *A);
26172617
else if (const auto *TCBA = dyn_cast<EnforceTCBAttr>(Attr))
26182618
NewAttr = S.mergeEnforceTCBAttr(D, *TCBA);
26192619
else if (const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(Attr))

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,9 +3155,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
31553155
int64_t NumSimdWorkItems =
31563156
A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue();
31573157

3158-
if (!(XDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
3159-
YDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
3160-
ZDimVal.getZExtValue() % NumSimdWorkItems == 0)) {
3158+
if (XDimVal.getZExtValue() % NumSimdWorkItems != 0) {
31613159
S.Diag(A->getLocation(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
31623160
<< A << AL;
31633161
S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
@@ -3305,14 +3303,12 @@ void Sema::AddSYCLIntelNumSimdWorkItemsAttr(Decl *D,
33053303
}
33063304

33073305
// If the declaration has an [[intel::reqd_work_group_size]] attribute,
3308-
// check to see if can be evenly divided by the num_simd_work_items attr.
3306+
// check to see if the first argument can be evenly divided by the
3307+
// num_simd_work_items attribute.
33093308
if (const auto *DeclAttr = D->getAttr<ReqdWorkGroupSizeAttr>()) {
33103309
Optional<llvm::APSInt> XDimVal = DeclAttr->getXDimVal(Context);
3311-
Optional<llvm::APSInt> YDimVal = DeclAttr->getYDimVal(Context);
3312-
Optional<llvm::APSInt> ZDimVal = DeclAttr->getZDimVal(Context);
33133310

3314-
if (!(*XDimVal % ArgVal == 0 || *YDimVal % ArgVal == 0 ||
3315-
*ZDimVal % ArgVal == 0)) {
3311+
if (*XDimVal % ArgVal != 0) {
33163312
Diag(CI.getLoc(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
33173313
<< CI << DeclAttr;
33183314
Diag(DeclAttr->getLocation(), diag::note_conflicting_attribute);
@@ -3453,87 +3449,93 @@ static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D, const ParsedAttr &A) {
34533449
S.addIntelSingleArgAttr<SYCLIntelMaxGlobalWorkDimAttr>(D, A, E);
34543450
}
34553451

3456-
SYCLIntelLoopFuseAttr *
3457-
Sema::mergeSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
3458-
Expr *E) {
3452+
// Handles [[intel::loop_fuse]] and [[intel::loop_fuse_independent]].
3453+
void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
3454+
Expr *E) {
3455+
if (!E->isValueDependent()) {
3456+
// Validate that we have an integer constant expression and then store the
3457+
// converted constant expression into the semantic attribute so that we
3458+
// don't have to evaluate it again later.
3459+
llvm::APSInt ArgVal;
3460+
ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
3461+
if (Res.isInvalid())
3462+
return;
3463+
E = Res.get();
34593464

3460-
if (const auto ExistingAttr = D->getAttr<SYCLIntelLoopFuseAttr>()) {
3465+
// This attribute requires a non-negative value.
3466+
if (ArgVal < 0) {
3467+
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
3468+
<< CI << /*non-negative*/ 1;
3469+
return;
3470+
}
3471+
// Check to see if there's a duplicate attribute with different values
3472+
// already applied to the declaration.
3473+
if (const auto *DeclAttr = D->getAttr<SYCLIntelLoopFuseAttr>()) {
3474+
// If the other attribute argument is instantiation dependent, we won't
3475+
// have converted it to a constant expression yet and thus we test
3476+
// whether this is a null pointer.
3477+
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
3478+
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
3479+
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
3480+
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
3481+
return;
3482+
}
3483+
// [[intel::loop_fuse]] and [[intel::loop_fuse_independent]] are
3484+
// incompatible.
3485+
// FIXME: If additional spellings are provided for this attribute,
3486+
// this code will do the wrong thing.
3487+
if (DeclAttr->getAttributeSpellingListIndex() !=
3488+
CI.getAttributeSpellingListIndex()) {
3489+
Diag(CI.getLoc(), diag::err_attributes_are_not_compatible)
3490+
<< CI << DeclAttr;
3491+
Diag(DeclAttr->getLocation(), diag::note_conflicting_attribute);
3492+
return;
3493+
}
3494+
}
3495+
}
3496+
3497+
D->addAttr(::new (Context) SYCLIntelLoopFuseAttr(Context, CI, E));
3498+
}
3499+
3500+
SYCLIntelLoopFuseAttr *
3501+
Sema::MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A) {
3502+
// Check to see if there's a duplicate attribute with different values
3503+
// already applied to the declaration.
3504+
if (const auto *DeclAttr = D->getAttr<SYCLIntelLoopFuseAttr>()) {
3505+
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
3506+
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
3507+
if (DeclExpr && MergeExpr &&
3508+
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
3509+
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
3510+
Diag(A.getLoc(), diag::note_previous_attribute);
3511+
return nullptr;
3512+
}
34613513
// [[intel::loop_fuse]] and [[intel::loop_fuse_independent]] are
34623514
// incompatible.
34633515
// FIXME: If additional spellings are provided for this attribute,
34643516
// this code will do the wrong thing.
3465-
if (ExistingAttr->getAttributeSpellingListIndex() !=
3466-
CI.getAttributeSpellingListIndex()) {
3467-
Diag(CI.getLoc(), diag::err_attributes_are_not_compatible)
3468-
<< CI << ExistingAttr;
3469-
Diag(ExistingAttr->getLocation(), diag::note_conflicting_attribute);
3517+
if (DeclAttr->getAttributeSpellingListIndex() !=
3518+
A.getAttributeSpellingListIndex()) {
3519+
Diag(A.getLoc(), diag::err_attributes_are_not_compatible)
3520+
<< &A << DeclAttr;
3521+
Diag(DeclAttr->getLoc(), diag::note_conflicting_attribute);
34703522
return nullptr;
34713523
}
3472-
3473-
if (!E->isValueDependent()) {
3474-
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr(Context);
3475-
Optional<llvm::APSInt> ExistingArgVal =
3476-
ExistingAttr->getValue()->getIntegerConstantExpr(Context);
3477-
3478-
assert(ArgVal && ExistingArgVal &&
3479-
"Argument should be an integer constant expression");
3480-
// Compare attribute argument value and warn if there is a mismatch.
3481-
if (ArgVal->getExtValue() != ExistingArgVal->getExtValue())
3482-
Diag(ExistingAttr->getLoc(), diag::warn_duplicate_attribute)
3483-
<< ExistingAttr;
3484-
}
3485-
3486-
// If there is no mismatch, silently ignore duplicate attribute.
3487-
return nullptr;
3488-
}
3489-
return ::new (Context) SYCLIntelLoopFuseAttr(Context, CI, E);
3490-
}
3491-
3492-
static bool checkSYCLIntelLoopFuseArgument(Sema &S,
3493-
const AttributeCommonInfo &CI,
3494-
Expr *E) {
3495-
// Dependent expressions are checked when instantiated.
3496-
if (E->isValueDependent())
3497-
return false;
3498-
3499-
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr(S.Context);
3500-
if (!ArgVal) {
3501-
S.Diag(E->getExprLoc(), diag::err_attribute_argument_type)
3502-
<< CI << AANT_ArgumentIntegerConstant << E->getSourceRange();
3503-
return true;
3504-
}
3505-
3506-
if (!ArgVal->isNonNegative()) {
3507-
S.Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
3508-
<< CI << /*non-negative*/ 1;
3509-
return true;
35103524
}
35113525

3512-
return false;
3526+
return ::new (Context) SYCLIntelLoopFuseAttr(Context, A, A.getValue());
35133527
}
35143528

3515-
void Sema::addSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI,
3516-
Expr *E) {
3517-
assert(E && "argument has unexpected null value");
3518-
3519-
if (checkSYCLIntelLoopFuseArgument(*this, CI, E))
3520-
return;
3521-
3522-
SYCLIntelLoopFuseAttr *NewAttr = mergeSYCLIntelLoopFuseAttr(D, CI, E);
3523-
3524-
if (NewAttr)
3525-
D->addAttr(NewAttr);
3526-
}
3529+
static void handleSYCLIntelLoopFuseAttr(Sema &S, Decl *D, const ParsedAttr &A) {
3530+
S.CheckDeprecatedSYCLAttributeSpelling(A);
35273531

3528-
// Handles [[intel::loop_fuse]] and [[intel::loop_fuse_independent]].
3529-
static void handleLoopFuseAttr(Sema &S, Decl *D, const ParsedAttr &Attr) {
3530-
// Default argument value is set to 1.
3531-
Expr *E = Attr.isArgExpr(0)
3532-
? Attr.getArgAsExpr(0)
3532+
// If no attribute argument is specified, set to default value '1'.
3533+
Expr *E = A.isArgExpr(0)
3534+
? A.getArgAsExpr(0)
35333535
: IntegerLiteral::Create(S.Context, llvm::APInt(32, 1),
3534-
S.Context.IntTy, Attr.getLoc());
3536+
S.Context.IntTy, A.getLoc());
35353537

3536-
S.addSYCLIntelLoopFuseAttr(D, Attr, E);
3538+
S.AddSYCLIntelLoopFuseAttr(D, A, E);
35373539
}
35383540

35393541
static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
@@ -9136,7 +9138,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
91369138
handleUseStallEnableClustersAttr(S, D, AL);
91379139
break;
91389140
case ParsedAttr::AT_SYCLIntelLoopFuse:
9139-
handleLoopFuseAttr(S, D, AL);
9141+
handleSYCLIntelLoopFuseAttr(S, D, AL);
91409142
break;
91419143
case ParsedAttr::AT_VecTypeHint:
91429144
handleVecTypeHint(S, D, AL);

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static void instantiateSYCLIntelLoopFuseAttr(
640640
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
641641
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
642642
if (!Result.isInvalid())
643-
S.addSYCLIntelLoopFuseAttr(New, *Attr, Result.getAs<Expr>());
643+
S.AddSYCLIntelLoopFuseAttr(New, *Attr, Result.getAs<Expr>());
644644
}
645645

646646
static void instantiateIntelReqdSubGroupSize(

0 commit comments

Comments
 (0)