diff options
Diffstat (limited to 'clang/lib/Parse/ParseOpenMP.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 164 |
1 files changed, 119 insertions, 45 deletions
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 8ad5edb1bcd6..08dccf9e43f7 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -150,10 +150,12 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) { {OMPD_for, OMPD_simd, OMPD_for_simd}, {OMPD_parallel, OMPD_for, OMPD_parallel_for}, {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd}, + {OMPD_parallel, OMPD_loop, OMPD_parallel_loop}, {OMPD_parallel, OMPD_sections, OMPD_parallel_sections}, {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd}, {OMPD_target, OMPD_parallel, OMPD_target_parallel}, {OMPD_target, OMPD_simd, OMPD_target_simd}, + {OMPD_target_parallel, OMPD_loop, OMPD_target_parallel_loop}, {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for}, {OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd}, {OMPD_teams, OMPD_distribute, OMPD_teams_distribute}, @@ -163,8 +165,10 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) { OMPD_teams_distribute_parallel_for}, {OMPD_teams_distribute_parallel_for, OMPD_simd, OMPD_teams_distribute_parallel_for_simd}, + {OMPD_teams, OMPD_loop, OMPD_teams_loop}, {OMPD_target, OMPD_teams, OMPD_target_teams}, {OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute}, + {OMPD_target_teams, OMPD_loop, OMPD_target_teams_loop}, {OMPD_target_teams_distribute, OMPD_parallel, OMPD_target_teams_distribute_parallel}, {OMPD_target_teams_distribute, OMPD_simd, @@ -174,11 +178,17 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) { {OMPD_target_teams_distribute_parallel_for, OMPD_simd, OMPD_target_teams_distribute_parallel_for_simd}, {OMPD_master, OMPD_taskloop, OMPD_master_taskloop}, + {OMPD_masked, OMPD_taskloop, OMPD_masked_taskloop}, {OMPD_master_taskloop, OMPD_simd, OMPD_master_taskloop_simd}, + {OMPD_masked_taskloop, OMPD_simd, OMPD_masked_taskloop_simd}, {OMPD_parallel, OMPD_master, OMPD_parallel_master}, + {OMPD_parallel, OMPD_masked, OMPD_parallel_masked}, {OMPD_parallel_master, OMPD_taskloop, OMPD_parallel_master_taskloop}, + {OMPD_parallel_masked, OMPD_taskloop, OMPD_parallel_masked_taskloop}, {OMPD_parallel_master_taskloop, OMPD_simd, - OMPD_parallel_master_taskloop_simd}}; + OMPD_parallel_master_taskloop_simd}, + {OMPD_parallel_masked_taskloop, OMPD_simd, + OMPD_parallel_masked_taskloop_simd}}; enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; Token Tok = P.getCurToken(); OpenMPDirectiveKindExWrapper DKind = @@ -635,7 +645,7 @@ TypeResult Parser::parseOpenMPDeclareMapperVarDecl(SourceRange &Range, // Parse the declarator. DeclaratorContext Context = DeclaratorContext::Prototype; - Declarator DeclaratorInfo(DS, Context); + Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), Context); ParseDeclarator(DeclaratorInfo); Range = DeclaratorInfo.getSourceRange(); if (DeclaratorInfo.getIdentifier() == nullptr) { @@ -740,7 +750,7 @@ static bool parseDeclareSimdClauses( OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName); if (CKind == OMPC_uniform || CKind == OMPC_aligned || CKind == OMPC_linear) { - Parser::OpenMPVarListDataTy Data; + Sema::OpenMPVarListDataTy Data; SmallVectorImpl<Expr *> *Vars = &Uniforms; if (CKind == OMPC_aligned) { Vars = &Aligneds; @@ -953,6 +963,10 @@ static bool checkExtensionProperty(Parser &P, SourceLocation Loc, TraitProperty::implementation_extension_allow_templates) return true; + if (TIProperty.Kind == + TraitProperty::implementation_extension_bind_to_declaration) + return true; + auto IsMatchExtension = [](OMPTraitProperty &TP) { return (TP.Kind == llvm::omp::TraitProperty::implementation_extension_match_all || @@ -1433,7 +1447,7 @@ void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr, case OMPC_adjust_args: { AdjustArgsLoc = Tok.getLocation(); ConsumeToken(); - Parser::OpenMPVarListDataTy Data; + Sema::OpenMPVarListDataTy Data; SmallVector<Expr *> Vars; IsError = ParseOpenMPVarList(OMPD_declare_variant, OMPC_adjust_args, Vars, Data); @@ -1557,7 +1571,7 @@ bool Parser::parseOpenMPAppendArgs( // Parse the interop-types. if (Optional<OMPDeclareVariantAttr::InteropType> IType = parseInteropTypeList(*this)) - InterOpTypes.push_back(IType.getValue()); + InterOpTypes.push_back(*IType); else HasError = true; @@ -1764,7 +1778,7 @@ void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) { /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. /// /// default-clause: -/// 'default' '(' 'none' | 'shared' | 'firstprivate' ') +/// 'default' '(' 'none' | 'shared' | 'private' | 'firstprivate' ') /// /// proc_bind-clause: /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') @@ -1830,7 +1844,7 @@ void Parser::ParseOMPDeclareTargetClauses( bool IsIndirectClause = getLangOpts().OpenMP >= 51 && getOpenMPClauseKind(ClauseName) == OMPC_indirect; - if (DTCI.Indirect.hasValue() && IsIndirectClause) { + if (DTCI.Indirect && IsIndirectClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(OMPD_declare_target) << getOpenMPClauseName(OMPC_indirect) << 0; @@ -1867,7 +1881,7 @@ void Parser::ParseOMPDeclareTargetClauses( if (IsDeviceTypeClause) { Optional<SimpleClauseData> DevTypeData = parseOpenMPSimpleClause(*this, OMPC_device_type); - if (DevTypeData.hasValue()) { + if (DevTypeData) { if (DeviceTypeLoc.isValid()) { // We already saw another device_type clause, diagnose it. Diag(DevTypeData.getValue().Loc, @@ -1887,7 +1901,7 @@ void Parser::ParseOMPDeclareTargetClauses( case OMPC_DEVICE_TYPE_unknown: llvm_unreachable("Unexpected device_type"); } - DeviceTypeLoc = DevTypeData.getValue().Loc; + DeviceTypeLoc = DevTypeData->Loc; } continue; } @@ -1928,7 +1942,7 @@ void Parser::ParseOMPDeclareTargetClauses( ConsumeToken(); } - if (DTCI.Indirect.hasValue() && DTCI.DT != OMPDeclareTargetDeclAttr::DT_Any) + if (DTCI.Indirect && DTCI.DT != OMPDeclareTargetDeclAttr::DT_Any) Diag(DeviceTypeLoc, diag::err_omp_declare_target_indirect_device_type); // For declare target require at least 'to' or 'link' to be present. @@ -2022,7 +2036,7 @@ void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind, /// annot_pragma_openmp_end /// Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( - AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, bool Delayed, + AccessSpecifier &AS, ParsedAttributes &Attrs, bool Delayed, DeclSpec::TST TagType, Decl *Tag) { assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) && "Not an OpenMP directive!"); @@ -2307,9 +2321,9 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc); if (HasClauses) ParseOMPDeclareTargetClauses(DTCI); - bool HasImplicitMappings = - DKind == OMPD_begin_declare_target || !HasClauses || - (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect.hasValue()); + bool HasImplicitMappings = DKind == OMPD_begin_declare_target || + !HasClauses || + (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect); // Skip the last annot_pragma_openmp_end. ConsumeAnyToken(); @@ -2363,6 +2377,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( case OMPD_parallel_for_simd: case OMPD_parallel_sections: case OMPD_parallel_master: + case OMPD_parallel_masked: case OMPD_atomic: case OMPD_target: case OMPD_teams: @@ -2379,6 +2394,10 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( case OMPD_master_taskloop_simd: case OMPD_parallel_master_taskloop: case OMPD_parallel_master_taskloop_simd: + case OMPD_masked_taskloop: + case OMPD_masked_taskloop_simd: + case OMPD_parallel_masked_taskloop: + case OMPD_parallel_masked_taskloop_simd: case OMPD_distribute: case OMPD_target_update: case OMPD_distribute_parallel_for: @@ -2399,6 +2418,10 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( case OMPD_masked: case OMPD_metadirective: case OMPD_loop: + case OMPD_teams_loop: + case OMPD_target_teams_loop: + case OMPD_parallel_loop: + case OMPD_target_parallel_loop: Diag(Tok, diag::err_omp_unexpected_directive) << 1 << getOpenMPDirectiveName(DKind); break; @@ -2451,9 +2474,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( /// for simd' | 'target teams distribute simd' | 'masked' {clause} /// annot_pragma_openmp_end /// -StmtResult -Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { - static bool ReadDirectiveWithinMetadirective = false; +StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( + ParsedStmtContext StmtCtx, bool ReadDirectiveWithinMetadirective) { if (!ReadDirectiveWithinMetadirective) assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) && "Not an OpenMP directive!"); @@ -2481,6 +2503,16 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { bool HasAssociatedStatement = true; switch (DKind) { + case OMPD_nothing: + if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == + ParsedStmtContext()) + Diag(Tok, diag::err_omp_immediate_directive) + << getOpenMPDirectiveName(DKind) << 0; + ConsumeToken(); + skipUntilPragmaOpenMPEnd(DKind); + if (Tok.is(tok::annot_pragma_openmp_end)) + ConsumeAnnotationToken(); + break; case OMPD_metadirective: { ConsumeToken(); SmallVector<VariantMatchInfo, 4> VMIs; @@ -2615,9 +2647,9 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { } // Parse Directive - ReadDirectiveWithinMetadirective = true; - Directive = ParseOpenMPDeclarativeOrExecutableDirective(StmtCtx); - ReadDirectiveWithinMetadirective = false; + Directive = ParseOpenMPDeclarativeOrExecutableDirective( + StmtCtx, + /*ReadDirectiveWithinMetadirective=*/true); break; } break; @@ -2745,6 +2777,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { case OMPD_parallel_for_simd: case OMPD_parallel_sections: case OMPD_parallel_master: + case OMPD_parallel_masked: case OMPD_task: case OMPD_ordered: case OMPD_atomic: @@ -2755,12 +2788,20 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { case OMPD_target_parallel: case OMPD_target_parallel_for: case OMPD_loop: + case OMPD_teams_loop: + case OMPD_target_teams_loop: + case OMPD_parallel_loop: + case OMPD_target_parallel_loop: case OMPD_taskloop: case OMPD_taskloop_simd: case OMPD_master_taskloop: + case OMPD_masked_taskloop: case OMPD_master_taskloop_simd: + case OMPD_masked_taskloop_simd: case OMPD_parallel_master_taskloop: + case OMPD_parallel_masked_taskloop: case OMPD_parallel_master_taskloop_simd: + case OMPD_parallel_masked_taskloop_simd: case OMPD_distribute: case OMPD_distribute_parallel_for: case OMPD_distribute_parallel_for_simd: @@ -3097,7 +3138,8 @@ OMPClause *Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) { /// in_reduction-clause | allocator-clause | allocate-clause | /// acq_rel-clause | acquire-clause | release-clause | relaxed-clause | /// depobj-clause | destroy-clause | detach-clause | inclusive-clause | -/// exclusive-clause | uses_allocators-clause | use_device_addr-clause +/// exclusive-clause | uses_allocators-clause | use_device_addr-clause | +/// has_device_addr /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -3279,6 +3321,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_use_device_ptr: case OMPC_use_device_addr: case OMPC_is_device_ptr: + case OMPC_has_device_addr: case OMPC_allocate: case OMPC_nontemporal: case OMPC_inclusive: @@ -3573,7 +3616,7 @@ OMPClause *Parser::ParseOpenMPInteropClause(OpenMPClauseKind Kind, /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. /// /// default-clause: -/// 'default' '(' 'none' | 'shared' | 'firstprivate' ')' +/// 'default' '(' 'none' | 'shared' | 'private' | 'firstprivate' ')' /// /// proc_bind-clause: /// 'proc_bind' '(' 'master' | 'close' | 'spread' ')' @@ -3582,7 +3625,8 @@ OMPClause *Parser::ParseOpenMPInteropClause(OpenMPClauseKind Kind, /// 'bind' '(' 'teams' | 'parallel' | 'thread' ')' /// /// update-clause: -/// 'update' '(' 'in' | 'out' | 'inout' | 'mutexinoutset' ')' +/// 'update' '(' 'in' | 'out' | 'inout' | 'mutexinoutset' | +/// 'inoutset' ')' /// OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly) { @@ -3590,10 +3634,14 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, if (!Val || ParseOnly) return nullptr; if (getLangOpts().OpenMP < 51 && Kind == OMPC_default && - static_cast<DefaultKind>(Val.getValue().Type) == - OMP_DEFAULT_firstprivate) { + (static_cast<DefaultKind>(Val.getValue().Type) == OMP_DEFAULT_private || + static_cast<DefaultKind>(Val.getValue().Type) == + OMP_DEFAULT_firstprivate)) { Diag(Val.getValue().LOpen, diag::err_omp_invalid_dsa) - << getOpenMPClauseName(OMPC_firstprivate) + << getOpenMPClauseName(static_cast<DefaultKind>(Val.getValue().Type) == + OMP_DEFAULT_private + ? OMPC_private + : OMPC_firstprivate) << getOpenMPClauseName(OMPC_default) << "5.1"; return nullptr; } @@ -3875,7 +3923,7 @@ static OpenMPMapModifierKind isMapModifier(Parser &P) { } /// Parse the mapper modifier in map, to, and from clauses. -bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) { +bool Parser::parseMapperModifier(Sema::OpenMPVarListDataTy &Data) { // Parse '('. BalancedDelimiterTracker T(*this, tok::l_paren, tok::colon); if (T.expectAndConsume(diag::err_expected_lparen_after, "mapper")) { @@ -3907,7 +3955,7 @@ bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) { /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) | /// present -bool Parser::parseMapTypeModifiers(OpenMPVarListDataTy &Data) { +bool Parser::parseMapTypeModifiers(Sema::OpenMPVarListDataTy &Data) { while (getCurToken().isNot(tok::colon)) { OpenMPMapModifierKind TypeModifier = isMapModifier(*this); if (TypeModifier == OMPC_MAP_MODIFIER_always || @@ -3963,7 +4011,7 @@ static OpenMPMapClauseKind isMapType(Parser &P) { /// Parse map-type in map clause. /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) /// where, map-type ::= to | from | tofrom | alloc | release | delete -static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data) { +static void parseMapType(Parser &P, Sema::OpenMPVarListDataTy &Data) { Token Tok = P.getCurToken(); if (Tok.is(tok::colon)) { P.Diag(Tok, diag::err_omp_map_type_missing); @@ -4082,11 +4130,38 @@ ExprResult Parser::ParseOpenMPIteratorsExpr() { Data); } +bool Parser::ParseOpenMPReservedLocator(OpenMPClauseKind Kind, + Sema::OpenMPVarListDataTy &Data, + const LangOptions &LangOpts) { + // Currently the only reserved locator is 'omp_all_memory' which is only + // allowed on a depend clause. + if (Kind != OMPC_depend || LangOpts.OpenMP < 51) + return false; + + if (Tok.is(tok::identifier) && + Tok.getIdentifierInfo()->isStr("omp_all_memory")) { + + if (Data.ExtraModifier == OMPC_DEPEND_outallmemory || + Data.ExtraModifier == OMPC_DEPEND_inoutallmemory) + Diag(Tok, diag::warn_omp_more_one_omp_all_memory); + else if (Data.ExtraModifier != OMPC_DEPEND_out && + Data.ExtraModifier != OMPC_DEPEND_inout) + Diag(Tok, diag::err_omp_requires_out_inout_depend_type); + else + Data.ExtraModifier = Data.ExtraModifier == OMPC_DEPEND_out + ? OMPC_DEPEND_outallmemory + : OMPC_DEPEND_inoutallmemory; + ConsumeToken(); + return true; + } + return false; +} + /// Parses clauses with list. bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl<Expr *> &Vars, - OpenMPVarListDataTy &Data) { + Sema::OpenMPVarListDataTy &Data) { UnqualifiedId UnqualifiedReductionId; bool InvalidReductionId = false; bool IsInvalidMapperModifier = false; @@ -4342,14 +4417,16 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, Tok.isNot(tok::annot_pragma_openmp_end))) { ParseScope OMPListScope(this, Scope::OpenMPDirectiveScope); ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); - // Parse variable - ExprResult VarExpr = - Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); - if (VarExpr.isUsable()) { - Vars.push_back(VarExpr.get()); - } else { - SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, - StopBeforeMatch); + if (!ParseOpenMPReservedLocator(Kind, Data, getLangOpts())) { + // Parse variable + ExprResult VarExpr = + Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); + if (VarExpr.isUsable()) { + Vars.push_back(VarExpr.get()); + } else { + SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, + StopBeforeMatch); + } } // Skip ',' if any IsComma = Tok.is(tok::comma); @@ -4437,6 +4514,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, /// 'use_device_addr' '(' list ')' /// is_device_ptr-clause: /// 'is_device_ptr' '(' list ')' +/// has_device_addr-clause: +/// 'has_device_addr' '(' list ')' /// allocate-clause: /// 'allocate' '(' [ allocator ':' ] list ')' /// nontemporal-clause: @@ -4456,7 +4535,7 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, SourceLocation Loc = Tok.getLocation(); SourceLocation LOpen = ConsumeToken(); SmallVector<Expr *, 4> Vars; - OpenMPVarListDataTy Data; + Sema::OpenMPVarListDataTy Data; if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) return nullptr; @@ -4464,10 +4543,5 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, if (ParseOnly) return nullptr; OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc); - return Actions.ActOnOpenMPVarListClause( - Kind, Vars, Data.DepModOrTailExpr, Locs, Data.ColonLoc, - Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, - Data.ExtraModifier, Data.MapTypeModifiers, Data.MapTypeModifiersLoc, - Data.IsMapTypeImplicit, Data.ExtraModifierLoc, Data.MotionModifiers, - Data.MotionModifiersLoc); + return Actions.ActOnOpenMPVarListClause(Kind, Vars, Locs, Data); } |
