Skip to content

Commit c3402c9

Browse files
authored
[SYCL][FPGA] Fix the way we handle duplicate vs conflicting values with loop attributes (#14342)
This patch improves diagnostic supports by resolving bugs the way we handle duplicate vs conflicting values with the following SYCL FPGA loop attributes: [[intel::max_reinvocation_delay()]] [[intel::initiation_interval()]] [[intel::max_concurrency()]] [[intel::speculated_iterations()]] [[intel::max_interleaving()]] The patch addresses issues in the test case below, which previously missed diagnostics due to a discontinuation in the while loop while checking for duplicate versus conflicting attribute values in the routine CheckForDuplicateAttrs(). Example with `speculated_iterations' attribute:    Before the fix:     [[intel::speculated_iterations(1)]] // expected-note {{previous attribute is here}}     [[intel::speculated_iterations(1)]] // OK     [[intel::speculated_iterations(2)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}     [[intel::speculated_iterations(4)]] // OK     for (int i = 0; i != 10; ++i) { a[i] = 0; }     After the fix:     [[intel::speculated_iterations(1)]] // expected-note 2 {{previous attribute is here}}     [[intel::speculated_iterations(1)]] // OK     [[intel::speculated_iterations(2)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}     [[intel::speculated_iterations(4)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}     for (int i = 0; i != 10; ++i) { a[i] = 0; } Signed-off-by: Soumi Manna <[email protected]> --------- Signed-off-by: Soumi Manna <[email protected]>
1 parent bf7c84c commit c3402c9

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ static void CheckForDuplicateAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
10251025
S.Diag((*LastFoundItr)->getLocation(), diag::err_loop_attr_conflict)
10261026
<< *FirstItr;
10271027
S.Diag((*FirstItr)->getLocation(), diag::note_previous_attribute);
1028-
return;
10291028
}
10301029
}
10311030
}

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

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,30 @@ void zoo() {
311311
[[intel::speculated_iterations(2)]] for (int i = 0; i != 10; ++i)
312312
a[i] = 0;
313313

314+
[[intel::speculated_iterations(1)]] // expected-note 2{{previous attribute is here}}
315+
[[intel::speculated_iterations(1)]] // OK
316+
[[intel::speculated_iterations(2)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}
317+
[[intel::speculated_iterations(4)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}
318+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
319+
320+
[[intel::max_interleaving(0)]] // expected-note 2{{previous attribute is here}}
321+
[[intel::max_interleaving(0)]] // OK
322+
[[intel::max_interleaving(1)]] // expected-error {{conflicting loop attribute 'max_interleaving'}}
323+
[[intel::max_interleaving(1)]] // expected-error {{conflicting loop attribute 'max_interleaving'}}
324+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
325+
326+
[[intel::max_concurrency(10)]] // expected-note 2{{previous attribute is here}}
327+
[[intel::max_concurrency(10)]] // OK
328+
[[intel::max_concurrency(20)]] // expected-error {{conflicting loop attribute 'max_concurrency'}}
329+
[[intel::max_concurrency(40)]] // expected-error {{conflicting loop attribute 'max_concurrency'}}
330+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
331+
332+
[[intel::initiation_interval(10)]] // expected-note 2{{previous attribute is here}}
333+
[[intel::initiation_interval(10)]] // OK
334+
[[intel::initiation_interval(20)]] // expected-error {{conflicting loop attribute 'initiation_interval'}}
335+
[[intel::initiation_interval(40)]] // expected-error {{conflicting loop attribute 'initiation_interval'}}
336+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
337+
314338
[[intel::ivdep]]
315339
// expected-warning@+2 {{ignoring redundant Intel FPGA loop attribute 'ivdep': safelen INF >= safelen INF}}
316340
// expected-note@-2 {{previous attribute is here}}
@@ -383,6 +407,12 @@ void zoo() {
383407
[[intel::max_reinvocation_delay(20)]] for (int i = 0; i != 10; ++i)
384408
a[i] = 0;
385409

410+
[[intel::max_reinvocation_delay(10)]] // expected-note 2{{previous attribute is here}}
411+
[[intel::max_reinvocation_delay(10)]] // OK
412+
[[intel::max_reinvocation_delay(20)]] // expected-error {{conflicting loop attribute 'max_reinvocation_delay'}}
413+
[[intel::max_reinvocation_delay(40)]] // expected-error {{conflicting loop attribute 'max_reinvocation_delay'}}
414+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
415+
386416
[[intel::enable_loop_pipelining]]
387417
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'enable_loop_pipelining'}}
388418
[[intel::enable_loop_pipelining]] for (int i = 0; i != 10; ++i)
@@ -476,7 +506,7 @@ void ivdep_dependent() {
476506
};
477507
}
478508

479-
template <int A, int B, int C>
509+
template <int A, int B, int C, int D>
480510
void ii_dependent() {
481511
int a[10];
482512
// expected-error@+1 {{'initiation_interval' attribute requires a positive integral compile time constant expression}}
@@ -491,6 +521,13 @@ void ii_dependent() {
491521
[[intel::initiation_interval(A)]] // expected-note {{previous attribute is here}}
492522
[[intel::initiation_interval(B)]] for (int i = 0; i != 10; ++i)
493523
a[i] = 0;
524+
525+
[[intel::initiation_interval(A)]] // expected-note 2{{previous attribute is here}}
526+
[[intel::initiation_interval(A)]] // OK
527+
[[intel::initiation_interval(B)]] // expected-error {{conflicting loop attribute 'initiation_interval'}}
528+
[[intel::initiation_interval(D)]] // expected-error {{conflicting loop attribute 'initiation_interval'}}
529+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
530+
494531
}
495532

496533
template <int A, int B, int C, int D>
@@ -515,6 +552,13 @@ void max_concurrency_dependent() {
515552
// max_concurrency attribute accepts value 0.
516553
[[intel::max_concurrency(D)]] for (int i = 0; i != 10; ++i)
517554
a[i] = 0;
555+
556+
[[intel::max_concurrency(D)]] // expected-note 2{{previous attribute is here}}
557+
[[intel::max_concurrency(D)]] // OK
558+
[[intel::max_concurrency(A)]] // expected-error {{conflicting loop attribute 'max_concurrency'}}
559+
[[intel::max_concurrency(B)]] // expected-error {{conflicting loop attribute 'max_concurrency'}}
560+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
561+
518562
}
519563

520564
template <int A, int B, int C, int D>
@@ -540,9 +584,16 @@ void max_interleaving_dependent() {
540584
[[intel::max_interleaving(D)]]
541585
[[intel::max_interleaving(D)]] for (int i = 0; i != 10; ++i)
542586
a[i] = 0;
587+
588+
[[intel::max_interleaving(D)]] // expected-note 2{{previous attribute is here}}
589+
[[intel::max_interleaving(D)]] // OK
590+
[[intel::max_interleaving(C)]] // expected-error {{conflicting loop attribute 'max_interleaving'}}
591+
[[intel::max_interleaving(C)]] // expected-error {{conflicting loop attribute 'max_interleaving'}}
592+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
593+
543594
}
544595

545-
template <int A, int B, int C, int D>
596+
template <int A, int B, int C, int D, int E>
546597
void speculated_iterations_dependent() {
547598
int a[10];
548599
// expected-error@+1 {{'speculated_iterations' attribute requires a non-negative integral compile time constant expression}}
@@ -561,6 +612,13 @@ void speculated_iterations_dependent() {
561612
[[intel::speculated_iterations(B)]]
562613
[[intel::speculated_iterations(B)]] for (int i = 0; i != 10; ++i)
563614
a[i] = 0;
615+
616+
[[intel::speculated_iterations(A)]] // expected-note 2{{previous attribute is here}}
617+
[[intel::speculated_iterations(A)]] // OK
618+
[[intel::speculated_iterations(B)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}
619+
[[intel::speculated_iterations(E)]] // expected-error {{conflicting loop attribute 'speculated_iterations'}}
620+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
621+
564622
}
565623

566624
template <int A, int B, int C>
@@ -624,7 +682,7 @@ void loop_count_control_dependent() {
624682
a[i] = 0;
625683
}
626684

627-
template <int A, int B, int C>
685+
template <int A, int B, int C, int D>
628686
void max_reinvocation_delay_dependent() {
629687
int a[10];
630688
// expected-error@+1 {{'max_reinvocation_delay' attribute requires a positive integral compile time constant expression}}
@@ -639,6 +697,13 @@ void max_reinvocation_delay_dependent() {
639697
[[intel::max_reinvocation_delay(A)]]
640698
[[intel::max_reinvocation_delay(A)]] for (int i = 0; i != 10; ++i)
641699
a[i] = 0;
700+
701+
[[intel::max_reinvocation_delay(A)]] // expected-note 2{{previous attribute is here}}
702+
[[intel::max_reinvocation_delay(A)]] // OK
703+
[[intel::max_reinvocation_delay(B)]] // expected-error {{conflicting loop attribute 'max_reinvocation_delay'}}
704+
[[intel::max_reinvocation_delay(D)]] // expected-error {{conflicting loop attribute 'max_reinvocation_delay'}}
705+
for (int i = 0; i != 10; ++i) { a[i] = 0; }
706+
642707
}
643708

644709
void check_max_concurrency_expression() {
@@ -815,14 +880,14 @@ int main() {
815880
//expected-note@-1 +{{in instantiation of function template specialization}}
816881
ivdep_dependent<2, 4, -1>();
817882
//expected-note@-1 +{{in instantiation of function template specialization}}
818-
ii_dependent<2, 4, -1>();
883+
ii_dependent<2, 4, -1, 8>();
819884
//expected-note@-1 +{{in instantiation of function template specialization}}
820885
max_concurrency_dependent<1, 4, -2, 0>(); // expected-note{{in instantiation of function template specialization 'max_concurrency_dependent<1, 4, -2, 0>' requested here}}
821886
max_interleaving_dependent<-1, 4, 0, 1>(); // expected-note{{in instantiation of function template specialization 'max_interleaving_dependent<-1, 4, 0, 1>' requested here}}
822-
speculated_iterations_dependent<1, 8, -3, 0>(); // expected-note{{in instantiation of function template specialization 'speculated_iterations_dependent<1, 8, -3, 0>' requested here}}
887+
speculated_iterations_dependent<1, 8, -3, 0, 16>(); // expected-note{{in instantiation of function template specialization 'speculated_iterations_dependent<1, 8, -3, 0, 16>' requested here}}
823888
loop_coalesce_dependent<-1, 4, 0>(); // expected-note{{in instantiation of function template specialization 'loop_coalesce_dependent<-1, 4, 0>' requested here}}
824889
loop_count_control_dependent<3, 2, -1>(); // expected-note{{in instantiation of function template specialization 'loop_count_control_dependent<3, 2, -1>' requested here}}
825-
max_reinvocation_delay_dependent<1, 3, 0>(); // expected-note{{in instantiation of function template specialization 'max_reinvocation_delay_dependent<1, 3, 0>' requested here}}
890+
max_reinvocation_delay_dependent<1, 3, 0, 6>(); // expected-note{{in instantiation of function template specialization 'max_reinvocation_delay_dependent<1, 3, 0, 6>' requested here}}
826891
check_max_concurrency_expression();
827892
check_max_interleaving_expression();
828893
check_speculated_iterations_expression();

0 commit comments

Comments
 (0)