Skip to content

Commit b0ad1af

Browse files
kparzyszaugusto2112
authored andcommitted
[flang][OpenMP] Make OmpDirectiveSpecification::Flags an EnumSet (llvm#169713)
The idea is that there can be multiple flags on a given directive. When "Flags" was a simple enum, only one flag could have been set at a time.
1 parent 8821300 commit b0ad1af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+237
-206
lines changed

flang/include/flang/Common/enum-set.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ template <typename ENUM, std::size_t BITS> class EnumSet {
217217
private:
218218
bitsetType bitset_{};
219219
};
220+
221+
namespace detail {
222+
template <typename...> struct IsEnumSetTest {
223+
static constexpr bool value{false};
224+
};
225+
template <typename E, size_t B> struct IsEnumSetTest<EnumSet<E, B>> {
226+
static constexpr bool value{true};
227+
};
228+
} // namespace detail
229+
template <typename T> constexpr bool IsEnumSet{detail::IsEnumSetTest<T>::value};
220230
} // namespace Fortran::common
221231

222232
template <typename ENUM, std::size_t values>

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "parse-tree.h"
1515
#include "tools.h"
1616
#include "unparse.h"
17+
#include "flang/Common/enum-set.h"
1718
#include "flang/Common/idioms.h"
1819
#include "flang/Common/indirection.h"
1920
#include "flang/Support/Fortran.h"
21+
#include "llvm/ADT/StringExtras.h"
2022
#include "llvm/Frontend/OpenMP/OMP.h"
2123
#include "llvm/Support/raw_ostream.h"
2224
#include <string>
@@ -35,6 +37,19 @@ class ParseTreeDumper {
3537
: out_(out), asFortran_{asFortran} {}
3638

3739
static constexpr const char *GetNodeName(const char *) { return "char *"; }
40+
41+
template <typename T, typename E, size_t B>
42+
static std::string GetMemberNames(const common::EnumSet<E, B> &x) {
43+
llvm::ListSeparator sep;
44+
std::string s;
45+
llvm::raw_string_ostream stream(s);
46+
x.IterateOverMembers([&](E e) { stream << sep << T::EnumToString(e); });
47+
return stream.str();
48+
}
49+
#define NODE_ENUMSET(T, S) \
50+
static std::string GetNodeName(const T::S &x) { \
51+
return #S " = {"s + GetMemberNames<T>(x) + "}"s; \
52+
}
3853
#define NODE_NAME(T, N) \
3954
static constexpr const char *GetNodeName(const T &) { return N; }
4055
#define NODE_ENUM(T, E) \
@@ -572,7 +587,8 @@ class ParseTreeDumper {
572587
NODE_ENUM(OmpDeviceTypeClause, DeviceTypeDescription)
573588
NODE(parser, OmpDirectiveName)
574589
NODE(parser, OmpDirectiveSpecification)
575-
NODE_ENUM(OmpDirectiveSpecification, Flags)
590+
NODE_ENUM(OmpDirectiveSpecification, Flag)
591+
NODE_ENUMSET(OmpDirectiveSpecification, Flags)
576592
NODE(parser, OmpDoacross)
577593
NODE(OmpDoacross, Sink)
578594
NODE(OmpDoacross, Source)

flang/include/flang/Parser/parse-tree-visitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define FORTRAN_PARSER_PARSE_TREE_VISITOR_H_
1111

1212
#include "parse-tree.h"
13+
#include "flang/Common/enum-set.h"
1314
#include "flang/Common/visit.h"
1415
#include <cstddef>
1516
#include <optional>
@@ -41,7 +42,7 @@ struct ParseTreeVisitorLookupScope {
4142
// Default case for visitation of non-class data members, strings, and
4243
// any other non-decomposable values.
4344
template <typename A, typename V>
44-
static std::enable_if_t<!std::is_class_v<A> ||
45+
static std::enable_if_t<!std::is_class_v<A> || common::IsEnumSet<A> ||
4546
std::is_same_v<std::string, A> || std::is_same_v<CharBlock, A>>
4647
Walk(const A &x, V &visitor) {
4748
if (visitor.Pre(x)) {

flang/include/flang/Parser/parse-tree.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "format-specification.h"
2323
#include "message.h"
2424
#include "provenance.h"
25+
#include "flang/Common/enum-set.h"
2526
#include "flang/Common/idioms.h"
2627
#include "flang/Common/indirection.h"
2728
#include "flang/Common/reference.h"
@@ -4975,7 +4976,9 @@ struct OmpClauseList {
49754976
// --- Directives and constructs
49764977

49774978
struct OmpDirectiveSpecification {
4978-
ENUM_CLASS(Flags, None, DeprecatedSyntax);
4979+
ENUM_CLASS(Flag, DeprecatedSyntax)
4980+
using Flags = common::EnumSet<Flag, Flag_enumSize>;
4981+
49794982
TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification);
49804983
const OmpDirectiveName &DirName() const {
49814984
return std::get<OmpDirectiveName>(t);

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ TYPE_PARSER(
16331633
maybe(Parser<OmpClauseList>{}),
16341634
maybe(parenthesized(
16351635
OmpArgumentListParser<llvm::omp::Directive::OMPD_flush>{})),
1636-
pure(OmpDirectiveSpecification::Flags::DeprecatedSyntax)))) ||
1636+
pure(OmpDirectiveSpecification::Flags(
1637+
{OmpDirectiveSpecification::Flag::DeprecatedSyntax}))))) ||
16371638
// Parse DECLARE_VARIANT individually, because the "[base:]variant"
16381639
// argument will conflict with DECLARE_REDUCTION's "ident:types...".
16391640
predicated(Parser<OmpDirectiveName>{},
@@ -1643,13 +1644,13 @@ TYPE_PARSER(
16431644
maybe(parenthesized(OmpArgumentListParser<
16441645
llvm::omp::Directive::OMPD_declare_variant>{})),
16451646
maybe(Parser<OmpClauseList>{}),
1646-
pure(OmpDirectiveSpecification::Flags::None))) ||
1647+
pure(OmpDirectiveSpecification::Flags()))) ||
16471648
// Parse the standard syntax: directive [(arguments)] [clauses]
16481649
sourced(construct<OmpDirectiveSpecification>( //
16491650
sourced(OmpDirectiveNameParser{}),
16501651
maybe(parenthesized(OmpArgumentListParser<>{})),
16511652
maybe(Parser<OmpClauseList>{}),
1652-
pure(OmpDirectiveSpecification::Flags::None))))
1653+
pure(OmpDirectiveSpecification::Flags()))))
16531654

16541655
static bool IsStandaloneOrdered(const OmpDirectiveSpecification &dirSpec) {
16551656
// An ORDERED construct is standalone if it has DOACROSS or DEPEND clause.

flang/lib/Parser/unparse.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ class UnparseVisitor {
21422142

21432143
Walk(std::get<OmpDirectiveName>(x.t));
21442144
auto flags{std::get<OmpDirectiveSpecification::Flags>(x.t)};
2145-
if (flags == OmpDirectiveSpecification::Flags::DeprecatedSyntax) {
2145+
if (flags.test(OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
21462146
if (x.DirId() == llvm::omp::Directive::OMPD_flush) {
21472147
// FLUSH clause arglist
21482148
unparseClauses();
@@ -2539,8 +2539,8 @@ class UnparseVisitor {
25392539
void Unparse(const OpenMPInteropConstruct &x) {
25402540
BeginOpenMP();
25412541
Word("!$OMP INTEROP");
2542-
using Flags = OmpDirectiveSpecification::Flags;
2543-
if (std::get<Flags>(x.v.t) == Flags::DeprecatedSyntax) {
2542+
auto flags{std::get<OmpDirectiveSpecification::Flags>(x.v.t)};
2543+
if (flags.test(OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
25442544
Walk("(", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
25452545
Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
25462546
} else {
@@ -2679,8 +2679,8 @@ class UnparseVisitor {
26792679
void Unparse(const OpenMPFlushConstruct &x) {
26802680
BeginOpenMP();
26812681
Word("!$OMP FLUSH");
2682-
using Flags = OmpDirectiveSpecification::Flags;
2683-
if (std::get<Flags>(x.v.t) == Flags::DeprecatedSyntax) {
2682+
auto flags{std::get<OmpDirectiveSpecification::Flags>(x.v.t)};
2683+
if (flags.test(OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
26842684
Walk("(", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
26852685
Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
26862686
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,8 +2748,8 @@ void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
27482748

27492749
unsigned version{context_.langOptions().OpenMPVersion};
27502750
if (version >= 52) {
2751-
using Flags = parser::OmpDirectiveSpecification::Flags;
2752-
if (std::get<Flags>(x.v.t) == Flags::DeprecatedSyntax) {
2751+
auto &flags{std::get<parser::OmpDirectiveSpecification::Flags>(x.v.t)};
2752+
if (flags.test(parser::OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
27532753
context_.Say(x.source,
27542754
"The syntax \"FLUSH clause (object, ...)\" has been deprecated, use \"FLUSH(object, ...) clause\" instead"_warn_en_US);
27552755
}

flang/test/Parser/OpenMP/allocate-align-tree.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end program allocate_align_tree
2828
!CHECK-NEXT: | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'j'
2929
!CHECK-NEXT: | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Constant -> Expr = '16_4'
3030
!CHECK-NEXT: | | | LiteralConstant -> IntLiteralConstant = '16'
31-
!CHECK-NEXT: | | Flags = None
31+
!CHECK-NEXT: | | Flags = {}
3232
!CHECK-NEXT: | Block
3333
!CHECK-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
3434
!CHECK-NEXT: | | | OmpBeginDirective
@@ -38,7 +38,7 @@ end program allocate_align_tree
3838
!CHECK-NEXT: | | | | | LiteralConstant -> IntLiteralConstant = '32'
3939
!CHECK-NEXT: | | | | OmpClause -> Allocator -> Scalar -> Integer -> Expr = '2_8'
4040
!CHECK-NEXT: | | | | | Designator -> DataRef -> Name = 'omp_large_cap_mem_alloc'
41-
!CHECK-NEXT: | | | | Flags = None
41+
!CHECK-NEXT: | | | | Flags = {}
4242
!CHECK-NEXT: | | | Block
4343
!CHECK-NEXT: | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AllocateStmt
4444

flang/test/Parser/OpenMP/allocate-tree-spec-part.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end program allocate_tree
2323
!CHECK-NEXT: | | | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'f'
2424
!CHECK-NEXT: | | | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '1_8'
2525
!CHECK-NEXT: | | | | | Designator -> DataRef -> Name = 'omp_default_mem_alloc'
26-
!CHECK-NEXT: | | | | Flags = None
26+
!CHECK-NEXT: | | | | Flags = {}
2727
!CHECK-NEXT: | | | Block
2828
!CHECK-NEXT: | ExecutionPart -> Block
2929
!CHECK-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt = 'f=2_4'
@@ -37,28 +37,28 @@ end program allocate_tree
3737
!CHECK-NEXT: | | | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'w'
3838
!CHECK-NEXT: | | | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '3_8'
3939
!CHECK-NEXT: | | | | | Designator -> DataRef -> Name = 'omp_const_mem_alloc'
40-
!CHECK-NEXT: | | | | Flags = None
40+
!CHECK-NEXT: | | | | Flags = {}
4141
!CHECK-NEXT: | | | Block
4242
!CHECK-NEXT: | | | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
4343
!CHECK-NEXT: | | | | | OmpBeginDirective
4444
!CHECK-NEXT: | | | | | | OmpDirectiveName -> llvm::omp::Directive = allocate
4545
!CHECK-NEXT: | | | | | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'xarray'
4646
!CHECK-NEXT: | | | | | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '2_8'
4747
!CHECK-NEXT: | | | | | | | Designator -> DataRef -> Name = 'omp_large_cap_mem_alloc'
48-
!CHECK-NEXT: | | | | | | Flags = None
48+
!CHECK-NEXT: | | | | | | Flags = {}
4949
!CHECK-NEXT: | | | | | Block
5050
!CHECK-NEXT: | | | | | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
5151
!CHECK-NEXT: | | | | | | | OmpBeginDirective
5252
!CHECK-NEXT: | | | | | | | | OmpDirectiveName -> llvm::omp::Directive = allocate
5353
!CHECK-NEXT: | | | | | | | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'zarray'
5454
!CHECK-NEXT: | | | | | | | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '1_8'
5555
!CHECK-NEXT: | | | | | | | | | Designator -> DataRef -> Name = 'omp_default_mem_alloc'
56-
!CHECK-NEXT: | | | | | | | | Flags = None
56+
!CHECK-NEXT: | | | | | | | | Flags = {}
5757
!CHECK-NEXT: | | | | | | | Block
5858
!CHECK-NEXT: | | | | | | | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
5959
!CHECK-NEXT: | | | | | | | | | OmpBeginDirective
6060
!CHECK-NEXT: | | | | | | | | | | OmpDirectiveName -> llvm::omp::Directive = allocate
6161
!CHECK-NEXT: | | | | | | | | | | OmpClauseList ->
62-
!CHECK-NEXT: | | | | | | | | | | Flags = None
62+
!CHECK-NEXT: | | | | | | | | | | Flags = {}
6363
!CHECK-NEXT: | | | | | | | | | Block
6464
!CHECK-NEXT: | | | | | | | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AllocateStmt

flang/test/Parser/OpenMP/allocate-tree.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end program allocate_tree
2424
!CHECK-NEXT: | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'w'
2525
!CHECK-NEXT: | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '3_8'
2626
!CHECK-NEXT: | | | Designator -> DataRef -> Name = 'omp_const_mem_alloc'
27-
!CHECK-NEXT: | | Flags = None
27+
!CHECK-NEXT: | | Flags = {}
2828
!CHECK-NEXT: | Block
2929

3030
!CHECK: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
@@ -33,21 +33,21 @@ end program allocate_tree
3333
!CHECK-NEXT: | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'xarray'
3434
!CHECK-NEXT: | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '2_8'
3535
!CHECK-NEXT: | | | Designator -> DataRef -> Name = 'omp_large_cap_mem_alloc'
36-
!CHECK-NEXT: | | Flags = None
36+
!CHECK-NEXT: | | Flags = {}
3737
!CHECK-NEXT: | Block
3838
!CHECK-NEXT: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
3939
!CHECK-NEXT: | | | OmpBeginDirective
4040
!CHECK-NEXT: | | | | OmpDirectiveName -> llvm::omp::Directive = allocate
4141
!CHECK-NEXT: | | | | OmpArgumentList -> OmpArgument -> OmpLocator -> OmpObject -> Designator -> DataRef -> Name = 'zarray'
4242
!CHECK-NEXT: | | | | OmpClauseList -> OmpClause -> Allocator -> Scalar -> Integer -> Expr = '1_8'
4343
!CHECK-NEXT: | | | | | Designator -> DataRef -> Name = 'omp_default_mem_alloc'
44-
!CHECK-NEXT: | | | | Flags = None
44+
!CHECK-NEXT: | | | | Flags = {}
4545
!CHECK-NEXT: | | | Block
4646
!CHECK-NEXT: | | | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpAllocateDirective
4747
!CHECK-NEXT: | | | | | OmpBeginDirective
4848
!CHECK-NEXT: | | | | | | OmpDirectiveName -> llvm::omp::Directive = allocate
4949
!CHECK-NEXT: | | | | | | OmpClauseList ->
50-
!CHECK-NEXT: | | | | | | Flags = None
50+
!CHECK-NEXT: | | | | | | Flags = {}
5151
!CHECK-NEXT: | | | | | Block
5252
!CHECK-NEXT: | | | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AllocateStmt
5353

0 commit comments

Comments
 (0)