[PATCH] D91879: [Flang][OpenMP 4.5] Add semantic check for OpenMP Schedule Clause - chunk size
Yashaswini Hegde via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 20 09:58:07 PST 2020
yhegde created this revision.
yhegde added reviewers: kiranchandramohan, clementval, richard.barton.arm, DavidTruby.
yhegde added projects: Flang, OpenMP, LLVM.
Herald added subscribers: llvm-commits, jdoerfert, guansong, yaxunl.
yhegde requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Semantic check for OpenMP 4.5 - 2.7.1 Schedule clause .
Checks for the value of chunk size of the schedule clauses are the same for all threads
Files:
check-omp-structure.h
check-omp-structure.cpp
Test cases:
omp-schedule-teams.f90
Hopefully this is the right test case. I request the reviewers to provide some more inputs about the test cases.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91879
Files:
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-schedule-teams.f90
Index: flang/test/Semantics/omp-schedule-teams.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/omp-schedule-teams.f90
@@ -0,0 +1,30 @@
+! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.7.1 Teams - Schedule Clause
+
+program omp_doschedule
+ integer,parameter :: N = 14
+ integer :: i
+ integer :: sumx
+ real :: B(N), C(N)
+
+ !$omp target
+ !$omp teams
+ !$omp parallel
+ !$omp do schedule(static, 4)
+ do i = 1,N
+ sumx = sumx + B(i) * C(i)
+ end do
+
+ !ERROR: The value of chunk size in SCHEDULE clause must be the same for all threads.
+ !$omp do schedule(static, 8)
+ do i = 1,N
+ sumx = sumx + B(i) * C(i)
+ end do
+
+ !$omp end do
+ !$omp end parallel
+ !$omp end teams
+ !$omp end target
+
+end program omp_doschedule
Index: flang/lib/Semantics/check-omp-structure.h
===================================================================
--- flang/lib/Semantics/check-omp-structure.h
+++ flang/lib/Semantics/check-omp-structure.h
@@ -175,6 +175,14 @@
llvm::StringRef getClauseName(llvm::omp::Clause clause) override;
llvm::StringRef getDirectiveName(llvm::omp::Directive directive) override;
+
+ std::optional<long int> chunkSize{0};
+ std::optional<long int> GetChunkSize() { return chunkSize; }
+ void SetChunkSize(const parser::ScalarIntExpr &chunkExpr) {
+ if (std::optional<long int> v{GetIntValue(chunkExpr)}) {
+ chunkSize.emplace(*v);
+ }
+ }
};
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
Index: flang/lib/Semantics/check-omp-structure.cpp
===================================================================
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -405,6 +405,7 @@
// Restrictions specific to each clause are implemented apart from the
// generalized restrictions.
+
void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
CheckAllowed(llvm::omp::Clause::OMPC_ordered);
// the parameter of ordered clause is optional
@@ -578,10 +579,24 @@
parser::ToUpperCaseLetters(
parser::OmpScheduleClause::EnumToString(kind)));
}
+
if (const auto &chunkExpr{
std::get<std::optional<parser::ScalarIntExpr>>(x.t)}) {
RequiresPositiveParameter(
llvm::omp::Clause::OMPC_schedule, *chunkExpr, "chunk size");
+
+ if (kind == parser::OmpScheduleClause::ScheduleType::Static) {
+ if (const auto cv{GetIntValue(chunkExpr)}) {
+ const auto cs{GetChunkSize()};
+ if (!*cs) {
+ SetChunkSize(*chunkExpr);
+ } else if (cs != cv) {
+ context_.Say(GetContext().clauseSource,
+ "The value of chunk size in SCHEDULE clause must"
+ " be the same for all threads."_err_en_US);
+ }
+ }
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91879.306718.patch
Type: text/x-patch
Size: 2974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201120/4fd8d36c/attachment.bin>
More information about the llvm-commits
mailing list