Skip to content

Commit b6e6ba9

Browse files
committed
[SYCL][FPGA] Add support for [[intel::loop_count()]] attribute
The original implementation of this attribute in intel#3438, did not support the [[intel::loop_count()]] attribute spelling. This patch adds support for that spelling. Signed-off-by: Soumi Manna <[email protected]>
1 parent 916b986 commit b6e6ba9

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,12 +2058,14 @@ def : MutualExclusions<[SYCLIntelFPGAMaxConcurrency,
20582058
def SYCLIntelFPGALoopCount : StmtAttr {
20592059
let Spellings = [CXX11<"intel", "loop_count_min">,
20602060
CXX11<"intel", "loop_count_max">,
2061-
CXX11<"intel", "loop_count_avg">];
2061+
CXX11<"intel", "loop_count_avg">,
2062+
CXX11<"intel", "loop_count">];
20622063
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
20632064
ErrorDiag, "'for', 'while', and 'do' statements">;
20642065
let Accessors = [Accessor<"isMin", [CXX11<"intel", "loop_count_min">]>,
20652066
Accessor<"isMax", [CXX11<"intel", "loop_count_max">]>,
2066-
Accessor<"isAvg", [CXX11<"intel", "loop_count_avg">]>];
2067+
Accessor<"isAvg", [CXX11<"intel", "loop_count_avg">]>,
2068+
Accessor<"isCount", [CXX11<"intel", "loop_count">]>];
20672069
let Args = [ExprArgument<"NTripCount">];
20682070
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
20692071
let IsStmtDependent = 1;

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,9 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
10401040
? "llvm.loop.intel.loopcount_max"
10411041
: IntelFPGALoopCountAvg->isMin()
10421042
? "llvm.loop.intel.loopcount_min"
1043-
: "llvm.loop.intel.loopcount_avg";
1043+
: IntelFPGALoopCountAvg->isAvg()
1044+
? "llvm.loop.intel.loopcount_avg"
1045+
: "llvm.loop.intel.loopcount";
10441046
setSYCLIntelFPGAVariantCount(Var, ArgVal.getSExtValue());
10451047
}
10461048

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,11 @@ CheckForDuplicateSYCLIntelLoopCountAttrs(Sema &S,
399399
unsigned int MinCount = 0;
400400
unsigned int MaxCount = 0;
401401
unsigned int AvgCount = 0;
402+
unsigned int Count = 0;
402403
for (const auto *A : OnlyLoopCountAttrs) {
403404
const auto *At = dyn_cast<SYCLIntelFPGALoopCountAttr>(A);
404-
At->isMin() ? MinCount++ : At->isMax() ? MaxCount++ : AvgCount++;
405-
if (MinCount > 1 || MaxCount > 1 || AvgCount > 1)
405+
At->isMin() ? MinCount++ : At->isMax() ? MaxCount++ : At->isAvg() ? AvgCount++ : Count++;
406+
if (MinCount > 1 || MaxCount > 1 || AvgCount > 1 || Count > 1)
406407
S.Diag(A->getLocation(), diag::err_sycl_loop_attr_duplication) << 1 << A;
407408
}
408409
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// CHECK: br label %for.cond, !llvm.loop ![[MD_LCA:[0-9]+]]
2020
// CHECK: br label %for.cond2, !llvm.loop ![[MD_LCA_1:[0-9]+]]
2121
// CHECK: br label %for.cond13, !llvm.loop ![[MD_LCA_2:[0-9]+]]
22+
// CHECK: br label %for.cond24, !llvm.loop ![[MD_LCA_3:[0-9]+]]
2223

2324
void disable_loop_pipelining() {
2425
int a[10];
@@ -136,12 +137,18 @@ void loop_count_control() {
136137
// CHECK-NEXT: ![[MD_loop_count_max]] = !{!"llvm.loop.intel.loopcount_max", i32 4}
137138
[[intel::loop_count_max(4)]] for (int i = 0; i != 10; ++i)
138139
a[i] = 0;
139-
// CHECK: ![[MD_LCA_2]] = distinct !{![[MD_LCA_2]], ![[MP:[0-9]+]], ![[MD_loop_count_min:[0-9]+]], ![[MD_loop_count_max_1:[0-9]+]], ![[MD_loop_count_avg_1:[0-9]+]]}
140+
// CHECK: ![[MD_LCA_2]] = distinct !{![[MD_LCA_2]], ![[MP:[0-9]+]], ![[MD_loop_count_min:[0-9]+]], ![[MD_loop_count_max_1:[0-9]+]], ![[MD_loop_count_avg_1:[0-9]+]], ![[MD_loop_count_1:[0-9]+]]}
140141
// CHECK: ![[MD_loop_count_min]] = !{!"llvm.loop.intel.loopcount_min", i32 4}
141142
// CHECK: ![[MD_loop_count_max_1]] = !{!"llvm.loop.intel.loopcount_max", i32 40}
142-
// CHECK-NEXT: ![[MD_loop_count_avg_1]] = !{!"llvm.loop.intel.loopcount_avg", i32 21}
143-
[[intel::loop_count_min(4)]] [[intel::loop_count_max(40)]] [[intel::loop_count_avg(21)]] for (int i = 0; i != 10; ++i)
143+
// CHECK: ![[MD_loop_count_avg_1]] = !{!"llvm.loop.intel.loopcount_avg", i32 21}
144+
// CHECK: ![[MD_loop_count_1]] = !{!"llvm.loop.intel.loopcount", i32 30}
145+
[[intel::loop_count_min(4)]] [[intel::loop_count_max(40)]] [[intel::loop_count_avg(21)]] [[intel::loop_count(30)]] for (int i = 0; i != 10; ++i)
144146
a[i] = 0;
147+
148+
// CHECK: ![[MD_LCA_3]] = distinct !{![[MD_LCA_3]], ![[MP:[0-9]+]], ![[MD_loop_count:[0-9]+]]}
149+
// CHECK-NEXT: ![[MD_loop_count]] = !{!"llvm.loop.intel.loopcount", i32 12}
150+
[[intel::loop_count(A)]] for (int i = 0; i != 10; ++i)
151+
a[i] = 0;
145152
}
146153

147154
template <typename name, typename Func>

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ void foo() {
2323
// expected-error@+1 {{'nofusion' attribute cannot be applied to a declaration}}
2424
[[intel::nofusion]] int k[10];
2525
// expected-error@+1{{'loop_count_avg' attribute cannot be applied to a declaration}}
26-
[[intel::loop_count_avg(6)]] int p[10];
26+
[[intel::loop_count_avg(6)]] int l[10];
27+
// expected-error@+1{{'loop_count' attribute cannot be applied to a declaration}}
28+
[[intel::loop_count(8)]] int m[10];
2729
}
2830

2931
// Test for deprecated spelling of Intel FPGA loop attributes
@@ -117,6 +119,9 @@ void boo() {
117119
// expected-error@+1 {{'loop_count_avg' attribute takes one argument}}
118120
[[intel::loop_count_avg(3, 6)]] for (int i = 0; i != 10; ++i)
119121
a[i] = 0;
122+
// expected-error@+1 {{'loop_count' attribute takes one argument}}
123+
[[intel::loop_count(6, 9)]] for (int i = 0; i != 10; ++i)
124+
a[i] = 0;
120125
}
121126

122127
// Test for incorrect argument value for Intel FPGA loop attributes
@@ -203,6 +208,14 @@ void goo() {
203208
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
204209
[[intel::loop_count_avg("abc")]] for (int i = 0; i != 10; ++i)
205210
a[i] = 0;
211+
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
212+
[[intel::loop_count("abc")]] for (int i = 0; i != 10; ++i)
213+
a[i] = 0;
214+
[[intel::loop_count(0)]] for (int i = 0; i != 10; ++i)
215+
a[i] = 0;
216+
// expected-error@+1 {{'loop_count' attribute requires a non-negative integral compile time constant expression}}
217+
[[intel::loop_count(-1)]] for (int i = 0; i != 10; ++i)
218+
a[i] = 0;
206219
}
207220

208221
// Test for Intel FPGA loop attributes duplication
@@ -316,6 +329,11 @@ void zoo() {
316329
// expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count_avg'}}
317330
[[intel::loop_count_avg(2)]] for (int i = 0; i != 10; ++i)
318331
a[i] = 0;
332+
333+
[[intel::loop_count(2)]]
334+
// expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count'}}
335+
[[intel::loop_count(2)]] for (int i = 0; i != 10; ++i)
336+
a[i] = 0;
319337
}
320338

321339
// Test for Intel FPGA loop attributes compatibility
@@ -365,6 +383,9 @@ void loop_attrs_compatibility() {
365383
[[intel::loop_count_max(8)]]
366384
for (int i = 0; i != 10; ++i)
367385
a[i] = 0;
386+
[[intel::loop_count(8)]]
387+
for (int i = 0; i != 10; ++i)
388+
a[i] = 0;
368389
}
369390

370391
template<int A, int B, int C>
@@ -499,6 +520,11 @@ void loop_count_control_dependent() {
499520
for (int i = 0; i != 10; ++i)
500521
a[i] = 0;
501522

523+
//expected-error@+1{{'loop_count' attribute requires a non-negative integral compile time constant expression}}
524+
[[intel::loop_count(C)]]
525+
for (int i = 0; i != 10; ++i)
526+
a[i] = 0;
527+
502528
[[intel::loop_count_avg(A)]]
503529
//expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count_avg'}}
504530
[[intel::loop_count_avg(B)]] for (int i = 0; i != 10; ++i)
@@ -514,6 +540,10 @@ void loop_count_control_dependent() {
514540
[[intel::loop_count_max(B)]] for (int i = 0; i != 10; ++i)
515541
a[i] = 0;
516542

543+
[[intel::loop_count(A)]]
544+
//expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count'}}
545+
[[intel::loop_count(B)]] for (int i = 0; i != 10; ++i)
546+
a[i] = 0;
517547
}
518548

519549
void check_max_concurrency_expression() {
@@ -648,6 +678,11 @@ void check_loop_attr_template_instantiation() {
648678
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
649679
[[intel::loop_count_min(Ty{})]] for (int i = 0; i != 10; ++i)
650680
a[i] = 0;
681+
682+
// expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'S'}}
683+
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
684+
[[intel::loop_count(Ty{})]] for (int i = 0; i != 10; ++i)
685+
a[i] = 0;
651686
}
652687

653688
int main() {

0 commit comments

Comments
 (0)