Skip to content

Commit c88ae6e

Browse files
authored
[flang][OpenMP] Move two utilities from Semantics to Parser, NFC (#168549)
Move `GetInnermostExecPart` and `IsStrictlyStructuredBlock` from Semantics/openmp-utils.* to Parser/openmp-utils.*. These two only depend on the AST contents and properties.
1 parent 0b82415 commit c88ae6e

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

flang/include/flang/Parser/openmp-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const T *GetFirstArgument(const OmpDirectiveSpecification &spec) {
137137

138138
const BlockConstruct *GetFortranBlockConstruct(
139139
const ExecutionPartConstruct &epc);
140+
const Block &GetInnermostExecPart(const Block &block);
141+
bool IsStrictlyStructuredBlock(const Block &block);
140142

141143
const OmpCombinerExpression *GetCombinerExpr(
142144
const OmpReductionSpecifier &rspec);

flang/include/flang/Semantics/openmp-utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ const SomeExpr *HasStorageOverlap(
9797
const SomeExpr &base, llvm::ArrayRef<SomeExpr> exprs);
9898
bool IsAssignment(const parser::ActionStmt *x);
9999
bool IsPointerAssignment(const evaluate::Assignment &x);
100-
const parser::Block &GetInnermostExecPart(const parser::Block &block);
101-
bool IsStrictlyStructuredBlock(const parser::Block &block);
102100
} // namespace omp
103101
} // namespace Fortran::semantics
104102

flang/lib/Parser/openmp-utils.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ const BlockConstruct *GetFortranBlockConstruct(
9393
return nullptr;
9494
}
9595

96+
/// parser::Block is a list of executable constructs, parser::BlockConstruct
97+
/// is Fortran's BLOCK/ENDBLOCK construct.
98+
/// Strip the outermost BlockConstructs, return the reference to the Block
99+
/// in the executable part of the innermost of the stripped constructs.
100+
/// Specifically, if the given `block` has a single entry (it's a list), and
101+
/// the entry is a BlockConstruct, get the Block contained within. Repeat
102+
/// this step as many times as possible.
103+
const Block &GetInnermostExecPart(const Block &block) {
104+
const Block *iter{&block};
105+
while (iter->size() == 1) {
106+
const ExecutionPartConstruct &ep{iter->front()};
107+
if (auto *bc{GetFortranBlockConstruct(ep)}) {
108+
iter = &std::get<Block>(bc->t);
109+
} else {
110+
break;
111+
}
112+
}
113+
return *iter;
114+
}
115+
116+
bool IsStrictlyStructuredBlock(const Block &block) {
117+
if (block.size() == 1) {
118+
return GetFortranBlockConstruct(block.front()) != nullptr;
119+
} else {
120+
return false;
121+
}
122+
}
123+
96124
const OmpCombinerExpression *GetCombinerExpr(
97125
const OmpReductionSpecifier &rspec) {
98126
return addr_if(std::get<std::optional<OmpCombinerExpression>>(rspec.t));

flang/lib/Semantics/check-omp-atomic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flang/Evaluate/rewrite.h"
2020
#include "flang/Evaluate/tools.h"
2121
#include "flang/Parser/char-block.h"
22+
#include "flang/Parser/openmp-utils.h"
2223
#include "flang/Parser/parse-tree.h"
2324
#include "flang/Semantics/openmp-utils.h"
2425
#include "flang/Semantics/symbol.h"
@@ -41,6 +42,7 @@
4142

4243
namespace Fortran::semantics {
4344

45+
using namespace Fortran::parser::omp;
4446
using namespace Fortran::semantics::omp;
4547

4648
namespace operation = Fortran::evaluate::operation;

flang/lib/Semantics/openmp-utils.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -496,32 +496,4 @@ bool IsPointerAssignment(const evaluate::Assignment &x) {
496496
return std::holds_alternative<evaluate::Assignment::BoundsSpec>(x.u) ||
497497
std::holds_alternative<evaluate::Assignment::BoundsRemapping>(x.u);
498498
}
499-
500-
/// parser::Block is a list of executable constructs, parser::BlockConstruct
501-
/// is Fortran's BLOCK/ENDBLOCK construct.
502-
/// Strip the outermost BlockConstructs, return the reference to the Block
503-
/// in the executable part of the innermost of the stripped constructs.
504-
/// Specifically, if the given `block` has a single entry (it's a list), and
505-
/// the entry is a BlockConstruct, get the Block contained within. Repeat
506-
/// this step as many times as possible.
507-
const parser::Block &GetInnermostExecPart(const parser::Block &block) {
508-
const parser::Block *iter{&block};
509-
while (iter->size() == 1) {
510-
const parser::ExecutionPartConstruct &ep{iter->front()};
511-
if (auto *bc{GetFortranBlockConstruct(ep)}) {
512-
iter = &std::get<parser::Block>(bc->t);
513-
} else {
514-
break;
515-
}
516-
}
517-
return *iter;
518-
}
519-
520-
bool IsStrictlyStructuredBlock(const parser::Block &block) {
521-
if (block.size() == 1) {
522-
return GetFortranBlockConstruct(block.front()) != nullptr;
523-
} else {
524-
return false;
525-
}
526-
}
527499
} // namespace Fortran::semantics::omp

0 commit comments

Comments
 (0)