diff options
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/AST/DeclBase.h | 8 | ||||
-rw-r--r-- | clang/include/clang/AST/DeclCXX.h | 8 | ||||
-rw-r--r-- | clang/include/clang/AST/DeclOpenMP.h | 102 | ||||
-rw-r--r-- | clang/include/clang/AST/RecursiveASTVisitor.h | 9 | ||||
-rw-r--r-- | clang/include/clang/Basic/DeclNodes.td | 1 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 4 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 | ||||
-rw-r--r-- | clang/include/clang/Basic/OpenMPKinds.def | 8 | ||||
-rw-r--r-- | clang/include/clang/Parse/Parser.h | 7 | ||||
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 23 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTBitCodes.h | 3 |
11 files changed, 176 insertions, 3 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 5869ec0bbf6..9117f53487d 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -175,7 +175,10 @@ public: IDNS_LocalExtern = 0x0800, /// This declaration is an OpenMP user defined reduction construction. - IDNS_OMPReduction = 0x1000 + IDNS_OMPReduction = 0x1000, + + /// This declaration is an OpenMP user defined mapper. + IDNS_OMPMapper = 0x2000, }; /// ObjCDeclQualifier - 'Qualifiers' written next to the return and @@ -323,7 +326,7 @@ protected: unsigned FromASTFile : 1; /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. - unsigned IdentifierNamespace : 13; + unsigned IdentifierNamespace : 14; /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. @@ -1251,6 +1254,7 @@ public: /// NamespaceDecl /// TagDecl /// OMPDeclareReductionDecl +/// OMPDeclareMapperDecl /// FunctionDecl /// ObjCMethodDecl /// ObjCContainerDecl diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index d6cad4e8068..6b99f7cad17 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -1828,6 +1828,14 @@ public: CXXBasePath &Path, DeclarationName Name); /// Base-class lookup callback that determines whether there exists + /// an OpenMP declare mapper member with the given name. + /// + /// This callback can be used with \c lookupInBases() to find members + /// of the given name within a C++ class hierarchy. + static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier, + CXXBasePath &Path, DeclarationName Name); + + /// Base-class lookup callback that determines whether there exists /// a member with the given name that can be used in a nested-name-specifier. /// /// This callback can be used with \c lookupInBases() to find members of diff --git a/clang/include/clang/AST/DeclOpenMP.h b/clang/include/clang/AST/DeclOpenMP.h index d3d7cf51aa4..5faf6c84c8c 100644 --- a/clang/include/clang/AST/DeclOpenMP.h +++ b/clang/include/clang/AST/DeclOpenMP.h @@ -206,6 +206,108 @@ public: } }; +/// This represents '#pragma omp declare mapper ...' directive. Map clauses are +/// allowed to use with this directive. The following example declares a user +/// defined mapper for the type 'struct vec'. This example instructs the fields +/// 'len' and 'data' should be mapped when mapping instances of 'struct vec'. +/// +/// \code +/// #pragma omp declare mapper(mid: struct vec v) map(v.len, v.data[0:N]) +/// \endcode +class OMPDeclareMapperDecl final : public ValueDecl, public DeclContext { + friend class ASTDeclReader; + + /// Clauses assoicated with this mapper declaration + MutableArrayRef<OMPClause *> Clauses; + + /// Mapper variable, which is 'v' in the example above + Expr *MapperVarRef = nullptr; + + /// Name of the mapper variable + DeclarationName VarName; + + LazyDeclPtr PrevDeclInScope; + + virtual void anchor(); + + OMPDeclareMapperDecl(Kind DK, DeclContext *DC, SourceLocation L, + DeclarationName Name, QualType Ty, + DeclarationName VarName, + OMPDeclareMapperDecl *PrevDeclInScope) + : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), VarName(VarName), + PrevDeclInScope(PrevDeclInScope) {} + + void setPrevDeclInScope(OMPDeclareMapperDecl *Prev) { + PrevDeclInScope = Prev; + } + + /// Sets an array of clauses to this mapper declaration + void setClauses(ArrayRef<OMPClause *> CL); + +public: + /// Creates declare mapper node. + static OMPDeclareMapperDecl *Create(ASTContext &C, DeclContext *DC, + SourceLocation L, DeclarationName Name, + QualType T, DeclarationName VarName, + OMPDeclareMapperDecl *PrevDeclInScope); + /// Creates deserialized declare mapper node. + static OMPDeclareMapperDecl *CreateDeserialized(ASTContext &C, unsigned ID, + unsigned N); + + /// Creates an array of clauses to this mapper declaration and intializes + /// them. + void CreateClauses(ASTContext &C, ArrayRef<OMPClause *> CL); + + using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator; + using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator; + using clauselist_range = llvm::iterator_range<clauselist_iterator>; + using clauselist_const_range = + llvm::iterator_range<clauselist_const_iterator>; + + unsigned clauselist_size() const { return Clauses.size(); } + bool clauselist_empty() const { return Clauses.empty(); } + + clauselist_range clauselists() { + return clauselist_range(clauselist_begin(), clauselist_end()); + } + clauselist_const_range clauselists() const { + return clauselist_const_range(clauselist_begin(), clauselist_end()); + } + clauselist_iterator clauselist_begin() { return Clauses.begin(); } + clauselist_iterator clauselist_end() { return Clauses.end(); } + clauselist_const_iterator clauselist_begin() const { return Clauses.begin(); } + clauselist_const_iterator clauselist_end() const { return Clauses.end(); } + + /// Get the variable declared in the mapper + Expr *getMapperVarRef() { return MapperVarRef; } + const Expr *getMapperVarRef() const { return MapperVarRef; } + /// Set the variable declared in the mapper + void setMapperVarRef(Expr *MapperVarRefE) { MapperVarRef = MapperVarRefE; } + + /// Get the name of the variable declared in the mapper + DeclarationName getVarName() { return VarName; } + + /// Get reference to previous declare mapper construct in the same + /// scope with the same name. + OMPDeclareMapperDecl *getPrevDeclInScope() { + return cast_or_null<OMPDeclareMapperDecl>( + PrevDeclInScope.get(getASTContext().getExternalSource())); + } + const OMPDeclareMapperDecl *getPrevDeclInScope() const { + return cast_or_null<OMPDeclareMapperDecl>( + PrevDeclInScope.get(getASTContext().getExternalSource())); + } + + static bool classof(const Decl *D) { return classofKind(D->getKind()); } + static bool classofKind(Kind K) { return K == OMPDeclareMapper; } + static DeclContext *castToDeclContext(const OMPDeclareMapperDecl *D) { + return static_cast<DeclContext *>(const_cast<OMPDeclareMapperDecl *>(D)); + } + static OMPDeclareMapperDecl *castFromDeclContext(const DeclContext *DC) { + return static_cast<OMPDeclareMapperDecl *>(const_cast<DeclContext *>(DC)); + } +}; + /// Pseudo declaration for capturing expressions. Also is used for capturing of /// non-static data members in non-static member functions. /// diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 51050e80af2..224e5b3480b 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -1590,7 +1590,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { TRY_TO(TraverseStmt(I)); } }) - + DEF_TRAVERSE_DECL(OMPRequiresDecl, { for (auto *C : D->clauselists()) { TRY_TO(TraverseOMPClause(C)); @@ -1605,6 +1605,13 @@ DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, { return true; }) +DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, { + for (auto *C : D->clauselists()) + TRY_TO(TraverseOMPClause(C)); + TRY_TO(TraverseType(D->getType())); + return true; +}) + DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); }) // A helper method for TemplateDecl's children. diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td index a184b480f7c..74a6bf32478 100644 --- a/clang/include/clang/Basic/DeclNodes.td +++ b/clang/include/clang/Basic/DeclNodes.td @@ -41,6 +41,7 @@ def Named : Decl<"named declarations", 1>; def IndirectField : DDecl<Value>; def Binding : DDecl<Value>; def OMPDeclareReduction : DDecl<Value>, DeclContext; + def OMPDeclareMapper : DDecl<Value>, DeclContext; def Declarator : DDecl<Value, "declarators", 1>; def Field : DDecl<Declarator, "non-static data members">; def ObjCIvar : DDecl<Field>; diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index a5dc23ec85a..e6eb3040a52 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1176,6 +1176,10 @@ def err_omp_declare_target_unexpected_clause: Error< "unexpected '%0' clause, only 'to' or 'link' clauses expected">; def err_omp_expected_clause: Error< "expected at least one clause on '#pragma omp %0' directive">; +def err_omp_mapper_illegal_identifier : Error< + "illegal identifier on 'omp declare mapper' directive">; +def err_omp_mapper_expected_declarator : Error< + "expected declarator on 'omp declare mapper' directive">; // Pragma loop support. def err_pragma_loop_missing_argument : Error< diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 32c92e4632b..4271833beca 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8977,6 +8977,12 @@ def err_omp_parent_cancel_region_ordered : Error< def err_omp_reduction_wrong_type : Error<"reduction type cannot be %select{qualified with 'const', 'volatile' or 'restrict'|a function|a reference|an array}0 type">; def err_omp_wrong_var_in_declare_reduction : Error<"only %select{'omp_priv' or 'omp_orig'|'omp_in' or 'omp_out'}0 variables are allowed in %select{initializer|combiner}0 expression">; def err_omp_declare_reduction_redefinition : Error<"redefinition of user-defined reduction for type %0">; +def err_omp_mapper_wrong_type : Error< + "mapper type must be of struct, union or class type">; +def err_omp_declare_mapper_wrong_var : Error< + "only variable %0 is allowed in map clauses of this 'omp declare mapper' directive">; +def err_omp_declare_mapper_redefinition : Error< + "redefinition of user-defined mapper for type %0 with name %1">; def err_omp_array_section_use : Error<"OpenMP array section is not allowed here">; def err_omp_typecheck_section_value : Error< "subscripted value is not an array or pointer">; diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def index 7fd28f0c456..9e92c0ac225 100644 --- a/clang/include/clang/Basic/OpenMPKinds.def +++ b/clang/include/clang/Basic/OpenMPKinds.def @@ -179,6 +179,9 @@ #ifndef OPENMP_TASKGROUP_CLAUSE #define OPENMP_TASKGROUP_CLAUSE(Name) #endif +#ifndef OPENMP_DECLARE_MAPPER_CLAUSE +#define OPENMP_DECLARE_MAPPER_CLAUSE(Name) +#endif // OpenMP directives. OPENMP_DIRECTIVE(threadprivate) @@ -214,6 +217,7 @@ OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections") OPENMP_DIRECTIVE_EXT(for_simd, "for simd") OPENMP_DIRECTIVE_EXT(cancellation_point, "cancellation point") OPENMP_DIRECTIVE_EXT(declare_reduction, "declare reduction") +OPENMP_DIRECTIVE_EXT(declare_mapper, "declare mapper") OPENMP_DIRECTIVE_EXT(declare_simd, "declare simd") OPENMP_DIRECTIVE(taskloop) OPENMP_DIRECTIVE_EXT(taskloop_simd, "taskloop simd") @@ -887,6 +891,10 @@ OPENMP_TARGET_TEAMS_DISTRIBUTE_SIMD_CLAUSE(simdlen) // Clauses allowed for OpenMP directive 'taskgroup'. OPENMP_TASKGROUP_CLAUSE(task_reduction) +// Clauses allowed for OpenMP directive 'declare mapper'. +OPENMP_DECLARE_MAPPER_CLAUSE(map) + +#undef OPENMP_DECLARE_MAPPER_CLAUSE #undef OPENMP_TASKGROUP_CLAUSE #undef OPENMP_TASKLOOP_SIMD_CLAUSE #undef OPENMP_TASKLOOP_CLAUSE diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index e6e2bc36521..f5c70e71b8a 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2803,6 +2803,13 @@ private: /// initializer. void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm); + /// Parses 'omp declare mapper' directive. + DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS); + /// Parses variable declaration in 'omp declare mapper' directive. + TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range, + DeclarationName &Name, + AccessSpecifier AS = AS_none); + /// Parses simple list of variables. /// /// \param Kind Kind of the directive. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1c756427168..23eceef7c9e 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3155,6 +3155,8 @@ public: LookupObjCImplicitSelfParam, /// Look up the name of an OpenMP user-defined reduction operation. LookupOMPReductionName, + /// Look up the name of an OpenMP user-defined mapper. + LookupOMPMapperName, /// Look up any declaration with any name. LookupAnyName }; @@ -8870,6 +8872,27 @@ public: DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); + /// Check variable declaration in 'omp declare mapper' construct. + TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); + /// Check if the specified type is allowed to be used in 'omp declare + /// mapper' construct. + QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, + TypeResult ParsedType); + /// Called on start of '#pragma omp declare mapper'. + OMPDeclareMapperDecl *ActOnOpenMPDeclareMapperDirectiveStart( + Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, + SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, + Decl *PrevDeclInScope = nullptr); + /// Build the mapper variable of '#pragma omp declare mapper'. + void ActOnOpenMPDeclareMapperDirectiveVarDecl(OMPDeclareMapperDecl *DMD, + Scope *S, QualType MapperType, + SourceLocation StartLoc, + DeclarationName VN); + /// Called at the end of '#pragma omp declare mapper'. + DeclGroupPtrTy + ActOnOpenMPDeclareMapperDirectiveEnd(OMPDeclareMapperDecl *D, Scope *S, + ArrayRef<OMPClause *> ClauseList); + /// Called on the start of target region i.e. '#pragma omp declare target'. bool ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc); /// Called at the end of target region i.e. '#pragme omp end declare target'. diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index 5aed4e9f24e..a1ab6116641 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1537,6 +1537,9 @@ namespace serialization { /// A PragmaDetectMismatchDecl record. DECL_PRAGMA_DETECT_MISMATCH, + /// An OMPDeclareMapperDecl record. + DECL_OMP_DECLARE_MAPPER, + /// An OMPDeclareReductionDecl record. DECL_OMP_DECLARE_REDUCTION, |