[flang-commits] [flang] [flang][OpenMP] Generalize checks of loop construct structure (PR #170735)
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Mon Dec 15 07:25:44 PST 2025
================
@@ -262,41 +270,106 @@ static bool IsLoopTransforming(llvm::omp::Directive dir) {
}
}
-void OmpStructureChecker::CheckNestedBlock(const parser::OpenMPLoopConstruct &x,
- const parser::Block &body, size_t &nestedCount) {
+void OmpStructureChecker::CheckNestedBlock(
+ const parser::OpenMPLoopConstruct &x, const parser::Block &body) {
for (auto &stmt : body) {
if (auto *dir{parser::Unwrap<parser::CompilerDirective>(stmt)}) {
context_.Say(dir->source,
"Compiler directives are not allowed inside OpenMP loop constructs"_warn_en_US);
- } else if (parser::Unwrap<parser::DoConstruct>(stmt)) {
- ++nestedCount;
} else if (auto *omp{parser::Unwrap<parser::OpenMPLoopConstruct>(stmt)}) {
if (!IsLoopTransforming(omp->BeginDir().DirId())) {
context_.Say(omp->source,
"Only loop-transforming OpenMP constructs are allowed inside OpenMP loop constructs"_err_en_US);
}
- ++nestedCount;
} else if (auto *block{parser::Unwrap<parser::BlockConstruct>(stmt)}) {
- CheckNestedBlock(x, std::get<parser::Block>(block->t), nestedCount);
- } else {
+ CheckNestedBlock(x, std::get<parser::Block>(block->t));
+ } else if (!parser::Unwrap<parser::DoConstruct>(stmt)) {
parser::CharBlock source{parser::GetSource(stmt).value_or(x.source)};
context_.Say(source,
"OpenMP loop construct can only contain DO loops or loop-nest-generating OpenMP constructs"_err_en_US);
}
}
}
+static bool IsFullUnroll(const parser::OpenMPLoopConstruct &x) {
+ const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()};
+
+ if (beginSpec.DirName().v == llvm::omp::Directive::OMPD_unroll) {
+ return llvm::none_of(beginSpec.Clauses().v, [](const parser::OmpClause &c) {
+ return c.Id() == llvm::omp::Clause::OMPC_partial;
+ });
+ }
+ return false;
+}
+
+static std::optional<size_t> CountGeneratedLoops(
----------------
Meinersbur wrote:
Sorry for the late review. PR looks good, just a terminology note:
To distingish from loops nested inside each other in a loop nest, the OpenMP spec uses "loop nests" to describe the elements of a loop (nest) sequence. With the `depth` clause, the `fuse` construct can also entire loops nests, e.g.
```f90
!$OMP FUSE DEPTH(2)
DO I1 = 1, 10
DO J1 = 1, 10
END DO
END DO
DO I2 = 1, 10
DO J2 = 1, 10
END DO
END DO
!$OMP END FUSE
```
So I think the name `GeneratedLoops` is ambiguous here.
https://github.com/llvm/llvm-project/pull/170735
More information about the flang-commits
mailing list