[flang][OpenMP] Include check for fully unrolled loops into nest chec…#181729
Open
[flang][OpenMP] Include check for fully unrolled loops into nest chec…#181729
Conversation
…k, NFC It's naturally a part of the verification of constructs nested in loop constructs, so perform that check there instead of having it in a separate function.
Member
|
@llvm/pr-subscribers-flang-semantics Author: Krzysztof Parzyszek (kparzysz) Changes…k, NFC It's naturally a part of the verification of constructs nested in loop constructs, so perform that check there instead of having it in a separate function. Full diff: https://github.com/llvm/llvm-project/pull/181729.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 02580e16a8bf4..8a74f8b98686b 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -270,6 +270,17 @@ static bool IsLoopTransforming(llvm::omp::Directive dir) {
}
}
+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;
+}
+
void OmpStructureChecker::CheckNestedBlock(
const parser::OpenMPLoopConstruct &x, const parser::Block &body) {
using BlockRange = parser::omp::BlockRange;
@@ -282,6 +293,10 @@ void OmpStructureChecker::CheckNestedBlock(
context_.Say(omp->source,
"Only loop-transforming OpenMP constructs are allowed inside OpenMP loop constructs"_err_en_US);
}
+ if (IsFullUnroll(*omp)) {
+ context_.Say(x.source,
+ "OpenMP loop construct cannot apply to a fully unrolled loop"_err_en_US);
+ }
} else if (!parser::Unwrap<parser::DoConstruct>(stmt)) {
parser::CharBlock source{parser::GetSource(stmt).value_or(x.source)};
context_.Say(source,
@@ -290,17 +305,6 @@ void OmpStructureChecker::CheckNestedBlock(
}
}
-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> CountGeneratedNests(
const parser::ExecutionPartConstruct &epc) {
if (parser::Unwrap<parser::DoConstruct>(epc)) {
@@ -403,18 +407,6 @@ void OmpStructureChecker::CheckNestedConstruct(
}
}
-void OmpStructureChecker::CheckFullUnroll(
- const parser::OpenMPLoopConstruct &x) {
- // If the nested construct is a full unroll, then this construct is invalid
- // since it won't contain a loop.
- if (const parser::OpenMPLoopConstruct *nested{x.GetNestedConstruct()}) {
- if (IsFullUnroll(*nested)) {
- context_.Say(x.source,
- "OpenMP loop construct cannot apply to a fully unrolled loop"_err_en_US);
- }
- }
-}
-
void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
loopStack_.push_back(&x);
@@ -472,7 +464,6 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
}
CheckLoopItrVariableIsInt(x);
CheckNestedConstruct(x);
- CheckFullUnroll(x);
CheckAssociatedLoopConstraints(x);
HasInvalidDistributeNesting(x);
HasInvalidLoopBinding(x);
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 9b5b0525dd27f..21460ab0fbe08 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -330,7 +330,6 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
void CheckNestedBlock(
const parser::OpenMPLoopConstruct &x, const parser::Block &body);
void CheckNestedConstruct(const parser::OpenMPLoopConstruct &x);
- void CheckFullUnroll(const parser::OpenMPLoopConstruct &x);
void CheckTargetNest(const parser::OpenMPConstruct &x);
void CheckTargetUpdate();
void CheckTaskgraph(const parser::OmpBlockConstruct &x);
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…k, NFC
It's naturally a part of the verification of constructs nested in loop constructs, so perform that check there instead of having it in a separate function.