diff options
Diffstat (limited to 'flang/lib/Parser')
-rw-r--r-- | flang/lib/Parser/openacc-parsers.cpp | 71 | ||||
-rw-r--r-- | flang/lib/Parser/openmp-parsers.cpp | 13 | ||||
-rw-r--r-- | flang/lib/Parser/prescan.cpp | 26 | ||||
-rw-r--r-- | flang/lib/Parser/prescan.h | 12 | ||||
-rw-r--r-- | flang/lib/Parser/tools.cpp | 5 |
5 files changed, 68 insertions, 59 deletions
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp index ad035e6..0dec5652 100644 --- a/flang/lib/Parser/openacc-parsers.cpp +++ b/flang/lib/Parser/openacc-parsers.cpp @@ -75,21 +75,21 @@ TYPE_PARSER( // tile size is one of: // * (represented as an empty std::optional<ScalarIntExpr>) // constant-int-expr -TYPE_PARSER(construct<AccTileExpr>(scalarIntConstantExpr) || +TYPE_PARSER(sourced(construct<AccTileExpr>(scalarIntConstantExpr) || construct<AccTileExpr>( - "*" >> construct<std::optional<ScalarIntConstantExpr>>())) + "*" >> construct<std::optional<ScalarIntConstantExpr>>()))) TYPE_PARSER(construct<AccTileExprList>(nonemptyList(Parser<AccTileExpr>{}))) // 2.9 (1979-1982) gang-arg is one of : // [num:]int-expr // dim:int-expr // static:size-expr -TYPE_PARSER(construct<AccGangArg>(construct<AccGangArg::Static>( - "STATIC: " >> Parser<AccSizeExpr>{})) || +TYPE_PARSER(sourced(construct<AccGangArg>(construct<AccGangArg::Static>( + "STATIC: " >> Parser<AccSizeExpr>{})) || construct<AccGangArg>( construct<AccGangArg::Dim>("DIM: " >> scalarIntExpr)) || construct<AccGangArg>( - construct<AccGangArg::Num>(maybe("NUM: "_tok) >> scalarIntExpr))) + construct<AccGangArg::Num>(maybe("NUM: "_tok) >> scalarIntExpr)))) // 2.9 gang-arg-list TYPE_PARSER( @@ -101,7 +101,7 @@ TYPE_PARSER(construct<AccCollapseArg>( // 2.5.15 Reduction, F'2023 R1131, and CUF reduction-op // Operator for reduction -TYPE_PARSER(sourced(construct<ReductionOperator>( +TYPE_PARSER(construct<ReductionOperator>( first("+" >> pure(ReductionOperator::Operator::Plus), "*" >> pure(ReductionOperator::Operator::Multiply), "MAX" >> pure(ReductionOperator::Operator::Max), @@ -112,32 +112,32 @@ TYPE_PARSER(sourced(construct<ReductionOperator>( ".AND." >> pure(ReductionOperator::Operator::And), ".OR." >> pure(ReductionOperator::Operator::Or), ".EQV." >> pure(ReductionOperator::Operator::Eqv), - ".NEQV." >> pure(ReductionOperator::Operator::Neqv))))) + ".NEQV." >> pure(ReductionOperator::Operator::Neqv)))) // 2.15.1 Bind clause -TYPE_PARSER(sourced(construct<AccBindClause>(name)) || - sourced(construct<AccBindClause>(scalarDefaultCharExpr))) +TYPE_PARSER(sourced(construct<AccBindClause>(name) || + construct<AccBindClause>(scalarDefaultCharExpr))) // 2.5.16 Default clause -TYPE_PARSER(construct<AccDefaultClause>( +TYPE_PARSER(sourced(construct<AccDefaultClause>( first("NONE" >> pure(llvm::acc::DefaultValue::ACC_Default_none), - "PRESENT" >> pure(llvm::acc::DefaultValue::ACC_Default_present)))) + "PRESENT" >> pure(llvm::acc::DefaultValue::ACC_Default_present))))) // SELF clause is either a simple optional condition for compute construct // or a synonym of the HOST clause for the update directive 2.14.4 holding // an object list. -TYPE_PARSER( +TYPE_PARSER(sourced( construct<AccSelfClause>(Parser<AccObjectList>{}) / lookAhead(")"_tok) || - construct<AccSelfClause>(scalarLogicalExpr / lookAhead(")"_tok)) || + construct<AccSelfClause>(scalarLogicalExpr) / lookAhead(")"_tok) || construct<AccSelfClause>( recovery(fail<std::optional<ScalarLogicalExpr>>( "logical expression or object list expected"_err_en_US), - SkipTo<')'>{} >> pure<std::optional<ScalarLogicalExpr>>()))) + SkipTo<')'>{} >> pure<std::optional<ScalarLogicalExpr>>())))) // Modifier for copyin, copyout, cache and create -TYPE_PARSER(construct<AccDataModifier>( +TYPE_PARSER(sourced(construct<AccDataModifier>( first("ZERO:" >> pure(AccDataModifier::Modifier::Zero), - "READONLY:" >> pure(AccDataModifier::Modifier::ReadOnly)))) + "READONLY:" >> pure(AccDataModifier::Modifier::ReadOnly))))) // Combined directives TYPE_PARSER(sourced(construct<AccCombinedDirective>( @@ -166,14 +166,13 @@ TYPE_PARSER(sourced(construct<AccStandaloneDirective>( TYPE_PARSER(sourced(construct<AccLoopDirective>( first("LOOP" >> pure(llvm::acc::Directive::ACCD_loop))))) -TYPE_PARSER(construct<AccBeginLoopDirective>( - sourced(Parser<AccLoopDirective>{}), Parser<AccClauseList>{})) +TYPE_PARSER(sourced(construct<AccBeginLoopDirective>( + Parser<AccLoopDirective>{}, Parser<AccClauseList>{}))) TYPE_PARSER(construct<AccEndLoop>("END LOOP"_tok)) TYPE_PARSER(construct<OpenACCLoopConstruct>( - sourced(Parser<AccBeginLoopDirective>{} / endAccLine), - maybe(Parser<DoConstruct>{}), + Parser<AccBeginLoopDirective>{} / endAccLine, maybe(Parser<DoConstruct>{}), maybe(startAccLine >> Parser<AccEndLoop>{} / endAccLine))) // 2.15.1 Routine directive @@ -186,8 +185,8 @@ TYPE_PARSER(sourced( parenthesized(Parser<AccObjectListWithModifier>{})))) // 2.11 Combined constructs -TYPE_PARSER(construct<AccBeginCombinedDirective>( - sourced(Parser<AccCombinedDirective>{}), Parser<AccClauseList>{})) +TYPE_PARSER(sourced(construct<AccBeginCombinedDirective>( + Parser<AccCombinedDirective>{}, Parser<AccClauseList>{}))) // 2.12 Atomic constructs TYPE_PARSER(construct<AccEndAtomic>(startAccLine >> "END ATOMIC"_tok)) @@ -213,10 +212,10 @@ TYPE_PARSER("ATOMIC" >> statement(assignmentStmt), Parser<AccEndAtomic>{} / endAccLine)) TYPE_PARSER( - sourced(construct<OpenACCAtomicConstruct>(Parser<AccAtomicRead>{})) || - sourced(construct<OpenACCAtomicConstruct>(Parser<AccAtomicCapture>{})) || - sourced(construct<OpenACCAtomicConstruct>(Parser<AccAtomicWrite>{})) || - sourced(construct<OpenACCAtomicConstruct>(Parser<AccAtomicUpdate>{}))) + sourced(construct<OpenACCAtomicConstruct>(Parser<AccAtomicRead>{}) || + construct<OpenACCAtomicConstruct>(Parser<AccAtomicCapture>{}) || + construct<OpenACCAtomicConstruct>(Parser<AccAtomicWrite>{}) || + construct<OpenACCAtomicConstruct>(Parser<AccAtomicUpdate>{}))) // 2.13 Declare constructs TYPE_PARSER(sourced(construct<AccDeclarativeDirective>( @@ -250,18 +249,18 @@ TYPE_PARSER(construct<OpenACCBlockConstruct>( pure(llvm::acc::Directive::ACCD_data)))))) // Standalone constructs -TYPE_PARSER(construct<OpenACCStandaloneConstruct>( - sourced(Parser<AccStandaloneDirective>{}), Parser<AccClauseList>{})) +TYPE_PARSER(sourced(construct<OpenACCStandaloneConstruct>( + Parser<AccStandaloneDirective>{}, Parser<AccClauseList>{}))) // Standalone declarative constructs -TYPE_PARSER(construct<OpenACCStandaloneDeclarativeConstruct>( - sourced(Parser<AccDeclarativeDirective>{}), Parser<AccClauseList>{})) +TYPE_PARSER(sourced(construct<OpenACCStandaloneDeclarativeConstruct>( + Parser<AccDeclarativeDirective>{}, Parser<AccClauseList>{}))) TYPE_PARSER(startAccLine >> withMessage("expected OpenACC directive"_err_en_US, - first(sourced(construct<OpenACCDeclarativeConstruct>( - Parser<OpenACCStandaloneDeclarativeConstruct>{})), - sourced(construct<OpenACCDeclarativeConstruct>( + sourced(first(construct<OpenACCDeclarativeConstruct>( + Parser<OpenACCStandaloneDeclarativeConstruct>{}), + construct<OpenACCDeclarativeConstruct>( Parser<OpenACCRoutineConstruct>{}))))) TYPE_PARSER(sourced(construct<OpenACCEndConstruct>( @@ -293,9 +292,9 @@ TYPE_PARSER(startAccLine >> "SERIAL"_tok >> maybe("LOOP"_tok) >> pure(llvm::acc::Directive::ACCD_serial_loop)))))) -TYPE_PARSER(construct<OpenACCCombinedConstruct>( - sourced(Parser<AccBeginCombinedDirective>{} / endAccLine), +TYPE_PARSER(sourced(construct<OpenACCCombinedConstruct>( + Parser<AccBeginCombinedDirective>{} / endAccLine, maybe(Parser<DoConstruct>{}), - maybe(Parser<AccEndCombinedDirective>{} / endAccLine))) + maybe(Parser<AccEndCombinedDirective>{} / endAccLine)))) } // namespace Fortran::parser diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index d677e14..c0472ad 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1159,6 +1159,9 @@ TYPE_PARSER( // construct<OmpDestroyClause>(Parser<OmpObject>{}))))) || "DEVICE" >> construct<OmpClause>(construct<OmpClause::Device>( parenthesized(Parser<OmpDeviceClause>{}))) || + "DEVICE_SAFESYNC" >> + construct<OmpClause>(construct<OmpClause::DeviceSafesync>( + maybe(parenthesized(scalarLogicalConstantExpr)))) || "DEVICE_TYPE" >> construct<OmpClause>(construct<OmpClause::DeviceType>( parenthesized(Parser<OmpDeviceTypeClause>{}))) || "DIST_SCHEDULE" >> @@ -1832,8 +1835,8 @@ TYPE_PARSER(sourced(construct<OpenMPDeclareMapperConstruct>( TYPE_PARSER(construct<OmpReductionCombiner>(Parser<AssignmentStmt>{}) || construct<OmpReductionCombiner>(Parser<FunctionReference>{})) -TYPE_PARSER(construct<OpenMPCriticalConstruct>( - OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical})) +TYPE_PARSER(sourced(construct<OpenMPCriticalConstruct>( + OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical}))) // 2.11.3 Executable Allocate directive TYPE_PARSER( @@ -1908,12 +1911,12 @@ TYPE_PARSER( Parser<OmpMetadirectiveDirective>{})) / endOmpLine)) -TYPE_PARSER(construct<OpenMPAssumeConstruct>( - sourced(OmpBlockConstructParser{llvm::omp::Directive::OMPD_assume}))) +TYPE_PARSER(sourced(construct<OpenMPAssumeConstruct>( + OmpBlockConstructParser{llvm::omp::Directive::OMPD_assume}))) // Block Construct #define MakeBlockConstruct(dir) \ - construct<OmpBlockConstruct>(OmpBlockConstructParser{dir}) + sourced(construct<OmpBlockConstruct>(OmpBlockConstructParser{dir})) TYPE_PARSER( // MakeBlockConstruct(llvm::omp::Directive::OMPD_masked) || MakeBlockConstruct(llvm::omp::Directive::OMPD_master) || diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp index 66e5b2c..df0372b 100644 --- a/flang/lib/Parser/prescan.cpp +++ b/flang/lib/Parser/prescan.cpp @@ -140,17 +140,9 @@ void Prescanner::Statement() { CHECK(*at_ == '!'); } std::optional<int> condOffset; - if (InOpenMPConditionalLine()) { + if (InOpenMPConditionalLine()) { // !$ condOffset = 2; - } else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'c' && - directiveSentinel_[2] == 'u' && directiveSentinel_[3] == 'f' && - directiveSentinel_[4] == '\0') { - // CUDA conditional compilation line. - condOffset = 5; - } else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'a' && - directiveSentinel_[2] == 'c' && directiveSentinel_[3] == 'c' && - directiveSentinel_[4] == '\0') { - // OpenACC conditional compilation line. + } else if (InOpenACCOrCUDAConditionalLine()) { // !@acc or !@cuf condOffset = 5; } if (condOffset && !preprocessingOnly_) { @@ -166,7 +158,8 @@ void Prescanner::Statement() { } else { // Compiler directive. Emit normalized sentinel, squash following spaces. // Conditional compilation lines (!$) take this path in -E mode too - // so that -fopenmp only has to appear on the later compilation. + // so that -fopenmp only has to appear on the later compilation + // (ditto for !@cuf and !@acc). EmitChar(tokens, '!'); ++at_, ++column_; for (const char *sp{directiveSentinel_}; *sp != '\0'; @@ -202,7 +195,7 @@ void Prescanner::Statement() { } tokens.CloseToken(); SkipSpaces(); - if (InOpenMPConditionalLine() && inFixedForm_ && !tabInCurrentLine_ && + if (InConditionalLine() && inFixedForm_ && !tabInCurrentLine_ && column_ == 6 && *at_ != '\n') { // !$ 0 - turn '0' into a space // !$ 1 - turn '1' into '&' @@ -347,7 +340,7 @@ void Prescanner::Statement() { while (CompilerDirectiveContinuation(tokens, line.sentinel)) { newlineProvenance = GetCurrentProvenance(); } - if (preprocessingOnly_ && inFixedForm_ && InOpenMPConditionalLine() && + if (preprocessingOnly_ && inFixedForm_ && InConditionalLine() && nextLine_ < limit_) { // In -E mode, when the line after !$ conditional compilation is a // regular fixed form continuation line, append a '&' to the line. @@ -1360,11 +1353,10 @@ const char *Prescanner::FixedFormContinuationLine(bool atNewline) { features_.IsEnabled(LanguageFeature::OldDebugLines))) && nextLine_[1] == ' ' && nextLine_[2] == ' ' && nextLine_[3] == ' ' && nextLine_[4] == ' '}; - if (InCompilerDirective() && - !(InOpenMPConditionalLine() && !preprocessingOnly_)) { + if (InCompilerDirective() && !(InConditionalLine() && !preprocessingOnly_)) { // !$ under -E is not continued, but deferred to later compilation if (IsFixedFormCommentChar(col1) && - !(InOpenMPConditionalLine() && preprocessingOnly_)) { + !(InConditionalLine() && preprocessingOnly_)) { int j{1}; for (; j < 5; ++j) { char ch{directiveSentinel_[j - 1]}; @@ -1443,7 +1435,7 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) { } p = SkipWhiteSpaceIncludingEmptyMacros(p); if (InCompilerDirective()) { - if (InOpenMPConditionalLine()) { + if (InConditionalLine()) { if (preprocessingOnly_) { // in -E mode, don't treat !$ as a continuation return nullptr; diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h index fc38adb..5e74817 100644 --- a/flang/lib/Parser/prescan.h +++ b/flang/lib/Parser/prescan.h @@ -171,7 +171,17 @@ private: bool InOpenMPConditionalLine() const { return directiveSentinel_ && directiveSentinel_[0] == '$' && !directiveSentinel_[1]; - ; + } + bool InOpenACCOrCUDAConditionalLine() const { + return directiveSentinel_ && directiveSentinel_[0] == '@' && + ((directiveSentinel_[1] == 'a' && directiveSentinel_[2] == 'c' && + directiveSentinel_[3] == 'c') || + (directiveSentinel_[1] == 'c' && directiveSentinel_[2] == 'u' && + directiveSentinel_[3] == 'f')) && + directiveSentinel_[4] == '\0'; + } + bool InConditionalLine() const { + return InOpenMPConditionalLine() || InOpenACCOrCUDAConditionalLine(); } bool InFixedFormSource() const { return inFixedForm_ && !inPreprocessorDirective_ && !InCompilerDirective(); diff --git a/flang/lib/Parser/tools.cpp b/flang/lib/Parser/tools.cpp index 264ca52..ed6d194 100644 --- a/flang/lib/Parser/tools.cpp +++ b/flang/lib/Parser/tools.cpp @@ -179,4 +179,9 @@ bool CheckForSingleVariableOnRHS(const AssignmentStmt &assignmentStmt) { return Unwrap<Designator>(std::get<Expr>(assignmentStmt.t)) != nullptr; } +const Name *GetDesignatorNameIfDataRef(const Designator &designator) { + const auto *dataRef{std::get_if<DataRef>(&designator.u)}; + return dataRef ? std::get_if<Name>(&dataRef->u) : nullptr; +} + } // namespace Fortran::parser |