[flang-commits] [flang] [flang][OpenMP] Generalize checks of loop construct structure (PR #170735)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Mon Dec 15 07:30:36 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(
----------------
kparzysz wrote:
Yes, it was meant to refer to top-level sibling loops. I can rename this to `GountGeneratedNests`.
https://github.com/llvm/llvm-project/pull/170735
More information about the flang-commits
mailing list