From 90aca33d886e6decefd2532165fb58638b9bb1ec Mon Sep 17 00:00:00 2001 From: Hongyon Suauthai Date: Fri, 1 Jun 2018 14:36:51 -0700 Subject: [PATCH] [flang] Fix comment in openmp-grammar.h. Fix unparse of reduction operator. Original-commit: flang-compiler/f18@f6a7a03492525bcdf31e61f3a71e28cbe5818e95 Reviewed-on: https://github.com/flang-compiler/f18/pull/96 --- flang/lib/parser/openmp-grammar.h | 51 +++++++++++++++---------------- flang/lib/parser/parse-tree.h | 4 +-- flang/lib/parser/unparse.cc | 16 ++++++++-- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/flang/lib/parser/openmp-grammar.h b/flang/lib/parser/openmp-grammar.h index 2921aeedaaa7..cf2d785238b2 100644 --- a/flang/lib/parser/openmp-grammar.h +++ b/flang/lib/parser/openmp-grammar.h @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef OPENMP_PARSER_GRAMMAR_H_ -#define OPENMP_PARSER_GRAMMAR_H_ +#ifndef FORTRAN_PARSER_OPENMP_GRAMMAR_H_ +#define FORTRAN_PARSER_OPENMP_GRAMMAR_H_ -// Top-level grammar specification for Fortran. These parsers drive -// the tokenization parsers in cooked-tokens.h to consume characters, -// recognize the productions of Fortran, and to construct a parse tree. -// See ParserCombinators.md for documentation on the parser combinator -// library used here to implement an LL recursive descent recognizer. +// Top-level grammar specification for OpenMP. +// See OpenMP-4.5-grammar.txt for documentation. #include "basic-parsers.h" #include "characters.h" @@ -63,13 +60,13 @@ TYPE_PARSER(construct( // map-type-modifier -> ALWAYS // map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE TYPE_PARSER(construct( - maybe(maybe("ALWAYS"_tok >> maybe(","_ch)) >> - ("TO" >> pure(OmpMapClause::Type::To) / ":"_ch || - "FROM" >> pure(OmpMapClause::Type::From) / ":"_ch || - "TOFROM" >> pure(OmpMapClause::Type::Tofrom) / ":"_ch || - "ALLOC" >> pure(OmpMapClause::Type::Alloc) / ":"_ch || - "RELEASE" >> pure(OmpMapClause::Type::Release) / ":"_ch || - "DELETE" >> pure(OmpMapClause::Type::Delete) / ":"_ch)), + maybe(maybe("ALWAYS" >> maybe(","_tok)) >> + ("TO" >> pure(OmpMapClause::Type::To) / ":"_tok || + "FROM" >> pure(OmpMapClause::Type::From) / ":"_tok || + "TOFROM" >> pure(OmpMapClause::Type::Tofrom) / ":"_tok || + "ALLOC" >> pure(OmpMapClause::Type::Alloc) / ":"_tok || + "RELEASE" >> pure(OmpMapClause::Type::Release) / ":"_tok || + "DELETE" >> pure(OmpMapClause::Type::Delete) / ":"_tok)), nonemptyList(name))) // SCHEDULE ([modifier [, modifier]:]kind[, chunk_size]) @@ -82,7 +79,7 @@ TYPE_PARSER(construct( "SIMD" >> pure(OmpScheduleModifierType::ModType::Simd))) TYPE_PARSER(construct(Parser{}, - maybe(","_ch >> Parser{}))) + maybe(","_tok >> Parser{}))) TYPE_PARSER(construct(maybe(Parser{}), "STATIC" >> pure(OmpScheduleClause::ScheduleType::Static) || @@ -90,11 +87,11 @@ TYPE_PARSER(construct(maybe(Parser{}), "GUIDED" >> pure(OmpScheduleClause::ScheduleType::Guided) || "AUTO" >> pure(OmpScheduleClause::ScheduleType::Auto) || "RUNTIME" >> pure(OmpScheduleClause::ScheduleType::Runtime), - maybe(","_ch) >> scalarIntExpr)) + maybe(","_tok) >> scalarIntExpr)) // IF(directive-name-modifier: scalar-logical-expr) TYPE_PARSER(construct( - ("PARALLEL"_tok >> pure(OmpIfClause::DirectiveNameModifier::Parallel) || + maybe("PARALLEL"_tok >> pure(OmpIfClause::DirectiveNameModifier::Parallel) || "TARGET ENTER DATA"_tok >> pure(OmpIfClause::DirectiveNameModifier::TargetEnterData) || "TARGET EXIT DATA"_tok >> @@ -106,7 +103,7 @@ TYPE_PARSER(construct( "TARGET"_tok >> pure(OmpIfClause::DirectiveNameModifier::Target) || "TASKLOOP"_tok >> pure(OmpIfClause::DirectiveNameModifier::Taskloop) || "TASK"_tok >> pure(OmpIfClause::DirectiveNameModifier::Task)) / - maybe(":"_ch), + maybe(":"_tok), scalarLogicalExpr)) // REDUCTION(reduction-identifier: list) @@ -130,7 +127,7 @@ TYPE_PARSER(construct(reductionBinaryOperator) || construct(reductionProcedureOperator)) TYPE_PARSER(construct( - Parser{} / ":"_ch, nonemptyList(designator))) + Parser{} / ":"_tok, nonemptyList(designator))) // DEPEND(SOURCE | SINK : vec | (IN | OUT | INOUT) : list TYPE_PARSER(construct( @@ -146,11 +143,11 @@ TYPE_PARSER(construct( TYPE_CONTEXT_PARSER("Omp Depend clause"_en_US, construct(construct( - "SINK"_tok >> ":"_ch >> nonemptyList(Parser{}))) || + "SINK"_tok >> ":"_tok >> nonemptyList(Parser{}))) || construct( construct("SOURCE"_tok)) || construct(construct( - Parser{}, ":"_ch >> nonemptyList(designator)))) + Parser{}, ":"_tok >> nonemptyList(designator)))) // LINEAR(list: linear-step) TYPE_PARSER(construct( @@ -162,20 +159,20 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US, construct( construct(construct( Parser{}, parenthesized(nonemptyList(name)), - maybe(":"_ch >> scalarIntConstantExpr))) || + maybe(":"_tok >> scalarIntConstantExpr))) || construct(construct( - nonemptyList(name), maybe(":"_ch >> scalarIntConstantExpr))))) + nonemptyList(name), maybe(":"_tok >> scalarIntConstantExpr))))) // ALIGNED(list: alignment) TYPE_PARSER(construct( - nonemptyList(name), maybe(":"_ch) >> scalarIntConstantExpr)) + nonemptyList(name), maybe(":"_tok) >> scalarIntConstantExpr)) TYPE_PARSER(construct(pure(OmpNameList::Kind::Object), name) || construct("/" >> pure(OmpNameList::Kind::Common), name / "/")) TYPE_PARSER( construct(construct("DEFAULTMAP"_tok >> - parenthesized("TOFROM"_tok >> ":"_ch >> "SCALAR"_tok))) || + parenthesized("TOFROM"_tok >> ":"_tok >> "SCALAR"_tok))) || construct(construct("INBRANCH"_tok)) || construct(construct("MERGEABLE"_tok)) || construct(construct("NOGROUP"_tok)) || @@ -193,7 +190,7 @@ TYPE_PARSER( "DEVICE"_tok >> parenthesized(scalarIntExpr))) || construct( construct("DIST_SCHEDULE"_tok >> - parenthesized("STATIC"_tok >> ","_ch >> scalarIntExpr))) || + parenthesized("STATIC"_tok >> ","_tok >> scalarIntExpr))) || construct(construct( "FINAL"_tok >> parenthesized(scalarIntExpr))) || construct( @@ -353,4 +350,4 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, indirect(Parser{})))) } // namespace Fortran::parser -#endif // OPENMP_PARSER_GRAMMAR_H_ +#endif // FORTRAN_PARSER_OPENMP_GRAMMAR_H_ diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index 5ee51567aff3..3f0778eb5cf3 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -3286,8 +3286,8 @@ struct OmpLinearClause { std::variant u; }; -// reduction-identifier -> Add, Subtract, Multiply, .and., .or., .eqv., .neqg., -// min, max, iand, ior, ieor +// reduction-identifier -> "+", "-", "*", .AND., .OR., .EQV., .NEQV., +// MIN, MAX, IAND, IOR, IEOR struct OmpReductionOperator { UNION_CLASS_BOILERPLATE(OmpReductionOperator); ENUM_CLASS(ProcedureOperator, MIN, MAX, IAND, IOR, IEOR) diff --git a/flang/lib/parser/unparse.cc b/flang/lib/parser/unparse.cc index 39c2f739ac8a..9481e7de14fe 100644 --- a/flang/lib/parser/unparse.cc +++ b/flang/lib/parser/unparse.cc @@ -1668,7 +1668,7 @@ public: Word(" SCHEDULE("); Walk(std::get>(x.t)); Walk(std::get(x.t)); - Walk(std::get>(x.t)); + Walk(",", std::get>(x.t)); Put(")"); } void Unparse(const OmpAlignedClause &x) { @@ -1693,6 +1693,18 @@ public: Walk(":", x.step); Put(")"); } + void Unparse(const OmpReductionOperator::BinaryOperator &x) { + switch (x) { + case OmpReductionOperator::BinaryOperator::Add: Put("+"); break; + case OmpReductionOperator::BinaryOperator::Subtract: Put("-"); break; + case OmpReductionOperator::BinaryOperator::Multiply: Put("*"); break; + case OmpReductionOperator::BinaryOperator::AND: Word(".AND."); break; + case OmpReductionOperator::BinaryOperator::OR: Word(".OR."); break; + case OmpReductionOperator::BinaryOperator::EQV: Word(".EQV."); break; + case OmpReductionOperator::BinaryOperator::NEQV: Word(".NEQV."); break; + default: break; + } + } void Unparse(const OmpReductionClause &x) { Word(" REDUCTION("); Walk(std::get(x.t)); @@ -2081,8 +2093,6 @@ public: WALK_NESTED_ENUM(OmpLinearModifier, Type) // OMP linear-modifier WALK_NESTED_ENUM( OmpReductionOperator, ProcedureOperator) // OMP reduction-identifier - WALK_NESTED_ENUM( - OmpReductionOperator, BinaryOperator) // OMP reduction-identifier WALK_NESTED_ENUM(OmpDependenceType, Type) // OMP dependence-type WALK_NESTED_ENUM(OmpMapClause, Type) // OMP map-type WALK_NESTED_ENUM(OmpScheduleClause, ScheduleType) // OMP schedule-type