[flang-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification for range/depth queries… (PR #187109)
via flang-commits
flang-commits at lists.llvm.org
Tue Mar 17 12:51:22 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
…, NFC
That makes them usable for a potential future implementation of APPLY.
---
Full diff: https://github.com/llvm/llvm-project/pull/187109.diff
3 Files Affected:
- (modified) flang/include/flang/Semantics/openmp-utils.h (+2-2)
- (modified) flang/lib/Semantics/check-omp-loop.cpp (+2-2)
- (modified) flang/lib/Semantics/openmp-utils.cpp (+18-20)
``````````diff
diff --git a/flang/include/flang/Semantics/openmp-utils.h b/flang/include/flang/Semantics/openmp-utils.h
index 91465f84d54ca..f5f82dfc81e0c 100644
--- a/flang/include/flang/Semantics/openmp-utils.h
+++ b/flang/include/flang/Semantics/openmp-utils.h
@@ -137,13 +137,13 @@ bool IsFullUnroll(const parser::OpenMPLoopConstruct &x);
// Return the depth of the affected nests:
// {affected-depth, must-be-perfect-nest, reason}.
std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
- const parser::OpenMPLoopConstruct &x, unsigned version);
+ const parser::OmpDirectiveSpecification &spec, unsigned version);
// Return the range of the affected nests in the sequence:
// {first, count, reason}.
// If the range is "the whole sequence", the return value will be {1, -1, ...}.
std::tuple<std::optional<int64_t>, std::optional<int64_t>, Reason>
GetAffectedLoopRangeWithReason(
- const parser::OpenMPLoopConstruct &x, unsigned version);
+ const parser::OmpDirectiveSpecification &spec, unsigned version);
// Count the required loop count from range. If count == -1, return -1,
// indicating all loops in the sequence.
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 01d07e30d3ce5..8f360daf4cfdc 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -293,7 +293,7 @@ void OmpStructureChecker::CheckNestedConstruct(
// Check if a loop-nest-associated construct has only one top-level loop
// in it.
auto [needFirst, needCount, rangeReason]{
- GetAffectedLoopRangeWithReason(x, version)};
+ GetAffectedLoopRangeWithReason(beginSpec, version)};
if (std::optional<int64_t> numLoops{sequence.length()}) {
if (*numLoops == 0) {
@@ -324,7 +324,7 @@ void OmpStructureChecker::CheckNestedConstruct(
// Check requirements on nest depth.
auto [needDepth, needPerfect, depthReason]{
- GetAffectedNestDepthWithReason(x, version)};
+ GetAffectedNestDepthWithReason(beginSpec, version)};
auto [haveSema, havePerf]{sequence.depth()};
if (dir != llvm::omp::Directive::OMPD_fuse) {
diff --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp
index 8abf008a72147..e104096cb3af1 100644
--- a/flang/lib/Semantics/openmp-utils.cpp
+++ b/flang/lib/Semantics/openmp-utils.cpp
@@ -791,9 +791,8 @@ bool IsTransformableLoop(const parser::ExecutionPartConstruct &epc) {
// Return the depth of the affected nests:
// {affected-depth, must-be-perfect-nest}.
std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
- const parser::OpenMPLoopConstruct &x, unsigned version) {
- const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()};
- llvm::omp::Directive dir{beginSpec.DirId()};
+ const parser::OmpDirectiveSpecification &spec, unsigned version) {
+ llvm::omp::Directive dir{spec.DirId()};
bool allowsCollapse{llvm::omp::isAllowedClauseForDirective(
dir, llvm::omp::Clause::OMPC_collapse, version)};
bool allowsOrdered{llvm::omp::isAllowedClauseForDirective(
@@ -801,9 +800,9 @@ std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
if (allowsCollapse || allowsOrdered) {
auto [count, reason]{GetArgumentValueWithReason(
- beginSpec, llvm::omp::Clause::OMPC_collapse, version)};
+ spec, llvm::omp::Clause::OMPC_collapse, version)};
auto [vo, ro]{GetArgumentValueWithReason(
- beginSpec, llvm::omp::Clause::OMPC_ordered, version)};
+ spec, llvm::omp::Clause::OMPC_ordered, version)};
if (vo) {
if (!count || *count < *vo) {
count = vo;
@@ -817,17 +816,16 @@ std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
switch (dir) {
case llvm::omp::Directive::OMPD_interchange: {
// Get the length of the argument list to PERMUTATION.
- if (parser::omp::FindClause(
- beginSpec, llvm::omp::Clause::OMPC_permutation)) {
+ if (parser::omp::FindClause(spec, llvm::omp::Clause::OMPC_permutation)) {
auto [num, reason]{GetNumArgumentsWithReason(
- beginSpec, llvm::omp::Clause::OMPC_permutation, version)};
+ spec, llvm::omp::Clause::OMPC_permutation, version)};
return {num, true, std::move(reason)};
}
// PERMUTATION not specified, assume PERMUTATION(2, 1).
std::string name{parser::omp::GetUpperName(
llvm::omp::Clause::OMPC_permutation, version)};
Reason reason;
- reason.Say(beginSpec.source,
+ reason.Say(spec.source,
"%s clause was not specified, %s(2, 1) was assumed"_because_en_US,
name.c_str(), name.c_str());
return {2, true, std::move(reason)};
@@ -836,20 +834,20 @@ std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
case llvm::omp::Directive::OMPD_tile: {
// Get the length of the argument list to SIZES.
auto [num, reason]{GetNumArgumentsWithReason(
- beginSpec, llvm::omp::Clause::OMPC_sizes, version)};
+ spec, llvm::omp::Clause::OMPC_sizes, version)};
return {num, true, std::move(reason)};
}
case llvm::omp::Directive::OMPD_fuse: {
// Get the value from the argument to DEPTH.
- if (parser::omp::FindClause(beginSpec, llvm::omp::Clause::OMPC_depth)) {
+ if (parser::omp::FindClause(spec, llvm::omp::Clause::OMPC_depth)) {
auto [count, reason]{GetArgumentValueWithReason(
- beginSpec, llvm::omp::Clause::OMPC_depth, version)};
+ spec, llvm::omp::Clause::OMPC_depth, version)};
return {count, true, std::move(reason)};
}
std::string name{
parser::omp::GetUpperName(llvm::omp::Clause::OMPC_depth, version)};
Reason reason;
- reason.Say(beginSpec.source,
+ reason.Say(spec.source,
"%s clause was not specified, a value of 1 was assumed"_because_en_US,
name.c_str());
return {1, true, std::move(reason)};
@@ -871,14 +869,13 @@ std::tuple<std::optional<int64_t>, bool, Reason> GetAffectedNestDepthWithReason(
// {first, count, std::move(reason)}.
std::tuple<std::optional<int64_t>, std::optional<int64_t>, Reason>
GetAffectedLoopRangeWithReason(
- const parser::OpenMPLoopConstruct &x, unsigned version) {
- const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()};
- llvm::omp::Directive dir{beginSpec.DirId()};
+ const parser::OmpDirectiveSpecification &spec, unsigned version) {
+ llvm::omp::Directive dir{spec.DirId()};
if (dir == llvm::omp::Directive::OMPD_fuse) {
std::string name{GetUpperName(llvm::omp::Clause::OMPC_looprange, version)};
- if (auto *clause{parser::omp::FindClause(
- beginSpec, llvm::omp::Clause::OMPC_looprange)}) {
+ if (auto *clause{
+ parser::omp::FindClause(spec, llvm::omp::Clause::OMPC_looprange)}) {
auto &range{DEREF(parser::Unwrap<parser::OmpLooprangeClause>(clause->u))};
std::optional<int64_t> first{GetIntValue(std::get<0>(range.t))};
std::optional<int64_t> count{GetIntValue(std::get<1>(range.t))};
@@ -897,7 +894,7 @@ GetAffectedLoopRangeWithReason(
// If LOOPRANGE was not found, return {1, -1}, where -1 means "the whole
// associated sequence".
Reason reason;
- reason.Say(x.source,
+ reason.Say(spec.source,
"%s clause was not specified, a value of 1 was assumed"_because_en_US,
name.c_str());
return {1, -1, std::move(reason)};
@@ -1111,7 +1108,8 @@ LoopSequence::Depth LoopSequence::calculateDepths() const {
// The result is a perfect nest only if all loop in the sequence
// are fused.
if (value && nestedLength) {
- auto [first, count, _]{GetAffectedLoopRangeWithReason(omp, version_)};
+ auto [first, count, _]{
+ GetAffectedLoopRangeWithReason(beginSpec, version_)};
if (auto required{GetRequiredCount(first, count)}) {
if (*required == -1 || *required == *nestedLength) {
return Depth{value, value};
``````````
</details>
https://github.com/llvm/llvm-project/pull/187109
More information about the flang-commits
mailing list