Skip to content

Commit b0ecb56

Browse files
authored
[SYCL][FPGA] Refactor statments attributes to align with community the way we handle conflicting vs duplicate values (#13146)
This patch updates ExprArgument<> to use same routine CheckForDuplicateAttrs() that was added on #12243 to diagnose non-identical duplicates as a 'conflicting' loop attributes and suppresse duplicate errors in cases where the two match for FPGA SYCL attributes: [[intel::max_concurrency()]] and [[intel::initiation_interval()]] to align with clang community change (Ref: llvm/llvm-project#70762). --------- Signed-off-by: Soumi Manna <[email protected]>
1 parent 451caf1 commit b0ecb56

File tree

8 files changed

+49
-38
lines changed

8 files changed

+49
-38
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ def SYCLIntelInitiationInterval : DeclOrStmtAttr {
25492549
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
25502550
ErrorDiag,
25512551
"'for', 'while', 'do' statements, and functions">;
2552-
let Args = [ExprArgument<"IntervalExpr">];
2552+
let Args = [ExprArgument<"NExpr">];
25532553
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
25542554
let Documentation = [SYCLIntelInitiationIntervalAttrDocs];
25552555
let SupportsNonconformingLambdaSyntax = 1;
@@ -2560,7 +2560,7 @@ def SYCLIntelMaxConcurrency : DeclOrStmtAttr {
25602560
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
25612561
ErrorDiag,
25622562
"'for', 'while', 'do' statements, and functions">;
2563-
let Args = [ExprArgument<"NThreadsExpr">];
2563+
let Args = [ExprArgument<"NExpr">];
25642564
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
25652565
let Documentation = [SYCLIntelMaxConcurrencyAttrDocs];
25662566
let SupportsNonconformingLambdaSyntax = 1;

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,15 +1056,14 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
10561056

10571057
if (const auto *SYCLIntelII =
10581058
dyn_cast<SYCLIntelInitiationIntervalAttr>(A)) {
1059-
const auto *CE = cast<ConstantExpr>(SYCLIntelII->getIntervalExpr());
1059+
const auto *CE = cast<ConstantExpr>(SYCLIntelII->getNExpr());
10601060
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
10611061
setSYCLIInterval(ArgVal.getSExtValue());
10621062
}
10631063

10641064
if (const auto *SYCLIntelMaxConcurrency =
10651065
dyn_cast<SYCLIntelMaxConcurrencyAttr>(A)) {
1066-
const auto *CE =
1067-
cast<ConstantExpr>(SYCLIntelMaxConcurrency->getNThreadsExpr());
1066+
const auto *CE = cast<ConstantExpr>(SYCLIntelMaxConcurrency->getNExpr());
10681067
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
10691068
setSYCLMaxConcurrencyNThreads(ArgVal.getSExtValue());
10701069
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ void CodeGenFunction::EmitKernelMetadata(const FunctionDecl *FD,
803803
}
804804

805805
if (const auto *A = FD->getAttr<SYCLIntelMaxConcurrencyAttr>()) {
806-
const auto *CE = cast<ConstantExpr>(A->getNThreadsExpr());
806+
const auto *CE = cast<ConstantExpr>(A->getNExpr());
807807
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
808808
llvm::Metadata *AttrMDArgs[] = {
809809
llvm::ConstantAsMetadata::get(Builder.getInt32(ArgVal.getSExtValue()))};
@@ -817,7 +817,7 @@ void CodeGenFunction::EmitKernelMetadata(const FunctionDecl *FD,
817817
}
818818

819819
if (const auto *A = FD->getAttr<SYCLIntelInitiationIntervalAttr>()) {
820-
const auto *CE = cast<ConstantExpr>(A->getIntervalExpr());
820+
const auto *CE = cast<ConstantExpr>(A->getNExpr());
821821
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
822822
llvm::Metadata *AttrMDArgs[] = {
823823
llvm::ConstantAsMetadata::get(Builder.getInt32(ArgVal.getSExtValue()))};

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,8 +4250,7 @@ void Sema::AddSYCLIntelInitiationIntervalAttr(Decl *D,
42504250
// If the other attribute argument is instantiation dependent, we won't
42514251
// have converted it to a constant expression yet and thus we test
42524252
// whether this is a null pointer.
4253-
if (const auto *DeclExpr =
4254-
dyn_cast<ConstantExpr>(DeclAttr->getIntervalExpr())) {
4253+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getNExpr())) {
42554254
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
42564255
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
42574256
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
@@ -4273,9 +4272,8 @@ Sema::MergeSYCLIntelInitiationIntervalAttr(
42734272
// already applied to the declaration.
42744273
if (const auto *DeclAttr =
42754274
D->getAttr<SYCLIntelInitiationIntervalAttr>()) {
4276-
if (const auto *DeclExpr =
4277-
dyn_cast<ConstantExpr>(DeclAttr->getIntervalExpr())) {
4278-
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getIntervalExpr())) {
4275+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getNExpr())) {
4276+
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getNExpr())) {
42794277
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
42804278
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
42814279
Diag(A.getLoc(), diag::note_previous_attribute);
@@ -4287,7 +4285,7 @@ Sema::MergeSYCLIntelInitiationIntervalAttr(
42874285
}
42884286

42894287
return ::new (Context)
4290-
SYCLIntelInitiationIntervalAttr(Context, A, A.getIntervalExpr());
4288+
SYCLIntelInitiationIntervalAttr(Context, A, A.getNExpr());
42914289
}
42924290

42934291
static void handleSYCLIntelInitiationIntervalAttr(Sema &S, Decl *D,
@@ -8418,9 +8416,8 @@ SYCLIntelMaxConcurrencyAttr *Sema::MergeSYCLIntelMaxConcurrencyAttr(
84188416
// Check to see if there's a duplicate attribute with different values
84198417
// already applied to the declaration.
84208418
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxConcurrencyAttr>()) {
8421-
if (const auto *DeclExpr =
8422-
dyn_cast<ConstantExpr>(DeclAttr->getNThreadsExpr())) {
8423-
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getNThreadsExpr())) {
8419+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getNExpr())) {
8420+
if (const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getNExpr())) {
84248421
if (DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
84258422
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
84268423
Diag(A.getLoc(), diag::note_previous_attribute);
@@ -8431,8 +8428,7 @@ SYCLIntelMaxConcurrencyAttr *Sema::MergeSYCLIntelMaxConcurrencyAttr(
84318428
}
84328429
}
84338430

8434-
return ::new (Context)
8435-
SYCLIntelMaxConcurrencyAttr(Context, A, A.getNThreadsExpr());
8431+
return ::new (Context) SYCLIntelMaxConcurrencyAttr(Context, A, A.getNExpr());
84368432
}
84378433

84388434
void Sema::AddSYCLIntelMaxConcurrencyAttr(Decl *D,
@@ -8458,8 +8454,7 @@ void Sema::AddSYCLIntelMaxConcurrencyAttr(Decl *D,
84588454
// If the other attribute argument is instantiation dependent, we won't
84598455
// have converted it to a constant expression yet and thus we test
84608456
// whether this is a null pointer.
8461-
if (const auto *DeclExpr =
8462-
dyn_cast<ConstantExpr>(DeclAttr->getNThreadsExpr())) {
8457+
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getNExpr())) {
84638458
if (ArgVal != DeclExpr->getResultAsAPSInt()) {
84648459
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
84658460
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ CheckForDuplicationSYCLLoopAttribute(Sema &S,
980980
// Diagnose non-identical duplicates as a 'conflicting' loop attributes
981981
// and suppress duplicate errors in cases where the two match for
982982
// FPGA attributes: 'SYCLIntelMaxInterleavingAttr',
983-
// 'SYCLIntelSpeculatedIterationsAttr', and
984-
// 'SYCLIntelMaxReinvocationDelayAttr'.
983+
// 'SYCLIntelSpeculatedIterationsAttr', 'SYCLIntelMaxReinvocationDelayAttr',
984+
// 'SYCLIntelInitiationIntervalAttr', and 'SYCLIntelMaxConcurrencyAttr'
985985
template <typename LoopAttrT>
986986
static void CheckForDuplicateAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
987987
auto FindFunc = [](const Attr *A) { return isa<const LoopAttrT>(A); };
@@ -1023,10 +1023,8 @@ static void CheckForDuplicateAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
10231023

10241024
static void CheckForIncompatibleSYCLLoopAttributes(
10251025
Sema &S, const SmallVectorImpl<const Attr *> &Attrs) {
1026-
CheckForDuplicationSYCLLoopAttribute<SYCLIntelInitiationIntervalAttr>(
1027-
S, Attrs);
1028-
CheckForDuplicationSYCLLoopAttribute<SYCLIntelMaxConcurrencyAttr>(S,
1029-
Attrs);
1026+
CheckForDuplicateAttrs<SYCLIntelInitiationIntervalAttr>(S, Attrs);
1027+
CheckForDuplicateAttrs<SYCLIntelMaxConcurrencyAttr>(S, Attrs);
10301028
CheckForDuplicationSYCLLoopAttribute<SYCLIntelLoopCoalesceAttr>(S, Attrs);
10311029
CheckForDuplicationSYCLLoopAttribute<SYCLIntelDisableLoopPipeliningAttr>(
10321030
S, Attrs);
@@ -1224,6 +1222,8 @@ bool Sema::CheckRebuiltAttributedStmtAttributes(ArrayRef<const Attr *> Attrs) {
12241222
CheckForDuplicateAttrs<SYCLIntelSpeculatedIterationsAttr>(*this, Attrs);
12251223
CheckForDuplicateAttrs<SYCLIntelMaxInterleavingAttr>(*this, Attrs);
12261224
CheckForDuplicateAttrs<SYCLIntelMaxReinvocationDelayAttr>(*this, Attrs);
1225+
CheckForDuplicateAttrs<SYCLIntelInitiationIntervalAttr>(*this, Attrs);
1226+
CheckForDuplicateAttrs<SYCLIntelMaxConcurrencyAttr>(*this, Attrs);
12271227
return false;
12281228
}
12291229

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,17 +2067,15 @@ TemplateInstantiator::TransformSYCLIntelIVDepAttr(
20672067
const SYCLIntelInitiationIntervalAttr *
20682068
TemplateInstantiator::TransformSYCLIntelInitiationIntervalAttr(
20692069
const SYCLIntelInitiationIntervalAttr *II) {
2070-
Expr *TransformedExpr =
2071-
getDerived().TransformExpr(II->getIntervalExpr()).get();
2070+
Expr *TransformedExpr = getDerived().TransformExpr(II->getNExpr()).get();
20722071
return getSema().BuildSYCLIntelInitiationIntervalAttr(*II,
20732072
TransformedExpr);
20742073
}
20752074

20762075
const SYCLIntelMaxConcurrencyAttr *
20772076
TemplateInstantiator::TransformSYCLIntelMaxConcurrencyAttr(
20782077
const SYCLIntelMaxConcurrencyAttr *MC) {
2079-
Expr *TransformedExpr =
2080-
getDerived().TransformExpr(MC->getNThreadsExpr()).get();
2078+
Expr *TransformedExpr = getDerived().TransformExpr(MC->getNExpr()).get();
20812079
return getSema().BuildSYCLIntelMaxConcurrencyAttr(*MC, TransformedExpr);
20822080
}
20832081

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ static void instantiateSYCLIntelMaxConcurrencyAttr(
802802
const SYCLIntelMaxConcurrencyAttr *A, Decl *New) {
803803
EnterExpressionEvaluationContext Unevaluated(
804804
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
805-
ExprResult Result = S.SubstExpr(A->getNThreadsExpr(), TemplateArgs);
805+
ExprResult Result = S.SubstExpr(A->getNExpr(), TemplateArgs);
806806
if (!Result.isInvalid())
807807
S.AddSYCLIntelMaxConcurrencyAttr(New, *A, Result.getAs<Expr>());
808808
}
@@ -832,7 +832,7 @@ static void instantiateSYCLIntelInitiationIntervalAttr(
832832
const SYCLIntelInitiationIntervalAttr *A, Decl *New) {
833833
EnterExpressionEvaluationContext Unevaluated(
834834
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
835-
ExprResult Result = S.SubstExpr(A->getIntervalExpr(), TemplateArgs);
835+
ExprResult Result = S.SubstExpr(A->getNExpr(), TemplateArgs);
836836
if (!Result.isInvalid())
837837
S.AddSYCLIntelInitiationIntervalAttr(New, *A, Result.getAs<Expr>());
838838
}

clang/test/SemaSYCL/intel-fpga-loops.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,26 @@ void zoo() {
264264
[[intel::ivdep(4)]] for (int i = 0; i != 10; ++i)
265265
a[i] = 0;
266266
[[intel::max_concurrency(2)]]
267-
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'max_concurrency'}}
268267
[[intel::max_concurrency(2)]] for (int i = 0; i != 10; ++i)
269268
a[i] = 0;
270269
[[intel::initiation_interval(2)]]
271-
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
272270
[[intel::initiation_interval(2)]] for (int i = 0; i != 10; ++i)
273271
a[i] = 0;
274272
[[intel::initiation_interval(2)]]
275-
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
276273
[[intel::max_concurrency(2)]]
277274
[[intel::initiation_interval(2)]] for (int i = 0; i != 10; ++i)
278275
a[i] = 0;
276+
277+
[[intel::max_concurrency(10)]] // expected-note {{previous attribute is here}}
278+
[[intel::max_concurrency(10)]] // OK
279+
// expected-error@+1 {{conflicting loop attribute 'max_concurrency'}}
280+
[[intel::max_concurrency(20)]] for (int i = 0; i != 10; ++i)
281+
a[i] = 0;
282+
[[intel::initiation_interval(10)]] // expected-note {{previous attribute is here}}
283+
[[intel::initiation_interval(10)]] // OK
284+
// expected-error@+1 {{conflicting loop attribute 'initiation_interval'}}
285+
[[intel::initiation_interval(20)]] for (int i = 0; i != 10; ++i)
286+
a[i] = 0;
279287
[[intel::disable_loop_pipelining]]
280288
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'disable_loop_pipelining'}}
281289
[[intel::disable_loop_pipelining]] for (int i = 0; i != 10; ++i)
@@ -475,8 +483,12 @@ void ii_dependent() {
475483
[[intel::initiation_interval(C)]] for (int i = 0; i != 10; ++i)
476484
a[i] = 0;
477485

478-
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
479486
[[intel::initiation_interval(A)]]
487+
[[intel::initiation_interval(A)]] for (int i = 0; i != 10; ++i)
488+
a[i] = 0;
489+
490+
// expected-error@+2 {{conflicting loop attribute 'initiation_interval'}}
491+
[[intel::initiation_interval(A)]] // expected-note {{previous attribute is here}}
480492
[[intel::initiation_interval(B)]] for (int i = 0; i != 10; ++i)
481493
a[i] = 0;
482494
}
@@ -488,11 +500,18 @@ void max_concurrency_dependent() {
488500
[[intel::max_concurrency(C)]] for (int i = 0; i != 10; ++i)
489501
a[i] = 0;
490502

491-
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'max_concurrency'}}
492-
[[intel::max_concurrency(A)]]
503+
// expected-error@+2 {{conflicting loop attribute 'max_concurrency'}}
504+
[[intel::max_concurrency(A)]] // expected-note {{previous attribute is here}}
493505
[[intel::max_concurrency(B)]] for (int i = 0; i != 10; ++i)
494506
a[i] = 0;
495507

508+
509+
[[intel::max_concurrency(A)]]
510+
[[intel::max_concurrency(A)]] for (int i = 0; i != 10; ++i)
511+
a[i] = 0;
512+
513+
514+
[[intel::max_concurrency(D)]]
496515
// max_concurrency attribute accepts value 0.
497516
[[intel::max_concurrency(D)]] for (int i = 0; i != 10; ++i)
498517
a[i] = 0;

0 commit comments

Comments
 (0)