Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -2058,12 +2058,14 @@ def : MutualExclusions<[SYCLIntelFPGAMaxConcurrency,
def SYCLIntelFPGALoopCount : StmtAttr {
let Spellings = [CXX11<"intel", "loop_count_min">,
CXX11<"intel", "loop_count_max">,
CXX11<"intel", "loop_count_avg">];
CXX11<"intel", "loop_count_avg">,
CXX11<"intel", "loop_count">];
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
ErrorDiag, "'for', 'while', and 'do' statements">;
let Accessors = [Accessor<"isMin", [CXX11<"intel", "loop_count_min">]>,
Accessor<"isMax", [CXX11<"intel", "loop_count_max">]>,
Accessor<"isAvg", [CXX11<"intel", "loop_count_avg">]>];
Accessor<"isAvg", [CXX11<"intel", "loop_count_avg">]>,
Accessor<"isCount", [CXX11<"intel", "loop_count">]>];
let Args = [ExprArgument<"NTripCount">];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let IsStmtDependent = 1;
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/CodeGen/CGLoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,11 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
const auto *CE =
cast<ConstantExpr>(IntelFPGALoopCountAvg->getNTripCount());
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
const char *Var = IntelFPGALoopCountAvg->isMax()
? "llvm.loop.intel.loopcount_max"
: IntelFPGALoopCountAvg->isMin()
? "llvm.loop.intel.loopcount_min"
: "llvm.loop.intel.loopcount_avg";
const char *Var =
IntelFPGALoopCountAvg->isMax() ? "llvm.loop.intel.loopcount_max"
: IntelFPGALoopCountAvg->isMin() ? "llvm.loop.intel.loopcount_min"
: IntelFPGALoopCountAvg->isAvg() ? "llvm.loop.intel.loopcount_avg"
: "llvm.loop.intel.loopcount";
setSYCLIntelFPGAVariantCount(Var, ArgVal.getSExtValue());
}

Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,14 @@ CheckForDuplicateSYCLIntelLoopCountAttrs(Sema &S,
unsigned int MinCount = 0;
unsigned int MaxCount = 0;
unsigned int AvgCount = 0;
unsigned int Count = 0;
for (const auto *A : OnlyLoopCountAttrs) {
const auto *At = dyn_cast<SYCLIntelFPGALoopCountAttr>(A);
At->isMin() ? MinCount++ : At->isMax() ? MaxCount++ : AvgCount++;
if (MinCount > 1 || MaxCount > 1 || AvgCount > 1)
At->isMin() ? MinCount++
: At->isMax() ? MaxCount++
: At->isAvg() ? AvgCount++
: Count++;
if (MinCount > 1 || MaxCount > 1 || AvgCount > 1 || Count > 1)
S.Diag(A->getLocation(), diag::err_sycl_loop_attr_duplication) << 1 << A;
}
}
Expand Down
12 changes: 9 additions & 3 deletions clang/test/CodeGenSYCL/intel-fpga-loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// CHECK: br label %for.cond, !llvm.loop ![[MD_LCA:[0-9]+]]
// CHECK: br label %for.cond2, !llvm.loop ![[MD_LCA_1:[0-9]+]]
// CHECK: br label %for.cond13, !llvm.loop ![[MD_LCA_2:[0-9]+]]
// CHECK: br label %for.cond24, !llvm.loop ![[MD_LCA_3:[0-9]+]]

void disable_loop_pipelining() {
int a[10];
Expand Down Expand Up @@ -136,11 +137,16 @@ void loop_count_control() {
// CHECK-NEXT: ![[MD_loop_count_max]] = !{!"llvm.loop.intel.loopcount_max", i32 4}
[[intel::loop_count_max(4)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// 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]+]]}
// 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:[0-9]+]]}
// CHECK: ![[MD_loop_count_min]] = !{!"llvm.loop.intel.loopcount_min", i32 4}
// CHECK: ![[MD_loop_count_max_1]] = !{!"llvm.loop.intel.loopcount_max", i32 40}
// CHECK-NEXT: ![[MD_loop_count_avg_1]] = !{!"llvm.loop.intel.loopcount_avg", i32 21}
[[intel::loop_count_min(4)]] [[intel::loop_count_max(40)]] [[intel::loop_count_avg(21)]] for (int i = 0; i != 10; ++i)
// CHECK: ![[MD_loop_count_avg_1]] = !{!"llvm.loop.intel.loopcount_avg", i32 21}
// CHECK-NEXT: ![[MD_loop_count]] = !{!"llvm.loop.intel.loopcount", i32 30}
[[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)
a[i] = 0;
// CHECK: ![[MD_LCA_3]] = distinct !{![[MD_LCA_3]], ![[MP:[0-9]+]], ![[MD_loop_count_1:[0-9]+]]}
// CHECK-NEXT: ![[MD_loop_count_1]] = !{!"llvm.loop.intel.loopcount", i32 12}
[[intel::loop_count(A)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

Expand Down
37 changes: 35 additions & 2 deletions clang/test/SemaSYCL/intel-fpga-loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ void foo() {
// expected-error@+1 {{'nofusion' attribute cannot be applied to a declaration}}
[[intel::nofusion]] int k[10];
// expected-error@+1{{'loop_count_avg' attribute cannot be applied to a declaration}}
[[intel::loop_count_avg(6)]] int p[10];
[[intel::loop_count_avg(6)]] int l[10];
// expected-error@+1{{'loop_count' attribute cannot be applied to a declaration}}
[[intel::loop_count(8)]] int m[10];
}

// Test for deprecated spelling of Intel FPGA loop attributes
Expand Down Expand Up @@ -115,7 +117,10 @@ void boo() {
[[intel::nofusion(0)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_count_avg' attribute takes one argument}}
[[intel::loop_count_avg(3, 6)]] for (int i = 0; i != 10; ++i)
[[intel::loop_count_avg(3, 6)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_count' attribute takes one argument}}
[[intel::loop_count(6, 9)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

Expand Down Expand Up @@ -203,6 +208,14 @@ void goo() {
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
[[intel::loop_count_avg("abc")]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'const char[4]'}}
[[intel::loop_count("abc")]] for (int i = 0; i != 10; ++i)
a[i] = 0;
[[intel::loop_count(0)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_count' attribute requires a non-negative integral compile time constant expression}}
[[intel::loop_count(-1)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

// Test for Intel FPGA loop attributes duplication
Expand Down Expand Up @@ -316,6 +329,11 @@ void zoo() {
// expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count_avg'}}
[[intel::loop_count_avg(2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;

[[intel::loop_count(2)]]
// expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count'}}
[[intel::loop_count(2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

// Test for Intel FPGA loop attributes compatibility
Expand Down Expand Up @@ -365,6 +383,8 @@ void loop_attrs_compatibility() {
[[intel::loop_count_max(8)]]
for (int i = 0; i != 10; ++i)
a[i] = 0;
[[intel::loop_count(8)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

template<int A, int B, int C>
Expand Down Expand Up @@ -499,6 +519,10 @@ void loop_count_control_dependent() {
for (int i = 0; i != 10; ++i)
a[i] = 0;

// expected-error@+1{{'loop_count' attribute requires a non-negative integral compile time constant expression}}
[[intel::loop_count(C)]] for (int i = 0; i != 10; ++i)
a[i] = 0;

[[intel::loop_count_avg(A)]]
//expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_count_avg'}}
[[intel::loop_count_avg(B)]] for (int i = 0; i != 10; ++i)
Expand All @@ -514,6 +538,10 @@ void loop_count_control_dependent() {
[[intel::loop_count_max(B)]] for (int i = 0; i != 10; ++i)
a[i] = 0;

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

void check_max_concurrency_expression() {
Expand Down Expand Up @@ -648,6 +676,11 @@ void check_loop_attr_template_instantiation() {
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
[[intel::loop_count_min(Ty{})]] for (int i = 0; i != 10; ++i)
a[i] = 0;

// expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'S'}}
// expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
[[intel::loop_count(Ty{})]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

int main() {
Expand Down