| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9 | /// This file implements semantic analysis for OpenMP directives and |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 10 | /// clauses. |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 17 | #include "clang/AST/CXXInheritance.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 24 | #include "clang/AST/TypeOrdering.h" |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 25 | #include "clang/Basic/OpenMPKinds.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Initialization.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Lookup.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Scope.h" |
| 29 | #include "clang/Sema/ScopeInfo.h" |
| Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 30 | #include "clang/Sema/SemaInternal.h" |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/PointerEmbeddedInt.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 38 | static const Expr *checkMapClauseExpressionBase( |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 39 | Sema &SemaRef, Expr *E, |
| 40 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 41 | OpenMPClauseKind CKind, bool NoDiagnose); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 42 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 43 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 44 | /// Default data sharing attributes, which can be applied to directive. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 45 | enum DefaultDataSharingAttributes { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 46 | DSA_unspecified = 0, /// Data sharing attribute not specified. |
| 47 | DSA_none = 1 << 0, /// Default data sharing attribute 'none'. |
| 48 | DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'. |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 51 | /// Stack for tracking declarations used in OpenMP directives and |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 52 | /// clauses and their data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 53 | class DSAStackTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 54 | public: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 55 | struct DSAVarData { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 56 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 57 | OpenMPClauseKind CKind = OMPC_unknown; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 58 | const Expr *RefExpr = nullptr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 59 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 60 | SourceLocation ImplicitDSALoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 61 | DSAVarData() = default; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 62 | DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 63 | const Expr *RefExpr, DeclRefExpr *PrivateCopy, |
| 64 | SourceLocation ImplicitDSALoc) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 65 | : DKind(DKind), CKind(CKind), RefExpr(RefExpr), |
| 66 | PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {} |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 67 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 68 | using OperatorOffsetTy = |
| 69 | llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4>; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 70 | using DoacrossDependMapTy = |
| 71 | llvm::DenseMap<OMPDependClause *, OperatorOffsetTy>; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 72 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 73 | private: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 74 | struct DSAInfo { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 75 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 76 | /// Pointer to a reference expression and a flag which shows that the |
| 77 | /// variable is marked as lastprivate(true) or not (false). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 78 | llvm::PointerIntPair<const Expr *, 1, bool> RefExpr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 79 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 80 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 81 | using DeclSAMapTy = llvm::SmallDenseMap<const ValueDecl *, DSAInfo, 8>; |
| 82 | using AlignedMapTy = llvm::SmallDenseMap<const ValueDecl *, const Expr *, 8>; |
| 83 | using LCDeclInfo = std::pair<unsigned, VarDecl *>; |
| 84 | using LoopControlVariablesMapTy = |
| 85 | llvm::SmallDenseMap<const ValueDecl *, LCDeclInfo, 8>; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 86 | /// Struct that associates a component with the clause kind where they are |
| 87 | /// found. |
| 88 | struct MappedExprComponentTy { |
| 89 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 90 | OpenMPClauseKind Kind = OMPC_unknown; |
| 91 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 92 | using MappedExprComponentsTy = |
| 93 | llvm::DenseMap<const ValueDecl *, MappedExprComponentTy>; |
| 94 | using CriticalsWithHintsTy = |
| 95 | llvm::StringMap<std::pair<const OMPCriticalDirective *, llvm::APSInt>>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 96 | struct ReductionData { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 97 | using BOKPtrType = llvm::PointerEmbeddedInt<BinaryOperatorKind, 16>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 98 | SourceRange ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 99 | llvm::PointerUnion<const Expr *, BOKPtrType> ReductionOp; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 100 | ReductionData() = default; |
| 101 | void set(BinaryOperatorKind BO, SourceRange RR) { |
| 102 | ReductionRange = RR; |
| 103 | ReductionOp = BO; |
| 104 | } |
| 105 | void set(const Expr *RefExpr, SourceRange RR) { |
| 106 | ReductionRange = RR; |
| 107 | ReductionOp = RefExpr; |
| 108 | } |
| 109 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 110 | using DeclReductionMapTy = |
| 111 | llvm::SmallDenseMap<const ValueDecl *, ReductionData, 4>; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 112 | struct DefaultmapInfo { |
| 113 | OpenMPDefaultmapClauseModifier ImplicitBehavior = |
| 114 | OMPC_DEFAULTMAP_MODIFIER_unknown; |
| 115 | SourceLocation SLoc; |
| 116 | DefaultmapInfo() = default; |
| 117 | DefaultmapInfo(OpenMPDefaultmapClauseModifier M, SourceLocation Loc) |
| 118 | : ImplicitBehavior(M), SLoc(Loc) {} |
| 119 | }; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 120 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 121 | struct SharingMapTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | DeclSAMapTy SharingMap; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 123 | DeclReductionMapTy ReductionMap; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 124 | AlignedMapTy AlignedMap; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 125 | MappedExprComponentsTy MappedExprComponents; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 126 | LoopControlVariablesMapTy LCVMap; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 127 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 128 | SourceLocation DefaultAttrLoc; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 129 | DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 130 | OpenMPDirectiveKind Directive = OMPD_unknown; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 131 | DeclarationNameInfo DirectiveName; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 132 | Scope *CurScope = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 133 | SourceLocation ConstructLoc; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 134 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 135 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 136 | /// This data is required during codegen. |
| 137 | DoacrossDependMapTy DoacrossDepends; |
| Patrick Lyster | 1647194 | 2019-02-06 18:18:02 +0000 | [diff] [blame] | 138 | /// First argument (Expr *) contains optional argument of the |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 139 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 140 | /// clause, false otherwise. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 141 | llvm::Optional<std::pair<const Expr *, OMPOrderedClause *>> OrderedRegion; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 142 | unsigned AssociatedLoops = 1; |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 143 | bool HasMutipleLoops = false; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 144 | const Decl *PossiblyLoopCounter = nullptr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 145 | bool NowaitRegion = false; |
| 146 | bool CancelRegion = false; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 147 | bool LoopStart = false; |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 148 | bool BodyComplete = false; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 149 | SourceLocation InnerTeamsRegionLoc; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 150 | /// Reference to the taskgroup task_reduction reference expression. |
| 151 | Expr *TaskgroupReductionRef = nullptr; |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 152 | llvm::DenseSet<QualType> MappedClassesQualTypes; |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 153 | /// List of globals marked as declare target link in this target region |
| 154 | /// (isOpenMPTargetExecutionDirective(Directive) == true). |
| 155 | llvm::SmallVector<DeclRefExpr *, 4> DeclareTargetLinkVarDecls; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 156 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 157 | Scope *CurScope, SourceLocation Loc) |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 158 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 159 | ConstructLoc(Loc) {} |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 160 | SharingMapTy() = default; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 163 | using StackTy = SmallVector<SharingMapTy, 4>; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 164 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 165 | /// Stack of used declaration and their data-sharing attributes. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 166 | DeclSAMapTy Threadprivates; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 167 | const FunctionScopeInfo *CurrentNonCapturingFunctionScope = nullptr; |
| 168 | SmallVector<std::pair<StackTy, const FunctionScopeInfo *>, 4> Stack; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 169 | /// true, if check for DSA must be from parent directive, false, if |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 170 | /// from current directive. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 171 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 172 | Sema &SemaRef; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 173 | bool ForceCapturing = false; |
| Alexey Bataev | d1caf93 | 2019-09-30 14:05:26 +0000 | [diff] [blame] | 174 | /// true if all the variables in the target executable directives must be |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 175 | /// captured by reference. |
| 176 | bool ForceCaptureByReferenceInTargetExecutable = false; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 177 | CriticalsWithHintsTy Criticals; |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 178 | unsigned IgnoredStackElements = 0; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 179 | |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 180 | /// Iterators over the stack iterate in order from innermost to outermost |
| 181 | /// directive. |
| 182 | using const_iterator = StackTy::const_reverse_iterator; |
| 183 | const_iterator begin() const { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 184 | return Stack.empty() ? const_iterator() |
| 185 | : Stack.back().first.rbegin() + IgnoredStackElements; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 186 | } |
| 187 | const_iterator end() const { |
| 188 | return Stack.empty() ? const_iterator() : Stack.back().first.rend(); |
| 189 | } |
| 190 | using iterator = StackTy::reverse_iterator; |
| 191 | iterator begin() { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 192 | return Stack.empty() ? iterator() |
| 193 | : Stack.back().first.rbegin() + IgnoredStackElements; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 194 | } |
| 195 | iterator end() { |
| 196 | return Stack.empty() ? iterator() : Stack.back().first.rend(); |
| 197 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 198 | |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 199 | // Convenience operations to get at the elements of the stack. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 200 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 201 | bool isStackEmpty() const { |
| 202 | return Stack.empty() || |
| 203 | Stack.back().second != CurrentNonCapturingFunctionScope || |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 204 | Stack.back().first.size() <= IgnoredStackElements; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 205 | } |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 206 | size_t getStackSize() const { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 207 | return isStackEmpty() ? 0 |
| 208 | : Stack.back().first.size() - IgnoredStackElements; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | SharingMapTy *getTopOfStackOrNull() { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 212 | size_t Size = getStackSize(); |
| 213 | if (Size == 0) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 214 | return nullptr; |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 215 | return &Stack.back().first[Size - 1]; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 216 | } |
| 217 | const SharingMapTy *getTopOfStackOrNull() const { |
| 218 | return const_cast<DSAStackTy&>(*this).getTopOfStackOrNull(); |
| 219 | } |
| 220 | SharingMapTy &getTopOfStack() { |
| 221 | assert(!isStackEmpty() && "no current directive"); |
| 222 | return *getTopOfStackOrNull(); |
| 223 | } |
| 224 | const SharingMapTy &getTopOfStack() const { |
| 225 | return const_cast<DSAStackTy&>(*this).getTopOfStack(); |
| 226 | } |
| 227 | |
| 228 | SharingMapTy *getSecondOnStackOrNull() { |
| 229 | size_t Size = getStackSize(); |
| 230 | if (Size <= 1) |
| 231 | return nullptr; |
| 232 | return &Stack.back().first[Size - 2]; |
| 233 | } |
| 234 | const SharingMapTy *getSecondOnStackOrNull() const { |
| 235 | return const_cast<DSAStackTy&>(*this).getSecondOnStackOrNull(); |
| 236 | } |
| 237 | |
| 238 | /// Get the stack element at a certain level (previously returned by |
| 239 | /// \c getNestingLevel). |
| 240 | /// |
| 241 | /// Note that nesting levels count from outermost to innermost, and this is |
| 242 | /// the reverse of our iteration order where new inner levels are pushed at |
| 243 | /// the front of the stack. |
| 244 | SharingMapTy &getStackElemAtLevel(unsigned Level) { |
| 245 | assert(Level < getStackSize() && "no such stack element"); |
| 246 | return Stack.back().first[Level]; |
| 247 | } |
| 248 | const SharingMapTy &getStackElemAtLevel(unsigned Level) const { |
| 249 | return const_cast<DSAStackTy&>(*this).getStackElemAtLevel(Level); |
| 250 | } |
| 251 | |
| 252 | DSAVarData getDSA(const_iterator &Iter, ValueDecl *D) const; |
| 253 | |
| 254 | /// Checks if the variable is a local for OpenMP region. |
| 255 | bool isOpenMPLocal(VarDecl *D, const_iterator Iter) const; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 256 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 257 | /// Vector of previously declared requires directives |
| 258 | SmallVector<const OMPRequiresDecl *, 2> RequiresDecls; |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 259 | /// omp_allocator_handle_t type. |
| 260 | QualType OMPAllocatorHandleT; |
| 261 | /// Expression for the predefined allocators. |
| 262 | Expr *OMPPredefinedAllocators[OMPAllocateDeclAttr::OMPUserDefinedMemAlloc] = { |
| 263 | nullptr}; |
| Gheorghe-Teodor Bercea | 411a624 | 2019-04-18 19:53:43 +0000 | [diff] [blame] | 264 | /// Vector of previously encountered target directives |
| 265 | SmallVector<SourceLocation, 2> TargetLocations; |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 266 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | public: |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 268 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 269 | |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 270 | /// Sets omp_allocator_handle_t type. |
| 271 | void setOMPAllocatorHandleT(QualType Ty) { OMPAllocatorHandleT = Ty; } |
| 272 | /// Gets omp_allocator_handle_t type. |
| 273 | QualType getOMPAllocatorHandleT() const { return OMPAllocatorHandleT; } |
| 274 | /// Sets the given default allocator. |
| 275 | void setAllocator(OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, |
| 276 | Expr *Allocator) { |
| 277 | OMPPredefinedAllocators[AllocatorKind] = Allocator; |
| 278 | } |
| 279 | /// Returns the specified default allocator. |
| 280 | Expr *getAllocator(OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind) const { |
| 281 | return OMPPredefinedAllocators[AllocatorKind]; |
| 282 | } |
| 283 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 284 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 285 | OpenMPClauseKind getClauseParsingMode() const { |
| 286 | assert(isClauseParsingMode() && "Must be in clause parsing mode."); |
| 287 | return ClauseKindMode; |
| 288 | } |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 289 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 290 | |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 291 | bool isBodyComplete() const { |
| 292 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 293 | return Top && Top->BodyComplete; |
| 294 | } |
| 295 | void setBodyComplete() { |
| 296 | getTopOfStack().BodyComplete = true; |
| 297 | } |
| 298 | |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 299 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 300 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 301 | |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 302 | void setForceCaptureByReferenceInTargetExecutable(bool V) { |
| 303 | ForceCaptureByReferenceInTargetExecutable = V; |
| 304 | } |
| 305 | bool isForceCaptureByReferenceInTargetExecutable() const { |
| 306 | return ForceCaptureByReferenceInTargetExecutable; |
| 307 | } |
| 308 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 309 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 310 | Scope *CurScope, SourceLocation Loc) { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 311 | assert(!IgnoredStackElements && |
| 312 | "cannot change stack while ignoring elements"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 313 | if (Stack.empty() || |
| 314 | Stack.back().second != CurrentNonCapturingFunctionScope) |
| 315 | Stack.emplace_back(StackTy(), CurrentNonCapturingFunctionScope); |
| 316 | Stack.back().first.emplace_back(DKind, DirName, CurScope, Loc); |
| 317 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void pop() { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 321 | assert(!IgnoredStackElements && |
| 322 | "cannot change stack while ignoring elements"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 323 | assert(!Stack.back().first.empty() && |
| 324 | "Data-sharing attributes stack is empty!"); |
| 325 | Stack.back().first.pop_back(); |
| 326 | } |
| 327 | |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 328 | /// RAII object to temporarily leave the scope of a directive when we want to |
| 329 | /// logically operate in its parent. |
| 330 | class ParentDirectiveScope { |
| 331 | DSAStackTy &Self; |
| 332 | bool Active; |
| 333 | public: |
| 334 | ParentDirectiveScope(DSAStackTy &Self, bool Activate) |
| 335 | : Self(Self), Active(false) { |
| 336 | if (Activate) |
| 337 | enable(); |
| 338 | } |
| 339 | ~ParentDirectiveScope() { disable(); } |
| 340 | void disable() { |
| 341 | if (Active) { |
| 342 | --Self.IgnoredStackElements; |
| 343 | Active = false; |
| 344 | } |
| 345 | } |
| 346 | void enable() { |
| 347 | if (!Active) { |
| 348 | ++Self.IgnoredStackElements; |
| 349 | Active = true; |
| 350 | } |
| 351 | } |
| 352 | }; |
| 353 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 354 | /// Marks that we're started loop parsing. |
| 355 | void loopInit() { |
| 356 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 357 | "Expected loop-based directive."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 358 | getTopOfStack().LoopStart = true; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 359 | } |
| 360 | /// Start capturing of the variables in the loop context. |
| 361 | void loopStart() { |
| 362 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 363 | "Expected loop-based directive."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 364 | getTopOfStack().LoopStart = false; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 365 | } |
| 366 | /// true, if variables are captured, false otherwise. |
| 367 | bool isLoopStarted() const { |
| 368 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 369 | "Expected loop-based directive."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 370 | return !getTopOfStack().LoopStart; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 371 | } |
| 372 | /// Marks (or clears) declaration as possibly loop counter. |
| 373 | void resetPossibleLoopCounter(const Decl *D = nullptr) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 374 | getTopOfStack().PossiblyLoopCounter = |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 375 | D ? D->getCanonicalDecl() : D; |
| 376 | } |
| 377 | /// Gets the possible loop counter decl. |
| 378 | const Decl *getPossiblyLoopCunter() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 379 | return getTopOfStack().PossiblyLoopCounter; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 380 | } |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 381 | /// Start new OpenMP region stack in new non-capturing function. |
| 382 | void pushFunction() { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 383 | assert(!IgnoredStackElements && |
| 384 | "cannot change stack while ignoring elements"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 385 | const FunctionScopeInfo *CurFnScope = SemaRef.getCurFunction(); |
| 386 | assert(!isa<CapturingScopeInfo>(CurFnScope)); |
| 387 | CurrentNonCapturingFunctionScope = CurFnScope; |
| 388 | } |
| 389 | /// Pop region stack for non-capturing function. |
| 390 | void popFunction(const FunctionScopeInfo *OldFSI) { |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 391 | assert(!IgnoredStackElements && |
| 392 | "cannot change stack while ignoring elements"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 393 | if (!Stack.empty() && Stack.back().second == OldFSI) { |
| 394 | assert(Stack.back().first.empty()); |
| 395 | Stack.pop_back(); |
| 396 | } |
| 397 | CurrentNonCapturingFunctionScope = nullptr; |
| 398 | for (const FunctionScopeInfo *FSI : llvm::reverse(SemaRef.FunctionScopes)) { |
| 399 | if (!isa<CapturingScopeInfo>(FSI)) { |
| 400 | CurrentNonCapturingFunctionScope = FSI; |
| 401 | break; |
| 402 | } |
| 403 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 406 | void addCriticalWithHint(const OMPCriticalDirective *D, llvm::APSInt Hint) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 407 | Criticals.try_emplace(D->getDirectiveName().getAsString(), D, Hint); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 408 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 409 | const std::pair<const OMPCriticalDirective *, llvm::APSInt> |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 410 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 411 | auto I = Criticals.find(Name.getAsString()); |
| 412 | if (I != Criticals.end()) |
| 413 | return I->second; |
| 414 | return std::make_pair(nullptr, llvm::APSInt()); |
| 415 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 416 | /// If 'aligned' declaration for given variable \a D was not seen yet, |
| Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 417 | /// add it and return NULL; otherwise return previous occurrence's expression |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 418 | /// for diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 419 | const Expr *addUniqueAligned(const ValueDecl *D, const Expr *NewDE); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 420 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 421 | /// Register specified variable as loop control variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 422 | void addLoopControlVariable(const ValueDecl *D, VarDecl *Capture); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 423 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 424 | /// current region. |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 425 | /// \return The index of the loop control variable in the list of associated |
| 426 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 427 | const LCDeclInfo isLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 428 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 429 | /// parent region. |
| 430 | /// \return The index of the loop control variable in the list of associated |
| 431 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 432 | const LCDeclInfo isParentLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 433 | /// Get the loop control variable for the I-th loop (or nullptr) in |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 434 | /// parent directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 435 | const ValueDecl *getParentLoopControlVariable(unsigned I) const; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 436 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 437 | /// Adds explicit data sharing attribute to the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 438 | void addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 439 | DeclRefExpr *PrivateCopy = nullptr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 440 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 441 | /// Adds additional information for the reduction items with the reduction id |
| 442 | /// represented as an operator. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 443 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 444 | BinaryOperatorKind BOK); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 445 | /// Adds additional information for the reduction items with the reduction id |
| 446 | /// represented as reduction identifier. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 447 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 448 | const Expr *ReductionRef); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 449 | /// Returns the location and reduction operation from the innermost parent |
| 450 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 451 | const DSAVarData |
| 452 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 453 | BinaryOperatorKind &BOK, |
| 454 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 455 | /// Returns the location and reduction operation from the innermost parent |
| 456 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 457 | const DSAVarData |
| 458 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 459 | const Expr *&ReductionRef, |
| 460 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 461 | /// Return reduction reference expression for the current taskgroup. |
| 462 | Expr *getTaskgroupReductionRef() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 463 | assert(getTopOfStack().Directive == OMPD_taskgroup && |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 464 | "taskgroup reference expression requested for non taskgroup " |
| 465 | "directive."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 466 | return getTopOfStack().TaskgroupReductionRef; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 467 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 468 | /// Checks if the given \p VD declaration is actually a taskgroup reduction |
| 469 | /// descriptor variable at the \p Level of OpenMP regions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 470 | bool isTaskgroupReductionRef(const ValueDecl *VD, unsigned Level) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 471 | return getStackElemAtLevel(Level).TaskgroupReductionRef && |
| 472 | cast<DeclRefExpr>(getStackElemAtLevel(Level).TaskgroupReductionRef) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 473 | ->getDecl() == VD; |
| 474 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 475 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 476 | /// Returns data sharing attributes from top of the stack for the |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | /// specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 478 | const DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 479 | /// Returns data-sharing attributes for the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 480 | const DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 481 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 482 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 483 | /// predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 484 | const DSAVarData |
| 485 | hasDSA(ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 486 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 487 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 488 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 489 | /// match specified \a CPred predicate in any innermost directive which |
| 490 | /// matches \a DPred predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 491 | const DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 492 | hasInnermostDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 493 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 494 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 495 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 496 | /// Checks if the specified variables has explicit data-sharing |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 497 | /// attributes which match specified \a CPred predicate at the specified |
| 498 | /// OpenMP region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 499 | bool hasExplicitDSA(const ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 500 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 501 | unsigned Level, bool NotLastprivate = false) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 502 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 503 | /// Returns true if the directive at level \Level matches in the |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 504 | /// specified \a DPred predicate. |
| 505 | bool hasExplicitDirective( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 506 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 507 | unsigned Level) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 508 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 509 | /// Finds a directive which matches specified \a DPred predicate. |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 510 | bool hasDirective( |
| 511 | const llvm::function_ref<bool( |
| 512 | OpenMPDirectiveKind, const DeclarationNameInfo &, SourceLocation)> |
| 513 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 514 | bool FromParent) const; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 515 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 516 | /// Returns currently analyzed directive. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 517 | OpenMPDirectiveKind getCurrentDirective() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 518 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 519 | return Top ? Top->Directive : OMPD_unknown; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 520 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 521 | /// Returns directive kind at specified level. |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 522 | OpenMPDirectiveKind getDirective(unsigned Level) const { |
| 523 | assert(!isStackEmpty() && "No directive at specified level."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 524 | return getStackElemAtLevel(Level).Directive; |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 525 | } |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 526 | /// Returns the capture region at the specified level. |
| 527 | OpenMPDirectiveKind getCaptureRegion(unsigned Level, |
| 528 | unsigned OpenMPCaptureLevel) const { |
| 529 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 530 | getOpenMPCaptureRegions(CaptureRegions, getDirective(Level)); |
| 531 | return CaptureRegions[OpenMPCaptureLevel]; |
| 532 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 533 | /// Returns parent directive. |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 534 | OpenMPDirectiveKind getParentDirective() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 535 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
| 536 | return Parent ? Parent->Directive : OMPD_unknown; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 537 | } |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 538 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 539 | /// Add requires decl to internal vector |
| 540 | void addRequiresDecl(OMPRequiresDecl *RD) { |
| 541 | RequiresDecls.push_back(RD); |
| 542 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 543 | |
| Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 544 | /// Checks if the defined 'requires' directive has specified type of clause. |
| 545 | template <typename ClauseType> |
| 546 | bool hasRequiresDeclWithClause() { |
| 547 | return llvm::any_of(RequiresDecls, [](const OMPRequiresDecl *D) { |
| 548 | return llvm::any_of(D->clauselists(), [](const OMPClause *C) { |
| 549 | return isa<ClauseType>(C); |
| 550 | }); |
| 551 | }); |
| 552 | } |
| 553 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 554 | /// Checks for a duplicate clause amongst previously declared requires |
| 555 | /// directives |
| 556 | bool hasDuplicateRequiresClause(ArrayRef<OMPClause *> ClauseList) const { |
| 557 | bool IsDuplicate = false; |
| 558 | for (OMPClause *CNew : ClauseList) { |
| 559 | for (const OMPRequiresDecl *D : RequiresDecls) { |
| 560 | for (const OMPClause *CPrev : D->clauselists()) { |
| 561 | if (CNew->getClauseKind() == CPrev->getClauseKind()) { |
| 562 | SemaRef.Diag(CNew->getBeginLoc(), |
| 563 | diag::err_omp_requires_clause_redeclaration) |
| 564 | << getOpenMPClauseName(CNew->getClauseKind()); |
| 565 | SemaRef.Diag(CPrev->getBeginLoc(), |
| 566 | diag::note_omp_requires_previous_clause) |
| 567 | << getOpenMPClauseName(CPrev->getClauseKind()); |
| 568 | IsDuplicate = true; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | return IsDuplicate; |
| 574 | } |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 575 | |
| Gheorghe-Teodor Bercea | 411a624 | 2019-04-18 19:53:43 +0000 | [diff] [blame] | 576 | /// Add location of previously encountered target to internal vector |
| 577 | void addTargetDirLocation(SourceLocation LocStart) { |
| 578 | TargetLocations.push_back(LocStart); |
| 579 | } |
| 580 | |
| 581 | // Return previously encountered target region locations. |
| 582 | ArrayRef<SourceLocation> getEncounteredTargetLocs() const { |
| 583 | return TargetLocations; |
| 584 | } |
| 585 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 586 | /// Set default data sharing attribute to none. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 587 | void setDefaultDSANone(SourceLocation Loc) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 588 | getTopOfStack().DefaultAttr = DSA_none; |
| 589 | getTopOfStack().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 590 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 591 | /// Set default data sharing attribute to shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 592 | void setDefaultDSAShared(SourceLocation Loc) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 593 | getTopOfStack().DefaultAttr = DSA_shared; |
| 594 | getTopOfStack().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 595 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 596 | /// Set default data mapping attribute to Modifier:Kind |
| 597 | void setDefaultDMAAttr(OpenMPDefaultmapClauseModifier M, |
| 598 | OpenMPDefaultmapClauseKind Kind, |
| 599 | SourceLocation Loc) { |
| 600 | DefaultmapInfo &DMI = getTopOfStack().DefaultmapMap[Kind]; |
| 601 | DMI.ImplicitBehavior = M; |
| 602 | DMI.SLoc = Loc; |
| 603 | } |
| 604 | /// Check whether the implicit-behavior has been set in defaultmap |
| 605 | bool checkDefaultmapCategory(OpenMPDefaultmapClauseKind VariableCategory) { |
| 606 | return getTopOfStack().DefaultmapMap[VariableCategory].ImplicitBehavior != |
| 607 | OMPC_DEFAULTMAP_MODIFIER_unknown; |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 608 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 609 | |
| 610 | DefaultDataSharingAttributes getDefaultDSA() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 611 | return isStackEmpty() ? DSA_unspecified |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 612 | : getTopOfStack().DefaultAttr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 613 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 614 | SourceLocation getDefaultDSALocation() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 615 | return isStackEmpty() ? SourceLocation() |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 616 | : getTopOfStack().DefaultAttrLoc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 617 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 618 | OpenMPDefaultmapClauseModifier |
| 619 | getDefaultmapModifier(OpenMPDefaultmapClauseKind Kind) const { |
| 620 | return isStackEmpty() |
| 621 | ? OMPC_DEFAULTMAP_MODIFIER_unknown |
| 622 | : getTopOfStack().DefaultmapMap[Kind].ImplicitBehavior; |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 623 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 624 | OpenMPDefaultmapClauseModifier |
| 625 | getDefaultmapModifierAtLevel(unsigned Level, |
| 626 | OpenMPDefaultmapClauseKind Kind) const { |
| 627 | return getStackElemAtLevel(Level).DefaultmapMap[Kind].ImplicitBehavior; |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 628 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 629 | bool isDefaultmapCapturedByRef(unsigned Level, |
| 630 | OpenMPDefaultmapClauseKind Kind) const { |
| 631 | OpenMPDefaultmapClauseModifier M = |
| 632 | getDefaultmapModifierAtLevel(Level, Kind); |
| 633 | if (Kind == OMPC_DEFAULTMAP_scalar || Kind == OMPC_DEFAULTMAP_pointer) { |
| 634 | return (M == OMPC_DEFAULTMAP_MODIFIER_alloc) || |
| 635 | (M == OMPC_DEFAULTMAP_MODIFIER_to) || |
| 636 | (M == OMPC_DEFAULTMAP_MODIFIER_from) || |
| 637 | (M == OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 638 | } |
| 639 | return true; |
| 640 | } |
| 641 | static bool mustBeFirstprivateBase(OpenMPDefaultmapClauseModifier M, |
| 642 | OpenMPDefaultmapClauseKind Kind) { |
| 643 | switch (Kind) { |
| 644 | case OMPC_DEFAULTMAP_scalar: |
| 645 | case OMPC_DEFAULTMAP_pointer: |
| 646 | return (M == OMPC_DEFAULTMAP_MODIFIER_unknown) || |
| 647 | (M == OMPC_DEFAULTMAP_MODIFIER_firstprivate) || |
| 648 | (M == OMPC_DEFAULTMAP_MODIFIER_default); |
| 649 | case OMPC_DEFAULTMAP_aggregate: |
| 650 | return M == OMPC_DEFAULTMAP_MODIFIER_firstprivate; |
| Simon Pilgrim | 1e3cc06 | 2019-11-18 11:42:14 +0000 | [diff] [blame] | 651 | default: |
| 652 | break; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 653 | } |
| Simon Pilgrim | 1e3cc06 | 2019-11-18 11:42:14 +0000 | [diff] [blame] | 654 | llvm_unreachable("Unexpected OpenMPDefaultmapClauseKind enum"); |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 655 | } |
| 656 | bool mustBeFirstprivateAtLevel(unsigned Level, |
| 657 | OpenMPDefaultmapClauseKind Kind) const { |
| 658 | OpenMPDefaultmapClauseModifier M = |
| 659 | getDefaultmapModifierAtLevel(Level, Kind); |
| 660 | return mustBeFirstprivateBase(M, Kind); |
| 661 | } |
| 662 | bool mustBeFirstprivate(OpenMPDefaultmapClauseKind Kind) const { |
| 663 | OpenMPDefaultmapClauseModifier M = getDefaultmapModifier(Kind); |
| 664 | return mustBeFirstprivateBase(M, Kind); |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 665 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 666 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 667 | /// Checks if the specified variable is a threadprivate. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 668 | bool isThreadPrivate(VarDecl *D) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 669 | const DSAVarData DVar = getTopDSA(D, false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 670 | return isOpenMPThreadPrivate(DVar.CKind); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 673 | /// Marks current region as ordered (it has an 'ordered' clause). |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 674 | void setOrderedRegion(bool IsOrdered, const Expr *Param, |
| 675 | OMPOrderedClause *Clause) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 676 | if (IsOrdered) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 677 | getTopOfStack().OrderedRegion.emplace(Param, Clause); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 678 | else |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 679 | getTopOfStack().OrderedRegion.reset(); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 680 | } |
| 681 | /// Returns true, if region is ordered (has associated 'ordered' clause), |
| 682 | /// false - otherwise. |
| 683 | bool isOrderedRegion() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 684 | if (const SharingMapTy *Top = getTopOfStackOrNull()) |
| 685 | return Top->OrderedRegion.hasValue(); |
| 686 | return false; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 687 | } |
| 688 | /// Returns optional parameter for the ordered region. |
| 689 | std::pair<const Expr *, OMPOrderedClause *> getOrderedRegionParam() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 690 | if (const SharingMapTy *Top = getTopOfStackOrNull()) |
| 691 | if (Top->OrderedRegion.hasValue()) |
| 692 | return Top->OrderedRegion.getValue(); |
| 693 | return std::make_pair(nullptr, nullptr); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 694 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 695 | /// Returns true, if parent region is ordered (has associated |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 696 | /// 'ordered' clause), false - otherwise. |
| 697 | bool isParentOrderedRegion() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 698 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
| 699 | return Parent->OrderedRegion.hasValue(); |
| 700 | return false; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 701 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 702 | /// Returns optional parameter for the ordered region. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 703 | std::pair<const Expr *, OMPOrderedClause *> |
| 704 | getParentOrderedRegionParam() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 705 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
| 706 | if (Parent->OrderedRegion.hasValue()) |
| 707 | return Parent->OrderedRegion.getValue(); |
| 708 | return std::make_pair(nullptr, nullptr); |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 709 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 710 | /// Marks current region as nowait (it has a 'nowait' clause). |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 711 | void setNowaitRegion(bool IsNowait = true) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 712 | getTopOfStack().NowaitRegion = IsNowait; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 713 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 714 | /// Returns true, if parent region is nowait (has associated |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 715 | /// 'nowait' clause), false - otherwise. |
| 716 | bool isParentNowaitRegion() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 717 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
| 718 | return Parent->NowaitRegion; |
| 719 | return false; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 720 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 721 | /// Marks parent region as cancel region. |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 722 | void setParentCancelRegion(bool Cancel = true) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 723 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
| 724 | Parent->CancelRegion |= Cancel; |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 725 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 726 | /// Return true if current region has inner cancel construct. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 727 | bool isCancelRegion() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 728 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 729 | return Top ? Top->CancelRegion : false; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 730 | } |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 731 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 732 | /// Set collapse value for the region. |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 733 | void setAssociatedLoops(unsigned Val) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 734 | getTopOfStack().AssociatedLoops = Val; |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 735 | if (Val > 1) |
| 736 | getTopOfStack().HasMutipleLoops = true; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 737 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 738 | /// Return collapse value for region. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 739 | unsigned getAssociatedLoops() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 740 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 741 | return Top ? Top->AssociatedLoops : 0; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 742 | } |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 743 | /// Returns true if the construct is associated with multiple loops. |
| 744 | bool hasMutipleLoops() const { |
| 745 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 746 | return Top ? Top->HasMutipleLoops : false; |
| 747 | } |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 748 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 749 | /// Marks current target region as one with closely nested teams |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 750 | /// region. |
| 751 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 752 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
| 753 | Parent->InnerTeamsRegionLoc = TeamsRegionLoc; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 754 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 755 | /// Returns true, if current region has closely nested teams region. |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 756 | bool hasInnerTeamsRegion() const { |
| 757 | return getInnerTeamsRegionLoc().isValid(); |
| 758 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 759 | /// Returns location of the nested teams region (if any). |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 760 | SourceLocation getInnerTeamsRegionLoc() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 761 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 762 | return Top ? Top->InnerTeamsRegionLoc : SourceLocation(); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 765 | Scope *getCurScope() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 766 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 767 | return Top ? Top->CurScope : nullptr; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 768 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 769 | SourceLocation getConstructLoc() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 770 | const SharingMapTy *Top = getTopOfStackOrNull(); |
| 771 | return Top ? Top->ConstructLoc : SourceLocation(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 772 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 773 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 774 | /// Do the check specified in \a Check to all component lists and return true |
| 775 | /// if any issue is found. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 776 | bool checkMappableExprComponentListsForDecl( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 777 | const ValueDecl *VD, bool CurrentRegionOnly, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 778 | const llvm::function_ref< |
| 779 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 780 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 781 | Check) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 782 | if (isStackEmpty()) |
| 783 | return false; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 784 | auto SI = begin(); |
| 785 | auto SE = end(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 786 | |
| 787 | if (SI == SE) |
| 788 | return false; |
| 789 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 790 | if (CurrentRegionOnly) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 791 | SE = std::next(SI); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 792 | else |
| 793 | std::advance(SI, 1); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 794 | |
| 795 | for (; SI != SE; ++SI) { |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 796 | auto MI = SI->MappedExprComponents.find(VD); |
| 797 | if (MI != SI->MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 798 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 799 | MI->second.Components) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 800 | if (Check(L, MI->second.Kind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 801 | return true; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 802 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 803 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 806 | /// Do the check specified in \a Check to all component lists at a given level |
| 807 | /// and return true if any issue is found. |
| 808 | bool checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 809 | const ValueDecl *VD, unsigned Level, |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 810 | const llvm::function_ref< |
| 811 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 812 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 813 | Check) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 814 | if (getStackSize() <= Level) |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 815 | return false; |
| 816 | |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 817 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
| 818 | auto MI = StackElem.MappedExprComponents.find(VD); |
| 819 | if (MI != StackElem.MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 820 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 821 | MI->second.Components) |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 822 | if (Check(L, MI->second.Kind)) |
| 823 | return true; |
| 824 | return false; |
| 825 | } |
| 826 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 827 | /// Create a new mappable expression component list associated with a given |
| 828 | /// declaration and initialize it with the provided list of components. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 829 | void addMappableExpressionComponents( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 830 | const ValueDecl *VD, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 831 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 832 | OpenMPClauseKind WhereFoundClauseKind) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 833 | MappedExprComponentTy &MEC = getTopOfStack().MappedExprComponents[VD]; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 834 | // Create new entry and append the new components there. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 835 | MEC.Components.resize(MEC.Components.size() + 1); |
| 836 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 837 | MEC.Kind = WhereFoundClauseKind; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 838 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 839 | |
| 840 | unsigned getNestingLevel() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 841 | assert(!isStackEmpty()); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 842 | return getStackSize() - 1; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 843 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 844 | void addDoacrossDependClause(OMPDependClause *C, |
| 845 | const OperatorOffsetTy &OpsOffs) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 846 | SharingMapTy *Parent = getSecondOnStackOrNull(); |
| 847 | assert(Parent && isOpenMPWorksharingDirective(Parent->Directive)); |
| 848 | Parent->DoacrossDepends.try_emplace(C, OpsOffs); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 849 | } |
| 850 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 851 | getDoacrossDependClauses() const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 852 | const SharingMapTy &StackElem = getTopOfStack(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 853 | if (isOpenMPWorksharingDirective(StackElem.Directive)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 854 | const DoacrossDependMapTy &Ref = StackElem.DoacrossDepends; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 855 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 856 | } |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 857 | return llvm::make_range(StackElem.DoacrossDepends.end(), |
| 858 | StackElem.DoacrossDepends.end()); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 859 | } |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 860 | |
| 861 | // Store types of classes which have been explicitly mapped |
| 862 | void addMappedClassesQualTypes(QualType QT) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 863 | SharingMapTy &StackElem = getTopOfStack(); |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 864 | StackElem.MappedClassesQualTypes.insert(QT); |
| 865 | } |
| 866 | |
| 867 | // Return set of mapped classes types |
| 868 | bool isClassPreviouslyMapped(QualType QT) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 869 | const SharingMapTy &StackElem = getTopOfStack(); |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 870 | return StackElem.MappedClassesQualTypes.count(QT) != 0; |
| 871 | } |
| 872 | |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 873 | /// Adds global declare target to the parent target region. |
| 874 | void addToParentTargetRegionLinkGlobals(DeclRefExpr *E) { |
| 875 | assert(*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( |
| 876 | E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && |
| 877 | "Expected declare target link global."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 878 | for (auto &Elem : *this) { |
| 879 | if (isOpenMPTargetExecutionDirective(Elem.Directive)) { |
| 880 | Elem.DeclareTargetLinkVarDecls.push_back(E); |
| 881 | return; |
| 882 | } |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
| 886 | /// Returns the list of globals with declare target link if current directive |
| 887 | /// is target. |
| 888 | ArrayRef<DeclRefExpr *> getLinkGlobals() const { |
| 889 | assert(isOpenMPTargetExecutionDirective(getCurrentDirective()) && |
| 890 | "Expected target executable directive."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 891 | return getTopOfStack().DeclareTargetLinkVarDecls; |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 892 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 893 | }; |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 894 | |
| 895 | bool isImplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
| 896 | return isOpenMPParallelDirective(DKind) || isOpenMPTeamsDirective(DKind); |
| 897 | } |
| 898 | |
| 899 | bool isImplicitOrExplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 900 | return isImplicitTaskingRegion(DKind) || isOpenMPTaskingDirective(DKind) || |
| 901 | DKind == OMPD_unknown; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 902 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 903 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 904 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 905 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 906 | static const Expr *getExprAsWritten(const Expr *E) { |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 907 | if (const auto *FE = dyn_cast<FullExpr>(E)) |
| 908 | E = FE->getSubExpr(); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 909 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 910 | if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 911 | E = MTE->getSubExpr(); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 912 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 913 | while (const auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 914 | E = Binder->getSubExpr(); |
| 915 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 916 | if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 917 | E = ICE->getSubExprAsWritten(); |
| 918 | return E->IgnoreParens(); |
| 919 | } |
| 920 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 921 | static Expr *getExprAsWritten(Expr *E) { |
| 922 | return const_cast<Expr *>(getExprAsWritten(const_cast<const Expr *>(E))); |
| 923 | } |
| 924 | |
| 925 | static const ValueDecl *getCanonicalDecl(const ValueDecl *D) { |
| 926 | if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) |
| 927 | if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 928 | D = ME->getMemberDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 929 | const auto *VD = dyn_cast<VarDecl>(D); |
| 930 | const auto *FD = dyn_cast<FieldDecl>(D); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 931 | if (VD != nullptr) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 932 | VD = VD->getCanonicalDecl(); |
| 933 | D = VD; |
| 934 | } else { |
| 935 | assert(FD); |
| 936 | FD = FD->getCanonicalDecl(); |
| 937 | D = FD; |
| 938 | } |
| 939 | return D; |
| 940 | } |
| 941 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 942 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 943 | return const_cast<ValueDecl *>( |
| 944 | getCanonicalDecl(const_cast<const ValueDecl *>(D))); |
| 945 | } |
| 946 | |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 947 | DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 948 | ValueDecl *D) const { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 949 | D = getCanonicalDecl(D); |
| 950 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 951 | const auto *FD = dyn_cast<FieldDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 952 | DSAVarData DVar; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 953 | if (Iter == end()) { |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 954 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 955 | // in a region but not in construct] |
| 956 | // File-scope or namespace-scope variables referenced in called routines |
| 957 | // in the region are shared unless they appear in a threadprivate |
| 958 | // directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 959 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(VD)) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 960 | DVar.CKind = OMPC_shared; |
| 961 | |
| 962 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 963 | // in a region but not in construct] |
| 964 | // Variables with static storage duration that are declared in called |
| 965 | // routines in the region are shared. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 966 | if (VD && VD->hasGlobalStorage()) |
| 967 | DVar.CKind = OMPC_shared; |
| 968 | |
| 969 | // Non-static data members are shared by default. |
| 970 | if (FD) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 971 | DVar.CKind = OMPC_shared; |
| 972 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 973 | return DVar; |
| 974 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 975 | |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 976 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 977 | // in a Construct, C/C++, predetermined, p.1] |
| 978 | // Variables with automatic storage duration that are declared in a scope |
| 979 | // inside the construct are private. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 980 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 981 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 982 | DVar.CKind = OMPC_private; |
| 983 | return DVar; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 986 | DVar.DKind = Iter->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 987 | // Explicitly specified attributes and local variables with predetermined |
| 988 | // attributes. |
| 989 | if (Iter->SharingMap.count(D)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 990 | const DSAInfo &Data = Iter->SharingMap.lookup(D); |
| 991 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 992 | DVar.PrivateCopy = Data.PrivateCopy; |
| 993 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 994 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 995 | return DVar; |
| 996 | } |
| 997 | |
| 998 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 999 | // in a Construct, C/C++, implicitly determined, p.1] |
| 1000 | // In a parallel or task construct, the data-sharing attributes of these |
| 1001 | // variables are determined by the default clause, if present. |
| 1002 | switch (Iter->DefaultAttr) { |
| 1003 | case DSA_shared: |
| 1004 | DVar.CKind = OMPC_shared; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1005 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1006 | return DVar; |
| 1007 | case DSA_none: |
| 1008 | return DVar; |
| 1009 | case DSA_unspecified: |
| 1010 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1011 | // in a Construct, implicitly determined, p.2] |
| 1012 | // In a parallel construct, if no default clause is present, these |
| 1013 | // variables are shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1014 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 1015 | if ((isOpenMPParallelDirective(DVar.DKind) && |
| 1016 | !isOpenMPTaskLoopDirective(DVar.DKind)) || |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1017 | isOpenMPTeamsDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1018 | DVar.CKind = OMPC_shared; |
| 1019 | return DVar; |
| 1020 | } |
| 1021 | |
| 1022 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1023 | // in a Construct, implicitly determined, p.4] |
| 1024 | // In a task construct, if no default clause is present, a variable that in |
| 1025 | // the enclosing context is determined to be shared by all implicit tasks |
| 1026 | // bound to the current team is shared. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1027 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1028 | DSAVarData DVarTemp; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1029 | const_iterator I = Iter, E = end(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1030 | do { |
| 1031 | ++I; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1032 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1033 | // Referenced in a Construct, implicitly determined, p.6] |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1034 | // In a task construct, if no default clause is present, a variable |
| 1035 | // whose data-sharing attribute is not determined by the rules above is |
| 1036 | // firstprivate. |
| 1037 | DVarTemp = getDSA(I, D); |
| 1038 | if (DVarTemp.CKind != OMPC_shared) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1039 | DVar.RefExpr = nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1040 | DVar.CKind = OMPC_firstprivate; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1041 | return DVar; |
| 1042 | } |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 1043 | } while (I != E && !isImplicitTaskingRegion(I->Directive)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1044 | DVar.CKind = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1045 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1046 | return DVar; |
| 1047 | } |
| 1048 | } |
| 1049 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1050 | // in a Construct, implicitly determined, p.3] |
| 1051 | // For constructs other than task, if no default clause is present, these |
| 1052 | // variables inherit their data-sharing attributes from the enclosing |
| 1053 | // context. |
| Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 1054 | return getDSA(++Iter, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1057 | const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D, |
| 1058 | const Expr *NewDE) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1059 | assert(!isStackEmpty() && "Data sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1060 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1061 | SharingMapTy &StackElem = getTopOfStack(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1062 | auto It = StackElem.AlignedMap.find(D); |
| 1063 | if (It == StackElem.AlignedMap.end()) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1064 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1065 | StackElem.AlignedMap[D] = NewDE; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1066 | return nullptr; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1067 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1068 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 1069 | return It->second; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1072 | void DSAStackTy::addLoopControlVariable(const ValueDecl *D, VarDecl *Capture) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1073 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1074 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1075 | SharingMapTy &StackElem = getTopOfStack(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1076 | StackElem.LCVMap.try_emplace( |
| 1077 | D, LCDeclInfo(StackElem.LCVMap.size() + 1, Capture)); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1080 | const DSAStackTy::LCDeclInfo |
| 1081 | DSAStackTy::isLoopControlVariable(const ValueDecl *D) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1082 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1083 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1084 | const SharingMapTy &StackElem = getTopOfStack(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1085 | auto It = StackElem.LCVMap.find(D); |
| 1086 | if (It != StackElem.LCVMap.end()) |
| 1087 | return It->second; |
| 1088 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1091 | const DSAStackTy::LCDeclInfo |
| 1092 | DSAStackTy::isParentLoopControlVariable(const ValueDecl *D) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1093 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
| 1094 | assert(Parent && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1095 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1096 | auto It = Parent->LCVMap.find(D); |
| 1097 | if (It != Parent->LCVMap.end()) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1098 | return It->second; |
| 1099 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1102 | const ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1103 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
| 1104 | assert(Parent && "Data-sharing attributes stack is empty"); |
| 1105 | if (Parent->LCVMap.size() < I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 1106 | return nullptr; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1107 | for (const auto &Pair : Parent->LCVMap) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1108 | if (Pair.second.first == I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 1109 | return Pair.first; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 1110 | return nullptr; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1113 | void DSAStackTy::addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1114 | DeclRefExpr *PrivateCopy) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1115 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1116 | if (A == OMPC_threadprivate) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1117 | DSAInfo &Data = Threadprivates[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1118 | Data.Attributes = A; |
| 1119 | Data.RefExpr.setPointer(E); |
| 1120 | Data.PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1121 | } else { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1122 | DSAInfo &Data = getTopOfStack().SharingMap[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1123 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 1124 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 1125 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 1126 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 1127 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 1128 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 1129 | return; |
| 1130 | } |
| 1131 | const bool IsLastprivate = |
| 1132 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 1133 | Data.Attributes = A; |
| 1134 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 1135 | Data.PrivateCopy = PrivateCopy; |
| 1136 | if (PrivateCopy) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1137 | DSAInfo &Data = getTopOfStack().SharingMap[PrivateCopy->getDecl()]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1138 | Data.Attributes = A; |
| 1139 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 1140 | Data.PrivateCopy = nullptr; |
| 1141 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1145 | /// Build a variable declaration for OpenMP loop iteration variable. |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1146 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1147 | StringRef Name, const AttrVec *Attrs = nullptr, |
| 1148 | DeclRefExpr *OrigRef = nullptr) { |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1149 | DeclContext *DC = SemaRef.CurContext; |
| 1150 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 1151 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1152 | auto *Decl = |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1153 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 1154 | if (Attrs) { |
| 1155 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 1156 | I != E; ++I) |
| 1157 | Decl->addAttr(*I); |
| 1158 | } |
| 1159 | Decl->setImplicit(); |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1160 | if (OrigRef) { |
| 1161 | Decl->addAttr( |
| 1162 | OMPReferencedVarAttr::CreateImplicit(SemaRef.Context, OrigRef)); |
| 1163 | } |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1164 | return Decl; |
| 1165 | } |
| 1166 | |
| 1167 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 1168 | SourceLocation Loc, |
| 1169 | bool RefersToCapture = false) { |
| 1170 | D->setReferenced(); |
| 1171 | D->markUsed(S.Context); |
| 1172 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 1173 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 1174 | VK_LValue); |
| 1175 | } |
| 1176 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1177 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1178 | BinaryOperatorKind BOK) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1179 | D = getCanonicalDecl(D); |
| 1180 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1181 | assert( |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1182 | getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1183 | "Additional reduction info may be specified only for reduction items."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1184 | ReductionData &ReductionData = getTopOfStack().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1185 | assert(ReductionData.ReductionRange.isInvalid() && |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1186 | getTopOfStack().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1187 | "Additional reduction info may be specified only once for reduction " |
| 1188 | "items."); |
| 1189 | ReductionData.set(BOK, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1190 | Expr *&TaskgroupReductionRef = |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1191 | getTopOfStack().TaskgroupReductionRef; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1192 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1193 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 1194 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 1195 | TaskgroupReductionRef = |
| 1196 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1197 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1200 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1201 | const Expr *ReductionRef) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1202 | D = getCanonicalDecl(D); |
| 1203 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1204 | assert( |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1205 | getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1206 | "Additional reduction info may be specified only for reduction items."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1207 | ReductionData &ReductionData = getTopOfStack().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1208 | assert(ReductionData.ReductionRange.isInvalid() && |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1209 | getTopOfStack().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1210 | "Additional reduction info may be specified only once for reduction " |
| 1211 | "items."); |
| 1212 | ReductionData.set(ReductionRef, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1213 | Expr *&TaskgroupReductionRef = |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1214 | getTopOfStack().TaskgroupReductionRef; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1215 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1216 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 1217 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 1218 | TaskgroupReductionRef = |
| 1219 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1220 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1223 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 1224 | const ValueDecl *D, SourceRange &SR, BinaryOperatorKind &BOK, |
| 1225 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1226 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1227 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1228 | for (const_iterator I = begin() + 1, E = end(); I != E; ++I) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1229 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1230 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1231 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1232 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1233 | if (!ReductionData.ReductionOp || |
| 1234 | ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1235 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1236 | SR = ReductionData.ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 1237 | BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1238 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 1239 | "expression for the descriptor is not " |
| 1240 | "set."); |
| 1241 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1242 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 1243 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1244 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1245 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1248 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 1249 | const ValueDecl *D, SourceRange &SR, const Expr *&ReductionRef, |
| 1250 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1251 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1252 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1253 | for (const_iterator I = begin() + 1, E = end(); I != E; ++I) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1254 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1255 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1256 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1257 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1258 | if (!ReductionData.ReductionOp || |
| 1259 | !ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1260 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1261 | SR = ReductionData.ReductionRange; |
| 1262 | ReductionRef = ReductionData.ReductionOp.get<const Expr *>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1263 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 1264 | "expression for the descriptor is not " |
| 1265 | "set."); |
| 1266 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1267 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 1268 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1269 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1270 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1273 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, const_iterator I) const { |
| Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1274 | D = D->getCanonicalDecl(); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1275 | for (const_iterator E = end(); I != E; ++I) { |
| 1276 | if (isImplicitOrExplicitTaskingRegion(I->Directive) || |
| 1277 | isOpenMPTargetExecutionDirective(I->Directive)) { |
| 1278 | Scope *TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
| 1279 | Scope *CurScope = getCurScope(); |
| 1280 | while (CurScope && CurScope != TopScope && !CurScope->isDeclScope(D)) |
| 1281 | CurScope = CurScope->getParent(); |
| 1282 | return CurScope != TopScope; |
| 1283 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1284 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1285 | return false; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1288 | static bool isConstNotMutableType(Sema &SemaRef, QualType Type, |
| 1289 | bool AcceptIfMutable = true, |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1290 | bool *IsClassType = nullptr) { |
| 1291 | ASTContext &Context = SemaRef.getASTContext(); |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1292 | Type = Type.getNonReferenceType().getCanonicalType(); |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1293 | bool IsConstant = Type.isConstant(Context); |
| 1294 | Type = Context.getBaseElementType(Type); |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1295 | const CXXRecordDecl *RD = AcceptIfMutable && SemaRef.getLangOpts().CPlusPlus |
| 1296 | ? Type->getAsCXXRecordDecl() |
| 1297 | : nullptr; |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1298 | if (const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 1299 | if (const ClassTemplateDecl *CTD = CTSD->getSpecializedTemplate()) |
| 1300 | RD = CTD->getTemplatedDecl(); |
| 1301 | if (IsClassType) |
| 1302 | *IsClassType = RD; |
| 1303 | return IsConstant && !(SemaRef.getLangOpts().CPlusPlus && RD && |
| 1304 | RD->hasDefinition() && RD->hasMutableFields()); |
| 1305 | } |
| 1306 | |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1307 | static bool rejectConstNotMutableType(Sema &SemaRef, const ValueDecl *D, |
| 1308 | QualType Type, OpenMPClauseKind CKind, |
| 1309 | SourceLocation ELoc, |
| 1310 | bool AcceptIfMutable = true, |
| 1311 | bool ListItemNotVar = false) { |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1312 | ASTContext &Context = SemaRef.getASTContext(); |
| 1313 | bool IsClassType; |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1314 | if (isConstNotMutableType(SemaRef, Type, AcceptIfMutable, &IsClassType)) { |
| 1315 | unsigned Diag = ListItemNotVar |
| 1316 | ? diag::err_omp_const_list_item |
| 1317 | : IsClassType ? diag::err_omp_const_not_mutable_variable |
| 1318 | : diag::err_omp_const_variable; |
| 1319 | SemaRef.Diag(ELoc, Diag) << getOpenMPClauseName(CKind); |
| 1320 | if (!ListItemNotVar && D) { |
| 1321 | const VarDecl *VD = dyn_cast<VarDecl>(D); |
| 1322 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 1323 | VarDecl::DeclarationOnly; |
| 1324 | SemaRef.Diag(D->getLocation(), |
| 1325 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1326 | << D; |
| 1327 | } |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1328 | return true; |
| 1329 | } |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1333 | const DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, |
| 1334 | bool FromParent) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1335 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1336 | DSAVarData DVar; |
| 1337 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1338 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1339 | auto TI = Threadprivates.find(D); |
| 1340 | if (TI != Threadprivates.end()) { |
| 1341 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1342 | DVar.CKind = OMPC_threadprivate; |
| 1343 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1344 | } |
| 1345 | if (VD && VD->hasAttr<OMPThreadPrivateDeclAttr>()) { |
| Alexey Bataev | 817d7f3 | 2017-11-14 21:01:01 +0000 | [diff] [blame] | 1346 | DVar.RefExpr = buildDeclRefExpr( |
| 1347 | SemaRef, VD, D->getType().getNonReferenceType(), |
| 1348 | VD->getAttr<OMPThreadPrivateDeclAttr>()->getLocation()); |
| 1349 | DVar.CKind = OMPC_threadprivate; |
| 1350 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1351 | return DVar; |
| 1352 | } |
| 1353 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1354 | // in a Construct, C/C++, predetermined, p.1] |
| 1355 | // Variables appearing in threadprivate directives are threadprivate. |
| 1356 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 1357 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1358 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 1359 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
| 1360 | (VD && VD->getStorageClass() == SC_Register && |
| 1361 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 1362 | DVar.RefExpr = buildDeclRefExpr( |
| 1363 | SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation()); |
| 1364 | DVar.CKind = OMPC_threadprivate; |
| 1365 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| 1366 | return DVar; |
| 1367 | } |
| 1368 | if (SemaRef.getLangOpts().OpenMPCUDAMode && VD && |
| 1369 | VD->isLocalVarDeclOrParm() && !isStackEmpty() && |
| 1370 | !isLoopControlVariable(D).first) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1371 | const_iterator IterTarget = |
| 1372 | std::find_if(begin(), end(), [](const SharingMapTy &Data) { |
| 1373 | return isOpenMPTargetExecutionDirective(Data.Directive); |
| 1374 | }); |
| 1375 | if (IterTarget != end()) { |
| 1376 | const_iterator ParentIterTarget = IterTarget + 1; |
| 1377 | for (const_iterator Iter = begin(); |
| 1378 | Iter != ParentIterTarget; ++Iter) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1379 | if (isOpenMPLocal(VD, Iter)) { |
| 1380 | DVar.RefExpr = |
| 1381 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1382 | D->getLocation()); |
| 1383 | DVar.CKind = OMPC_threadprivate; |
| 1384 | return DVar; |
| 1385 | } |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1386 | } |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1387 | if (!isClauseParsingMode() || IterTarget != begin()) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1388 | auto DSAIter = IterTarget->SharingMap.find(D); |
| 1389 | if (DSAIter != IterTarget->SharingMap.end() && |
| 1390 | isOpenMPPrivate(DSAIter->getSecond().Attributes)) { |
| 1391 | DVar.RefExpr = DSAIter->getSecond().RefExpr.getPointer(); |
| 1392 | DVar.CKind = OMPC_threadprivate; |
| 1393 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1394 | } |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1395 | const_iterator End = end(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1396 | if (!SemaRef.isOpenMPCapturedByRef( |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 1397 | D, std::distance(ParentIterTarget, End), |
| 1398 | /*OpenMPCaptureLevel=*/0)) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1399 | DVar.RefExpr = |
| 1400 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1401 | IterTarget->ConstructLoc); |
| 1402 | DVar.CKind = OMPC_threadprivate; |
| 1403 | return DVar; |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1409 | if (isStackEmpty()) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1410 | // Not in OpenMP execution region and top scope was already checked. |
| 1411 | return DVar; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1412 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1413 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1414 | // in a Construct, C/C++, predetermined, p.4] |
| 1415 | // Static data members are shared. |
| 1416 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1417 | // in a Construct, C/C++, predetermined, p.7] |
| 1418 | // Variables with static storage duration that are declared in a scope |
| 1419 | // inside the construct are shared. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1420 | if (VD && VD->isStaticDataMember()) { |
| Alexey Bataev | 73f9d9aa | 2019-06-28 16:16:00 +0000 | [diff] [blame] | 1421 | // Check for explicitly specified attributes. |
| 1422 | const_iterator I = begin(); |
| 1423 | const_iterator EndI = end(); |
| 1424 | if (FromParent && I != EndI) |
| 1425 | ++I; |
| 1426 | auto It = I->SharingMap.find(D); |
| 1427 | if (It != I->SharingMap.end()) { |
| 1428 | const DSAInfo &Data = It->getSecond(); |
| 1429 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 1430 | DVar.PrivateCopy = Data.PrivateCopy; |
| 1431 | DVar.CKind = Data.Attributes; |
| 1432 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
| 1433 | DVar.DKind = I->Directive; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1434 | return DVar; |
| Alexey Bataev | 73f9d9aa | 2019-06-28 16:16:00 +0000 | [diff] [blame] | 1435 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1436 | |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1437 | DVar.CKind = OMPC_shared; |
| 1438 | return DVar; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| Alexey Bataev | 73f9d9aa | 2019-06-28 16:16:00 +0000 | [diff] [blame] | 1441 | auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; }; |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1442 | // The predetermined shared attribute for const-qualified types having no |
| 1443 | // mutable members was removed after OpenMP 3.1. |
| 1444 | if (SemaRef.LangOpts.OpenMP <= 31) { |
| 1445 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1446 | // in a Construct, C/C++, predetermined, p.6] |
| 1447 | // Variables with const qualified type having no mutable member are |
| 1448 | // shared. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1449 | if (isConstNotMutableType(SemaRef, D->getType())) { |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1450 | // Variables with const-qualified type having no mutable member may be |
| 1451 | // listed in a firstprivate clause, even if they are static data members. |
| 1452 | DSAVarData DVarTemp = hasInnermostDSA( |
| 1453 | D, |
| 1454 | [](OpenMPClauseKind C) { |
| 1455 | return C == OMPC_firstprivate || C == OMPC_shared; |
| 1456 | }, |
| 1457 | MatchesAlways, FromParent); |
| 1458 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 1459 | return DVarTemp; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1460 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1461 | DVar.CKind = OMPC_shared; |
| 1462 | return DVar; |
| 1463 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1466 | // Explicitly specified attributes and local variables with predetermined |
| 1467 | // attributes. |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1468 | const_iterator I = begin(); |
| 1469 | const_iterator EndI = end(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1470 | if (FromParent && I != EndI) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1471 | ++I; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1472 | auto It = I->SharingMap.find(D); |
| 1473 | if (It != I->SharingMap.end()) { |
| 1474 | const DSAInfo &Data = It->getSecond(); |
| 1475 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 1476 | DVar.PrivateCopy = Data.PrivateCopy; |
| 1477 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1478 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 1479 | DVar.DKind = I->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | return DVar; |
| 1483 | } |
| 1484 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1485 | const DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 1486 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1487 | if (isStackEmpty()) { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1488 | const_iterator I; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1489 | return getDSA(I, D); |
| 1490 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1491 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1492 | const_iterator StartI = begin(); |
| 1493 | const_iterator EndI = end(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1494 | if (FromParent && StartI != EndI) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1495 | ++StartI; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1496 | return getDSA(StartI, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1499 | const DSAStackTy::DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1500 | DSAStackTy::hasDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1501 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1502 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1503 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1504 | if (isStackEmpty()) |
| 1505 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1506 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1507 | const_iterator I = begin(); |
| 1508 | const_iterator EndI = end(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1509 | if (FromParent && I != EndI) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1510 | ++I; |
| 1511 | for (; I != EndI; ++I) { |
| 1512 | if (!DPred(I->Directive) && |
| 1513 | !isImplicitOrExplicitTaskingRegion(I->Directive)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1514 | continue; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1515 | const_iterator NewI = I; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1516 | DSAVarData DVar = getDSA(NewI, D); |
| 1517 | if (I == NewI && CPred(DVar.CKind)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1518 | return DVar; |
| Alexey Bataev | 60859c0 | 2017-04-27 15:10:33 +0000 | [diff] [blame] | 1519 | } |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1520 | return {}; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1523 | const DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1524 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1525 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1526 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1527 | if (isStackEmpty()) |
| 1528 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1529 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1530 | const_iterator StartI = begin(); |
| 1531 | const_iterator EndI = end(); |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1532 | if (FromParent && StartI != EndI) |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1533 | ++StartI; |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1534 | if (StartI == EndI || !DPred(StartI->Directive)) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1535 | return {}; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1536 | const_iterator NewI = StartI; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1537 | DSAVarData DVar = getDSA(NewI, D); |
| 1538 | return (NewI == StartI && CPred(DVar.CKind)) ? DVar : DSAVarData(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1541 | bool DSAStackTy::hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1542 | const ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1543 | unsigned Level, bool NotLastprivate) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1544 | if (getStackSize() <= Level) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1545 | return false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1546 | D = getCanonicalDecl(D); |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1547 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
| 1548 | auto I = StackElem.SharingMap.find(D); |
| 1549 | if (I != StackElem.SharingMap.end() && |
| 1550 | I->getSecond().RefExpr.getPointer() && |
| 1551 | CPred(I->getSecond().Attributes) && |
| 1552 | (!NotLastprivate || !I->getSecond().RefExpr.getInt())) |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 1553 | return true; |
| 1554 | // Check predetermined rules for the loop control variables. |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1555 | auto LI = StackElem.LCVMap.find(D); |
| 1556 | if (LI != StackElem.LCVMap.end()) |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 1557 | return CPred(OMPC_private); |
| 1558 | return false; |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1561 | bool DSAStackTy::hasExplicitDirective( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1562 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 1563 | unsigned Level) const { |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1564 | if (getStackSize() <= Level) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1565 | return false; |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1566 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
| 1567 | return DPred(StackElem.Directive); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1570 | bool DSAStackTy::hasDirective( |
| 1571 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 1572 | const DeclarationNameInfo &, SourceLocation)> |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1573 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1574 | bool FromParent) const { |
| Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1575 | // We look only in the enclosing region. |
| Richard Smith | 375dec5 | 2019-05-30 23:21:14 +0000 | [diff] [blame] | 1576 | size_t Skip = FromParent ? 2 : 1; |
| 1577 | for (const_iterator I = begin() + std::min(Skip, getStackSize()), E = end(); |
| 1578 | I != E; ++I) { |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1579 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 1580 | return true; |
| 1581 | } |
| 1582 | return false; |
| 1583 | } |
| 1584 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1585 | void Sema::InitDataSharingAttributesStack() { |
| 1586 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 1587 | } |
| 1588 | |
| 1589 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 1590 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1591 | void Sema::pushOpenMPFunctionRegion() { |
| 1592 | DSAStack->pushFunction(); |
| 1593 | } |
| 1594 | |
| 1595 | void Sema::popOpenMPFunctionRegion(const FunctionScopeInfo *OldFSI) { |
| 1596 | DSAStack->popFunction(OldFSI); |
| 1597 | } |
| 1598 | |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1599 | static bool isOpenMPDeviceDelayedContext(Sema &S) { |
| 1600 | assert(S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && |
| 1601 | "Expected OpenMP device compilation."); |
| 1602 | return !S.isInOpenMPTargetExecutionDirective() && |
| 1603 | !S.isInOpenMPDeclareTargetContext(); |
| 1604 | } |
| 1605 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1606 | namespace { |
| 1607 | /// Status of the function emission on the host/device. |
| 1608 | enum class FunctionEmissionStatus { |
| 1609 | Emitted, |
| 1610 | Discarded, |
| 1611 | Unknown, |
| 1612 | }; |
| 1613 | } // anonymous namespace |
| 1614 | |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1615 | Sema::DeviceDiagBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc, |
| 1616 | unsigned DiagID) { |
| 1617 | assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice && |
| 1618 | "Expected OpenMP device compilation."); |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1619 | FunctionEmissionStatus FES = getEmissionStatus(getCurFunctionDecl()); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1620 | DeviceDiagBuilder::Kind Kind = DeviceDiagBuilder::K_Nop; |
| 1621 | switch (FES) { |
| 1622 | case FunctionEmissionStatus::Emitted: |
| 1623 | Kind = DeviceDiagBuilder::K_Immediate; |
| 1624 | break; |
| 1625 | case FunctionEmissionStatus::Unknown: |
| 1626 | Kind = isOpenMPDeviceDelayedContext(*this) ? DeviceDiagBuilder::K_Deferred |
| 1627 | : DeviceDiagBuilder::K_Immediate; |
| 1628 | break; |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1629 | case FunctionEmissionStatus::TemplateDiscarded: |
| 1630 | case FunctionEmissionStatus::OMPDiscarded: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1631 | Kind = DeviceDiagBuilder::K_Nop; |
| 1632 | break; |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1633 | case FunctionEmissionStatus::CUDADiscarded: |
| 1634 | llvm_unreachable("CUDADiscarded unexpected in OpenMP device compilation"); |
| 1635 | break; |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this); |
| 1639 | } |
| 1640 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1641 | Sema::DeviceDiagBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc, |
| 1642 | unsigned DiagID) { |
| 1643 | assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && |
| 1644 | "Expected OpenMP host compilation."); |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1645 | FunctionEmissionStatus FES = getEmissionStatus(getCurFunctionDecl()); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1646 | DeviceDiagBuilder::Kind Kind = DeviceDiagBuilder::K_Nop; |
| 1647 | switch (FES) { |
| 1648 | case FunctionEmissionStatus::Emitted: |
| 1649 | Kind = DeviceDiagBuilder::K_Immediate; |
| 1650 | break; |
| 1651 | case FunctionEmissionStatus::Unknown: |
| 1652 | Kind = DeviceDiagBuilder::K_Deferred; |
| 1653 | break; |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1654 | case FunctionEmissionStatus::TemplateDiscarded: |
| 1655 | case FunctionEmissionStatus::OMPDiscarded: |
| 1656 | case FunctionEmissionStatus::CUDADiscarded: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1657 | Kind = DeviceDiagBuilder::K_Nop; |
| 1658 | break; |
| 1659 | } |
| 1660 | |
| 1661 | return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this); |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 1664 | void Sema::checkOpenMPDeviceFunction(SourceLocation Loc, FunctionDecl *Callee, |
| 1665 | bool CheckForDelayedContext) { |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1666 | assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice && |
| 1667 | "Expected OpenMP device compilation."); |
| 1668 | assert(Callee && "Callee may not be null."); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1669 | Callee = Callee->getMostRecentDecl(); |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1670 | FunctionDecl *Caller = getCurFunctionDecl(); |
| 1671 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1672 | // host only function are not available on the device. |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1673 | if (Caller) { |
| 1674 | FunctionEmissionStatus CallerS = getEmissionStatus(Caller); |
| 1675 | FunctionEmissionStatus CalleeS = getEmissionStatus(Callee); |
| 1676 | assert(CallerS != FunctionEmissionStatus::CUDADiscarded && |
| 1677 | CalleeS != FunctionEmissionStatus::CUDADiscarded && |
| 1678 | "CUDADiscarded unexpected in OpenMP device function check"); |
| 1679 | if ((CallerS == FunctionEmissionStatus::Emitted || |
| 1680 | (!isOpenMPDeviceDelayedContext(*this) && |
| 1681 | CallerS == FunctionEmissionStatus::Unknown)) && |
| 1682 | CalleeS == FunctionEmissionStatus::OMPDiscarded) { |
| 1683 | StringRef HostDevTy = getOpenMPSimpleClauseTypeName( |
| 1684 | OMPC_device_type, OMPC_DEVICE_TYPE_host); |
| 1685 | Diag(Loc, diag::err_omp_wrong_device_function_call) << HostDevTy << 0; |
| 1686 | Diag(Callee->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(), |
| 1687 | diag::note_omp_marked_device_type_here) |
| 1688 | << HostDevTy; |
| 1689 | return; |
| 1690 | } |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1691 | } |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1692 | // If the caller is known-emitted, mark the callee as known-emitted. |
| 1693 | // Otherwise, mark the call in our call graph so we can traverse it later. |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 1694 | if ((CheckForDelayedContext && !isOpenMPDeviceDelayedContext(*this)) || |
| 1695 | (!Caller && !CheckForDelayedContext) || |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1696 | (Caller && getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted)) |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 1697 | markKnownEmitted(*this, Caller, Callee, Loc, |
| 1698 | [CheckForDelayedContext](Sema &S, FunctionDecl *FD) { |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1699 | return CheckForDelayedContext && |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1700 | S.getEmissionStatus(FD) == |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1701 | FunctionEmissionStatus::Emitted; |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 1702 | }); |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1703 | else if (Caller) |
| 1704 | DeviceCallGraph[Caller].insert({Callee, Loc}); |
| 1705 | } |
| 1706 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1707 | void Sema::checkOpenMPHostFunction(SourceLocation Loc, FunctionDecl *Callee, |
| 1708 | bool CheckCaller) { |
| 1709 | assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && |
| 1710 | "Expected OpenMP host compilation."); |
| 1711 | assert(Callee && "Callee may not be null."); |
| 1712 | Callee = Callee->getMostRecentDecl(); |
| 1713 | FunctionDecl *Caller = getCurFunctionDecl(); |
| 1714 | |
| 1715 | // device only function are not available on the host. |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1716 | if (Caller) { |
| 1717 | FunctionEmissionStatus CallerS = getEmissionStatus(Caller); |
| 1718 | FunctionEmissionStatus CalleeS = getEmissionStatus(Callee); |
| 1719 | assert( |
| 1720 | (LangOpts.CUDA || (CallerS != FunctionEmissionStatus::CUDADiscarded && |
| 1721 | CalleeS != FunctionEmissionStatus::CUDADiscarded)) && |
| 1722 | "CUDADiscarded unexpected in OpenMP host function check"); |
| 1723 | if (CallerS == FunctionEmissionStatus::Emitted && |
| 1724 | CalleeS == FunctionEmissionStatus::OMPDiscarded) { |
| 1725 | StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName( |
| 1726 | OMPC_device_type, OMPC_DEVICE_TYPE_nohost); |
| 1727 | Diag(Loc, diag::err_omp_wrong_device_function_call) << NoHostDevTy << 1; |
| 1728 | Diag(Callee->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(), |
| 1729 | diag::note_omp_marked_device_type_here) |
| 1730 | << NoHostDevTy; |
| 1731 | return; |
| 1732 | } |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1733 | } |
| 1734 | // If the caller is known-emitted, mark the callee as known-emitted. |
| 1735 | // Otherwise, mark the call in our call graph so we can traverse it later. |
| Yaxun Liu | 229c78d | 2019-10-09 23:54:10 +0000 | [diff] [blame] | 1736 | if (!shouldIgnoreInHostDeviceCheck(Callee)) { |
| 1737 | if ((!CheckCaller && !Caller) || |
| 1738 | (Caller && |
| 1739 | getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted)) |
| 1740 | markKnownEmitted( |
| 1741 | *this, Caller, Callee, Loc, [CheckCaller](Sema &S, FunctionDecl *FD) { |
| 1742 | return CheckCaller && |
| 1743 | S.getEmissionStatus(FD) == FunctionEmissionStatus::Emitted; |
| 1744 | }); |
| 1745 | else if (Caller) |
| 1746 | DeviceCallGraph[Caller].insert({Callee, Loc}); |
| 1747 | } |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
| Alexey Bataev | 123ad19 | 2019-02-27 20:29:45 +0000 | [diff] [blame] | 1750 | void Sema::checkOpenMPDeviceExpr(const Expr *E) { |
| 1751 | assert(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice && |
| 1752 | "OpenMP device compilation mode is expected."); |
| 1753 | QualType Ty = E->getType(); |
| 1754 | if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) || |
| Alexey Bataev | 8557d1a | 2019-06-18 18:39:26 +0000 | [diff] [blame] | 1755 | ((Ty->isFloat128Type() || |
| 1756 | (Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) && |
| 1757 | !Context.getTargetInfo().hasFloat128Type()) || |
| Alexey Bataev | 123ad19 | 2019-02-27 20:29:45 +0000 | [diff] [blame] | 1758 | (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 && |
| 1759 | !Context.getTargetInfo().hasInt128Type())) |
| Alexey Bataev | 6289259 | 2019-07-08 19:21:54 +0000 | [diff] [blame] | 1760 | targetDiag(E->getExprLoc(), diag::err_omp_unsupported_type) |
| 1761 | << static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty |
| 1762 | << Context.getTargetInfo().getTriple().str() << E->getSourceRange(); |
| Alexey Bataev | 123ad19 | 2019-02-27 20:29:45 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 1765 | static OpenMPDefaultmapClauseKind |
| Alexey Bataev | 6f7c876 | 2019-11-22 11:09:33 -0500 | [diff] [blame] | 1766 | getVariableCategoryFromDecl(const LangOptions &LO, const ValueDecl *VD) { |
| 1767 | if (LO.OpenMP <= 45) { |
| 1768 | if (VD->getType().getNonReferenceType()->isScalarType()) |
| 1769 | return OMPC_DEFAULTMAP_scalar; |
| 1770 | return OMPC_DEFAULTMAP_aggregate; |
| 1771 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 1772 | if (VD->getType().getNonReferenceType()->isAnyPointerType()) |
| 1773 | return OMPC_DEFAULTMAP_pointer; |
| 1774 | if (VD->getType().getNonReferenceType()->isScalarType()) |
| 1775 | return OMPC_DEFAULTMAP_scalar; |
| 1776 | return OMPC_DEFAULTMAP_aggregate; |
| 1777 | } |
| 1778 | |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 1779 | bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
| 1780 | unsigned OpenMPCaptureLevel) const { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1781 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1782 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1783 | ASTContext &Ctx = getASTContext(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1784 | bool IsByRef = true; |
| 1785 | |
| 1786 | // Find the directive that is associated with the provided scope. |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 1787 | D = cast<ValueDecl>(D->getCanonicalDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1788 | QualType Ty = D->getType(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1789 | |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 1790 | bool IsVariableUsedInMapClause = false; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1791 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1792 | // This table summarizes how a given variable should be passed to the device |
| 1793 | // given its type and the clauses where it appears. This table is based on |
| 1794 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 1795 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 1796 | // |
| 1797 | // ========================================================================= |
| 1798 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 1799 | // | |(tofrom:scalar)| | pvt | | | | |
| 1800 | // ========================================================================= |
| 1801 | // | scl | | | | - | | bycopy| |
| 1802 | // | scl | | - | x | - | - | bycopy| |
| 1803 | // | scl | | x | - | - | - | null | |
| 1804 | // | scl | x | | | - | | byref | |
| 1805 | // | scl | x | - | x | - | - | bycopy| |
| 1806 | // | scl | x | x | - | - | - | null | |
| 1807 | // | scl | | - | - | - | x | byref | |
| 1808 | // | scl | x | - | - | - | x | byref | |
| 1809 | // |
| 1810 | // | agg | n.a. | | | - | | byref | |
| 1811 | // | agg | n.a. | - | x | - | - | byref | |
| 1812 | // | agg | n.a. | x | - | - | - | null | |
| 1813 | // | agg | n.a. | - | - | - | x | byref | |
| 1814 | // | agg | n.a. | - | - | - | x[] | byref | |
| 1815 | // |
| 1816 | // | ptr | n.a. | | | - | | bycopy| |
| 1817 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 1818 | // | ptr | n.a. | x | - | - | - | null | |
| 1819 | // | ptr | n.a. | - | - | - | x | byref | |
| 1820 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 1821 | // | ptr | n.a. | - | - | x | | bycopy| |
| 1822 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 1823 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 1824 | // ========================================================================= |
| 1825 | // Legend: |
| 1826 | // scl - scalar |
| 1827 | // ptr - pointer |
| 1828 | // agg - aggregate |
| 1829 | // x - applies |
| 1830 | // - - invalid in this combination |
| 1831 | // [] - mapped with an array section |
| 1832 | // byref - should be mapped by reference |
| 1833 | // byval - should be mapped by value |
| 1834 | // null - initialize a local variable to null on the device |
| 1835 | // |
| 1836 | // Observations: |
| 1837 | // - All scalar declarations that show up in a map clause have to be passed |
| 1838 | // by reference, because they may have been mapped in the enclosing data |
| 1839 | // environment. |
| 1840 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 1841 | // passed by reference, regardless the result in the table above. |
| 1842 | // - For pointers mapped by value that have either an implicit map or an |
| 1843 | // array section, the runtime library may pass the NULL value to the |
| 1844 | // device instead of the value passed to it by the compiler. |
| 1845 | |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1846 | if (Ty->isReferenceType()) |
| 1847 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1848 | |
| 1849 | // Locate map clauses and see if the variable being captured is referred to |
| 1850 | // in any of those clauses. Here we only care about variables, not fields, |
| 1851 | // because fields are part of aggregates. |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1852 | bool IsVariableAssociatedWithSection = false; |
| 1853 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 1854 | DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1855 | D, Level, |
| 1856 | [&IsVariableUsedInMapClause, &IsVariableAssociatedWithSection, D]( |
| 1857 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1858 | MapExprComponents, |
| 1859 | OpenMPClauseKind WhereFoundClauseKind) { |
| 1860 | // Only the map clause information influences how a variable is |
| 1861 | // captured. E.g. is_device_ptr does not require changing the default |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 1862 | // behavior. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1863 | if (WhereFoundClauseKind != OMPC_map) |
| 1864 | return false; |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1865 | |
| 1866 | auto EI = MapExprComponents.rbegin(); |
| 1867 | auto EE = MapExprComponents.rend(); |
| 1868 | |
| 1869 | assert(EI != EE && "Invalid map expression!"); |
| 1870 | |
| 1871 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 1872 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 1873 | |
| 1874 | ++EI; |
| 1875 | if (EI == EE) |
| 1876 | return false; |
| 1877 | |
| 1878 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 1879 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 1880 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 1881 | IsVariableAssociatedWithSection = true; |
| 1882 | // There is nothing more we need to know about this variable. |
| 1883 | return true; |
| 1884 | } |
| 1885 | |
| 1886 | // Keep looking for more map info. |
| 1887 | return false; |
| 1888 | }); |
| 1889 | |
| 1890 | if (IsVariableUsedInMapClause) { |
| 1891 | // If variable is identified in a map clause it is always captured by |
| 1892 | // reference except if it is a pointer that is dereferenced somehow. |
| 1893 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 1894 | } else { |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1895 | // By default, all the data that has a scalar type is mapped by copy |
| 1896 | // (except for reduction variables). |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 1897 | // Defaultmap scalar is mutual exclusive to defaultmap pointer |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1898 | IsByRef = |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1899 | (DSAStack->isForceCaptureByReferenceInTargetExecutable() && |
| 1900 | !Ty->isAnyPointerType()) || |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1901 | !Ty->isScalarType() || |
| Alexey Bataev | 6f7c876 | 2019-11-22 11:09:33 -0500 | [diff] [blame] | 1902 | DSAStack->isDefaultmapCapturedByRef( |
| 1903 | Level, getVariableCategoryFromDecl(LangOpts, D)) || |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1904 | DSAStack->hasExplicitDSA( |
| 1905 | D, [](OpenMPClauseKind K) { return K == OMPC_reduction; }, Level); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1906 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1909 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 1910 | IsByRef = |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 1911 | ((IsVariableUsedInMapClause && |
| 1912 | DSAStack->getCaptureRegion(Level, OpenMPCaptureLevel) == |
| 1913 | OMPD_target) || |
| 1914 | !DSAStack->hasExplicitDSA( |
| 1915 | D, |
| 1916 | [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 1917 | Level, /*NotLastprivate=*/true)) && |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 1918 | // If the variable is artificial and must be captured by value - try to |
| 1919 | // capture by value. |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 1920 | !(isa<OMPCapturedExprDecl>(D) && !D->hasAttr<OMPCaptureNoInitAttr>() && |
| 1921 | !cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1924 | // When passing data by copy, we need to make sure it fits the uintptr size |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1925 | // and alignment, because the runtime library only deals with uintptr types. |
| 1926 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 1927 | // instead. |
| 1928 | if (!IsByRef && |
| 1929 | (Ctx.getTypeSizeInChars(Ty) > |
| 1930 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1931 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1932 | IsByRef = true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1933 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1934 | |
| 1935 | return IsByRef; |
| 1936 | } |
| 1937 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1938 | unsigned Sema::getOpenMPNestingLevel() const { |
| 1939 | assert(getLangOpts().OpenMP); |
| 1940 | return DSAStack->getNestingLevel(); |
| 1941 | } |
| 1942 | |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 1943 | bool Sema::isInOpenMPTargetExecutionDirective() const { |
| 1944 | return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) && |
| 1945 | !DSAStack->isClauseParsingMode()) || |
| 1946 | DSAStack->hasDirective( |
| 1947 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1948 | SourceLocation) -> bool { |
| 1949 | return isOpenMPTargetExecutionDirective(K); |
| 1950 | }, |
| 1951 | false); |
| 1952 | } |
| 1953 | |
| Alexey Bataev | 41ebe0c | 2019-05-09 18:14:57 +0000 | [diff] [blame] | 1954 | VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo, |
| 1955 | unsigned StopAt) { |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1956 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1957 | D = getCanonicalDecl(D); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1958 | |
| Alexey Bataev | 7c86069 | 2019-10-25 16:35:32 -0400 | [diff] [blame] | 1959 | auto *VD = dyn_cast<VarDecl>(D); |
| 1960 | // Do not capture constexpr variables. |
| 1961 | if (VD && VD->isConstexpr()) |
| 1962 | return nullptr; |
| 1963 | |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 1964 | // If we want to determine whether the variable should be captured from the |
| 1965 | // perspective of the current capturing scope, and we've already left all the |
| 1966 | // capturing scopes of the top directive on the stack, check from the |
| 1967 | // perspective of its parent directive (if any) instead. |
| 1968 | DSAStackTy::ParentDirectiveScope InParentDirectiveRAII( |
| 1969 | *DSAStack, CheckScopeInfo && DSAStack->isBodyComplete()); |
| 1970 | |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1971 | // If we are attempting to capture a global variable in a directive with |
| 1972 | // 'target' we return true so that this global is also mapped to the device. |
| 1973 | // |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 1974 | if (VD && !VD->hasLocalStorage() && |
| 1975 | (getCurCapturedRegion() || getCurBlock() || getCurLambda())) { |
| 1976 | if (isInOpenMPDeclareTargetContext()) { |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1977 | // Try to mark variable as declare target if it is used in capturing |
| 1978 | // regions. |
| Alexey Bataev | 217ff1e | 2019-08-16 20:15:02 +0000 | [diff] [blame] | 1979 | if (LangOpts.OpenMP <= 45 && |
| 1980 | !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1981 | checkDeclIsAllowedInOpenMPTarget(nullptr, VD); |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1982 | return nullptr; |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1983 | } else if (isInOpenMPTargetExecutionDirective()) { |
| 1984 | // If the declaration is enclosed in a 'declare target' directive, |
| 1985 | // then it should not be captured. |
| 1986 | // |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1987 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1988 | return nullptr; |
| 1989 | return VD; |
| 1990 | } |
| Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1991 | } |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1992 | |
| Alexey Bataev | 41ebe0c | 2019-05-09 18:14:57 +0000 | [diff] [blame] | 1993 | if (CheckScopeInfo) { |
| 1994 | bool OpenMPFound = false; |
| 1995 | for (unsigned I = StopAt + 1; I > 0; --I) { |
| 1996 | FunctionScopeInfo *FSI = FunctionScopes[I - 1]; |
| 1997 | if(!isa<CapturingScopeInfo>(FSI)) |
| 1998 | return nullptr; |
| 1999 | if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(FSI)) |
| 2000 | if (RSI->CapRegionKind == CR_OpenMP) { |
| 2001 | OpenMPFound = true; |
| 2002 | break; |
| 2003 | } |
| 2004 | } |
| 2005 | if (!OpenMPFound) |
| 2006 | return nullptr; |
| 2007 | } |
| 2008 | |
| Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 2009 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 2010 | (!DSAStack->isClauseParsingMode() || |
| 2011 | DSAStack->getParentDirective() != OMPD_unknown)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2012 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 2013 | if (Info.first || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2014 | (VD && VD->hasLocalStorage() && |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 2015 | isImplicitOrExplicitTaskingRegion(DSAStack->getCurrentDirective())) || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2016 | (VD && DSAStack->isForceVarCapturing())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2017 | return VD ? VD : Info.second; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2018 | DSAStackTy::DSAVarData DVarPrivate = |
| 2019 | DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 2020 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2021 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | e0eb66b | 2019-06-21 15:08:30 +0000 | [diff] [blame] | 2022 | // Threadprivate variables must not be captured. |
| 2023 | if (isOpenMPThreadPrivate(DVarPrivate.CKind)) |
| 2024 | return nullptr; |
| 2025 | // The variable is not private or it is the variable in the directive with |
| 2026 | // default(none) clause and not used in any clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2027 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, |
| 2028 | [](OpenMPDirectiveKind) { return true; }, |
| 2029 | DSAStack->isClauseParsingMode()); |
| Alexey Bataev | 41ebe0c | 2019-05-09 18:14:57 +0000 | [diff] [blame] | 2030 | if (DVarPrivate.CKind != OMPC_unknown || |
| 2031 | (VD && DSAStack->getDefaultDSA() == DSA_none)) |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2032 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 2033 | } |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2034 | return nullptr; |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 2037 | void Sema::adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
| 2038 | unsigned Level) const { |
| 2039 | SmallVector<OpenMPDirectiveKind, 4> Regions; |
| 2040 | getOpenMPCaptureRegions(Regions, DSAStack->getDirective(Level)); |
| 2041 | FunctionScopesIndex -= Regions.size(); |
| 2042 | } |
| 2043 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 2044 | void Sema::startOpenMPLoop() { |
| 2045 | assert(LangOpts.OpenMP && "OpenMP must be enabled."); |
| 2046 | if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) |
| 2047 | DSAStack->loopInit(); |
| 2048 | } |
| 2049 | |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 2050 | void Sema::startOpenMPCXXRangeFor() { |
| 2051 | assert(LangOpts.OpenMP && "OpenMP must be enabled."); |
| 2052 | if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2053 | DSAStack->resetPossibleLoopCounter(); |
| 2054 | DSAStack->loopStart(); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2058 | bool Sema::isOpenMPPrivateDecl(const ValueDecl *D, unsigned Level) const { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 2059 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 2060 | if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2061 | if (DSAStack->getAssociatedLoops() > 0 && |
| 2062 | !DSAStack->isLoopStarted()) { |
| 2063 | DSAStack->resetPossibleLoopCounter(D); |
| 2064 | DSAStack->loopStart(); |
| 2065 | return true; |
| 2066 | } |
| 2067 | if ((DSAStack->getPossiblyLoopCunter() == D->getCanonicalDecl() || |
| 2068 | DSAStack->isLoopControlVariable(D).first) && |
| 2069 | !DSAStack->hasExplicitDSA( |
| 2070 | D, [](OpenMPClauseKind K) { return K != OMPC_private; }, Level) && |
| 2071 | !isOpenMPSimdDirective(DSAStack->getCurrentDirective())) |
| 2072 | return true; |
| 2073 | } |
| Alexey Bataev | 0c99d19 | 2019-07-18 19:40:24 +0000 | [diff] [blame] | 2074 | if (const auto *VD = dyn_cast<VarDecl>(D)) { |
| 2075 | if (DSAStack->isThreadPrivate(const_cast<VarDecl *>(VD)) && |
| 2076 | DSAStack->isForceVarCapturing() && |
| 2077 | !DSAStack->hasExplicitDSA( |
| 2078 | D, [](OpenMPClauseKind K) { return K == OMPC_copyin; }, Level)) |
| 2079 | return true; |
| 2080 | } |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 2081 | return DSAStack->hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2082 | D, [](OpenMPClauseKind K) { return K == OMPC_private; }, Level) || |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 2083 | (DSAStack->isClauseParsingMode() && |
| 2084 | DSAStack->getClauseParsingMode() == OMPC_private) || |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 2085 | // Consider taskgroup reduction descriptor variable a private to avoid |
| 2086 | // possible capture in the region. |
| 2087 | (DSAStack->hasExplicitDirective( |
| 2088 | [](OpenMPDirectiveKind K) { return K == OMPD_taskgroup; }, |
| 2089 | Level) && |
| 2090 | DSAStack->isTaskgroupReductionRef(D, Level)); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2093 | void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, |
| 2094 | unsigned Level) { |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 2095 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 2096 | D = getCanonicalDecl(D); |
| 2097 | OpenMPClauseKind OMPC = OMPC_unknown; |
| 2098 | for (unsigned I = DSAStack->getNestingLevel() + 1; I > Level; --I) { |
| 2099 | const unsigned NewLevel = I - 1; |
| 2100 | if (DSAStack->hasExplicitDSA(D, |
| 2101 | [&OMPC](const OpenMPClauseKind K) { |
| 2102 | if (isOpenMPPrivate(K)) { |
| 2103 | OMPC = K; |
| 2104 | return true; |
| 2105 | } |
| 2106 | return false; |
| 2107 | }, |
| 2108 | NewLevel)) |
| 2109 | break; |
| 2110 | if (DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| 2111 | D, NewLevel, |
| 2112 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 2113 | OpenMPClauseKind) { return true; })) { |
| 2114 | OMPC = OMPC_map; |
| 2115 | break; |
| 2116 | } |
| 2117 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 2118 | NewLevel)) { |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 2119 | OMPC = OMPC_map; |
| Alexey Bataev | 6f7c876 | 2019-11-22 11:09:33 -0500 | [diff] [blame] | 2120 | if (DSAStack->mustBeFirstprivateAtLevel( |
| 2121 | NewLevel, getVariableCategoryFromDecl(LangOpts, D))) |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 2122 | OMPC = OMPC_firstprivate; |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 2123 | break; |
| 2124 | } |
| 2125 | } |
| 2126 | if (OMPC != OMPC_unknown) |
| 2127 | FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, OMPC)); |
| 2128 | } |
| 2129 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2130 | bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, |
| 2131 | unsigned Level) const { |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 2132 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 2133 | // Return true if the current level is no longer enclosed in a target region. |
| 2134 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2135 | const auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2136 | return VD && !VD->hasLocalStorage() && |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2137 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 2138 | Level); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2141 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2142 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2143 | void Sema::finalizeOpenMPDelayedAnalysis() { |
| 2144 | assert(LangOpts.OpenMP && "Expected OpenMP compilation mode."); |
| 2145 | // Diagnose implicit declare target functions and their callees. |
| 2146 | for (const auto &CallerCallees : DeviceCallGraph) { |
| 2147 | Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy = |
| 2148 | OMPDeclareTargetDeclAttr::getDeviceType( |
| 2149 | CallerCallees.getFirst()->getMostRecentDecl()); |
| 2150 | // Ignore host functions during device analyzis. |
| 2151 | if (LangOpts.OpenMPIsDevice && DevTy && |
| 2152 | *DevTy == OMPDeclareTargetDeclAttr::DT_Host) |
| 2153 | continue; |
| 2154 | // Ignore nohost functions during host analyzis. |
| 2155 | if (!LangOpts.OpenMPIsDevice && DevTy && |
| 2156 | *DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) |
| 2157 | continue; |
| 2158 | for (const std::pair<CanonicalDeclPtr<FunctionDecl>, SourceLocation> |
| 2159 | &Callee : CallerCallees.getSecond()) { |
| 2160 | const FunctionDecl *FD = Callee.first->getMostRecentDecl(); |
| 2161 | Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy = |
| 2162 | OMPDeclareTargetDeclAttr::getDeviceType(FD); |
| 2163 | if (LangOpts.OpenMPIsDevice && DevTy && |
| 2164 | *DevTy == OMPDeclareTargetDeclAttr::DT_Host) { |
| 2165 | // Diagnose host function called during device codegen. |
| 2166 | StringRef HostDevTy = getOpenMPSimpleClauseTypeName( |
| 2167 | OMPC_device_type, OMPC_DEVICE_TYPE_host); |
| 2168 | Diag(Callee.second, diag::err_omp_wrong_device_function_call) |
| 2169 | << HostDevTy << 0; |
| 2170 | Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(), |
| 2171 | diag::note_omp_marked_device_type_here) |
| 2172 | << HostDevTy; |
| 2173 | continue; |
| 2174 | } |
| 2175 | if (!LangOpts.OpenMPIsDevice && DevTy && |
| 2176 | *DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) { |
| 2177 | // Diagnose nohost function called during host codegen. |
| 2178 | StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName( |
| 2179 | OMPC_device_type, OMPC_DEVICE_TYPE_nohost); |
| 2180 | Diag(Callee.second, diag::err_omp_wrong_device_function_call) |
| 2181 | << NoHostDevTy << 1; |
| 2182 | Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(), |
| 2183 | diag::note_omp_marked_device_type_here) |
| 2184 | << NoHostDevTy; |
| 2185 | continue; |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2191 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 2192 | const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2193 | Scope *CurScope, SourceLocation Loc) { |
| 2194 | DSAStack->push(DKind, DirName, CurScope, Loc); |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 2195 | PushExpressionEvaluationContext( |
| 2196 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 2199 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 2200 | DSAStack->setClauseParsingMode(K); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 2203 | void Sema::EndOpenMPClause() { |
| 2204 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2207 | static void checkAllocateClauses(Sema &S, DSAStackTy *Stack, |
| 2208 | ArrayRef<OMPClause *> Clauses); |
| 2209 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2210 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2211 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 2212 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 2213 | // clause requires an accessible, unambiguous default constructor for the |
| 2214 | // class type, unless the list item is also specified in a firstprivate |
| 2215 | // clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2216 | if (const auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
| 2217 | for (OMPClause *C : D->clauses()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2218 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 2219 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2220 | for (Expr *DE : Clause->varlists()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2221 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 2222 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2223 | continue; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2224 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 2225 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2226 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2227 | QualType Type = VD->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2228 | const DSAStackTy::DSAVarData DVar = |
| 2229 | DSAStack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2230 | if (DVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2231 | // Generate helper private variable and initialize it with the |
| 2232 | // default value. The address of the original variable is replaced |
| 2233 | // by the address of the new private variable in CodeGen. This new |
| 2234 | // variable is not added to IdResolver, so the code in the OpenMP |
| 2235 | // region uses original variable for proper diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2236 | VarDecl *VDPrivate = buildVarDecl( |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2237 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 2238 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr, DRE); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 2239 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2240 | if (VDPrivate->isInvalidDecl()) { |
| 2241 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2242 | continue; |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2243 | } |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2244 | PrivateCopies.push_back(buildDeclRefExpr( |
| 2245 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2246 | } else { |
| 2247 | // The variable is also a firstprivate, so initialization sequence |
| 2248 | // for private copy is generated already. |
| 2249 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2250 | } |
| 2251 | } |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2252 | Clause->setPrivateCopies(PrivateCopies); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2253 | } |
| 2254 | } |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2255 | // Check allocate clauses. |
| 2256 | if (!CurContext->isDependentContext()) |
| 2257 | checkAllocateClauses(*this, DSAStack, D->clauses()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2260 | DSAStack->pop(); |
| 2261 | DiscardCleanupsInEvaluationContext(); |
| 2262 | PopExpressionEvaluationContext(); |
| 2263 | } |
| 2264 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 2265 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 2266 | Expr *NumIterations, Sema &SemaRef, |
| 2267 | Scope *S, DSAStackTy *Stack); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 2268 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2269 | namespace { |
| 2270 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2271 | class VarDeclFilterCCC final : public CorrectionCandidateCallback { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2272 | private: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2273 | Sema &SemaRef; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2274 | |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2275 | public: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2276 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 2277 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2278 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2279 | if (const auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2280 | return VD->hasGlobalStorage() && |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2281 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 2282 | SemaRef.getCurScope()); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2283 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2284 | return false; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2285 | } |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 2286 | |
| 2287 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
| Jonas Devlieghere | 2b3d49b | 2019-08-14 23:04:18 +0000 | [diff] [blame] | 2288 | return std::make_unique<VarDeclFilterCCC>(*this); |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2291 | }; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2292 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2293 | class VarOrFuncDeclFilterCCC final : public CorrectionCandidateCallback { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2294 | private: |
| 2295 | Sema &SemaRef; |
| 2296 | |
| 2297 | public: |
| 2298 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 2299 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 2300 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2301 | if (ND && ((isa<VarDecl>(ND) && ND->getKind() == Decl::Var) || |
| 2302 | isa<FunctionDecl>(ND))) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2303 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 2304 | SemaRef.getCurScope()); |
| 2305 | } |
| 2306 | return false; |
| 2307 | } |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 2308 | |
| 2309 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
| Jonas Devlieghere | 2b3d49b | 2019-08-14 23:04:18 +0000 | [diff] [blame] | 2310 | return std::make_unique<VarOrFuncDeclFilterCCC>(*this); |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 2311 | } |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2312 | }; |
| 2313 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2314 | } // namespace |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2315 | |
| 2316 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 2317 | CXXScopeSpec &ScopeSpec, |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2318 | const DeclarationNameInfo &Id, |
| 2319 | OpenMPDirectiveKind Kind) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2320 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 2321 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 2322 | |
| 2323 | if (Lookup.isAmbiguous()) |
| 2324 | return ExprError(); |
| 2325 | |
| 2326 | VarDecl *VD; |
| 2327 | if (!Lookup.isSingleResult()) { |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 2328 | VarDeclFilterCCC CCC(*this); |
| 2329 | if (TypoCorrection Corrected = |
| 2330 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, CCC, |
| 2331 | CTK_ErrorRecovery)) { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 2332 | diagnoseTypo(Corrected, |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2333 | PDiag(Lookup.empty() |
| 2334 | ? diag::err_undeclared_var_use_suggest |
| 2335 | : diag::err_omp_expected_var_arg_suggest) |
| 2336 | << Id.getName()); |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 2337 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2338 | } else { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 2339 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 2340 | : diag::err_omp_expected_var_arg) |
| 2341 | << Id.getName(); |
| 2342 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2343 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2344 | } else if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
| 2345 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
| 2346 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 2347 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2348 | } |
| 2349 | Lookup.suppressDiagnostics(); |
| 2350 | |
| 2351 | // OpenMP [2.9.2, Syntax, C/C++] |
| 2352 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2353 | if (Kind == OMPD_threadprivate && !VD->hasGlobalStorage()) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2354 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2355 | << getOpenMPDirectiveName(Kind) << !VD->isStaticLocal(); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2356 | bool IsDecl = |
| 2357 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2358 | Diag(VD->getLocation(), |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2359 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2360 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2361 | return ExprError(); |
| 2362 | } |
| 2363 | |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2364 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 2365 | NamedDecl *ND = CanonicalVD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2366 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 2367 | // A threadprivate directive for file-scope variables must appear outside |
| 2368 | // any definition or declaration. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2369 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 2370 | !getCurLexicalContext()->isTranslationUnit()) { |
| 2371 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2372 | << getOpenMPDirectiveName(Kind) << VD; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2373 | bool IsDecl = |
| 2374 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2375 | Diag(VD->getLocation(), |
| 2376 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2377 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2378 | return ExprError(); |
| 2379 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2380 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 2381 | // A threadprivate directive for static class member variables must appear |
| 2382 | // in the class definition, in the same scope in which the member |
| 2383 | // variables are declared. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2384 | if (CanonicalVD->isStaticDataMember() && |
| 2385 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 2386 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2387 | << getOpenMPDirectiveName(Kind) << VD; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2388 | bool IsDecl = |
| 2389 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2390 | Diag(VD->getLocation(), |
| 2391 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2392 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2393 | return ExprError(); |
| 2394 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2395 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 2396 | // A threadprivate directive for namespace-scope variables must appear |
| 2397 | // outside any definition or declaration other than the namespace |
| 2398 | // definition itself. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2399 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 2400 | (!getCurLexicalContext()->isFileContext() || |
| 2401 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 2402 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2403 | << getOpenMPDirectiveName(Kind) << VD; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2404 | bool IsDecl = |
| 2405 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2406 | Diag(VD->getLocation(), |
| 2407 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2408 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2409 | return ExprError(); |
| 2410 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2411 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 2412 | // A threadprivate directive for static block-scope variables must appear |
| 2413 | // in the scope of the variable and not in a nested scope. |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2414 | if (CanonicalVD->isLocalVarDecl() && CurScope && |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2415 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2416 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2417 | << getOpenMPDirectiveName(Kind) << VD; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2418 | bool IsDecl = |
| 2419 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2420 | Diag(VD->getLocation(), |
| 2421 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2422 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2423 | return ExprError(); |
| 2424 | } |
| 2425 | |
| 2426 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 2427 | // A threadprivate directive must lexically precede all references to any |
| 2428 | // of the variables in its list. |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2429 | if (Kind == OMPD_threadprivate && VD->isUsed() && |
| 2430 | !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2431 | Diag(Id.getLoc(), diag::err_omp_var_used) |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2432 | << getOpenMPDirectiveName(Kind) << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2433 | return ExprError(); |
| 2434 | } |
| 2435 | |
| 2436 | QualType ExprType = VD->getType().getNonReferenceType(); |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 2437 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 2438 | SourceLocation(), VD, |
| 2439 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 2440 | Id.getLoc(), ExprType, VK_LValue); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2443 | Sema::DeclGroupPtrTy |
| 2444 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 2445 | ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2446 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2447 | CurContext->addDecl(D); |
| 2448 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 2449 | } |
| David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 2450 | return nullptr; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2453 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2454 | class LocalVarRefChecker final |
| 2455 | : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2456 | Sema &SemaRef; |
| 2457 | |
| 2458 | public: |
| 2459 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2460 | if (const auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2461 | if (VD->hasLocalStorage()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2462 | SemaRef.Diag(E->getBeginLoc(), |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2463 | diag::err_omp_local_var_in_threadprivate_init) |
| 2464 | << E->getSourceRange(); |
| 2465 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 2466 | << VD << VD->getSourceRange(); |
| 2467 | return true; |
| 2468 | } |
| 2469 | } |
| 2470 | return false; |
| 2471 | } |
| 2472 | bool VisitStmt(const Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2473 | for (const Stmt *Child : S->children()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2474 | if (Child && Visit(Child)) |
| 2475 | return true; |
| 2476 | } |
| 2477 | return false; |
| 2478 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2479 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2480 | }; |
| 2481 | } // namespace |
| 2482 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2483 | OMPThreadPrivateDecl * |
| 2484 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2485 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2486 | for (Expr *RefExpr : VarList) { |
| 2487 | auto *DE = cast<DeclRefExpr>(RefExpr); |
| 2488 | auto *VD = cast<VarDecl>(DE->getDecl()); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2489 | SourceLocation ILoc = DE->getExprLoc(); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2490 | |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 2491 | // Mark variable as used. |
| 2492 | VD->setReferenced(); |
| 2493 | VD->markUsed(Context); |
| 2494 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 2495 | QualType QType = VD->getType(); |
| 2496 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 2497 | // It will be analyzed later. |
| 2498 | Vars.push_back(DE); |
| 2499 | continue; |
| 2500 | } |
| 2501 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2502 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 2503 | // A threadprivate variable must not have an incomplete type. |
| 2504 | if (RequireCompleteType(ILoc, VD->getType(), |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2505 | diag::err_omp_threadprivate_incomplete_type)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2506 | continue; |
| 2507 | } |
| 2508 | |
| 2509 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 2510 | // A threadprivate variable must not have a reference type. |
| 2511 | if (VD->getType()->isReferenceType()) { |
| 2512 | Diag(ILoc, diag::err_omp_ref_type_arg) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2513 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 2514 | bool IsDecl = |
| 2515 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2516 | Diag(VD->getLocation(), |
| 2517 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2518 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2519 | continue; |
| 2520 | } |
| 2521 | |
| Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 2522 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 2523 | // the corresponding diagnostic. |
| 2524 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 2525 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 2526 | getLangOpts().OpenMPUseTLS && |
| 2527 | getASTContext().getTargetInfo().isTLSSupported())) || |
| Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 2528 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 2529 | !VD->isLocalVarDecl())) { |
| Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 2530 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 2531 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2532 | bool IsDecl = |
| 2533 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2534 | Diag(VD->getLocation(), |
| 2535 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2536 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2537 | continue; |
| 2538 | } |
| 2539 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2540 | // Check if initial value of threadprivate variable reference variable with |
| 2541 | // local storage (it is not supported by runtime). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2542 | if (const Expr *Init = VD->getAnyInitializer()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2543 | LocalVarRefChecker Checker(*this); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2544 | if (Checker.Visit(Init)) |
| 2545 | continue; |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2548 | Vars.push_back(RefExpr); |
| Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 2549 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2550 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 2551 | Context, SourceRange(Loc, Loc))); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2552 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2553 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2554 | } |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2555 | OMPThreadPrivateDecl *D = nullptr; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 2556 | if (!Vars.empty()) { |
| 2557 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 2558 | Vars); |
| 2559 | D->setAccess(AS_public); |
| 2560 | } |
| 2561 | return D; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2562 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2563 | |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2564 | static OMPAllocateDeclAttr::AllocatorTypeTy |
| 2565 | getAllocatorKind(Sema &S, DSAStackTy *Stack, Expr *Allocator) { |
| 2566 | if (!Allocator) |
| 2567 | return OMPAllocateDeclAttr::OMPDefaultMemAlloc; |
| 2568 | if (Allocator->isTypeDependent() || Allocator->isValueDependent() || |
| 2569 | Allocator->isInstantiationDependent() || |
| Alexey Bataev | 441510e | 2019-03-21 19:05:07 +0000 | [diff] [blame] | 2570 | Allocator->containsUnexpandedParameterPack()) |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2571 | return OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2572 | auto AllocatorKindRes = OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2573 | const Expr *AE = Allocator->IgnoreParenImpCasts(); |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2574 | for (int I = OMPAllocateDeclAttr::OMPDefaultMemAlloc; |
| 2575 | I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) { |
| 2576 | auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2577 | const Expr *DefAllocator = Stack->getAllocator(AllocatorKind); |
| Alexey Bataev | 441510e | 2019-03-21 19:05:07 +0000 | [diff] [blame] | 2578 | llvm::FoldingSetNodeID AEId, DAEId; |
| 2579 | AE->Profile(AEId, S.getASTContext(), /*Canonical=*/true); |
| 2580 | DefAllocator->Profile(DAEId, S.getASTContext(), /*Canonical=*/true); |
| 2581 | if (AEId == DAEId) { |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2582 | AllocatorKindRes = AllocatorKind; |
| 2583 | break; |
| 2584 | } |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2585 | } |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2586 | return AllocatorKindRes; |
| 2587 | } |
| 2588 | |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2589 | static bool checkPreviousOMPAllocateAttribute( |
| 2590 | Sema &S, DSAStackTy *Stack, Expr *RefExpr, VarDecl *VD, |
| 2591 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, Expr *Allocator) { |
| 2592 | if (!VD->hasAttr<OMPAllocateDeclAttr>()) |
| 2593 | return false; |
| 2594 | const auto *A = VD->getAttr<OMPAllocateDeclAttr>(); |
| 2595 | Expr *PrevAllocator = A->getAllocator(); |
| 2596 | OMPAllocateDeclAttr::AllocatorTypeTy PrevAllocatorKind = |
| 2597 | getAllocatorKind(S, Stack, PrevAllocator); |
| 2598 | bool AllocatorsMatch = AllocatorKind == PrevAllocatorKind; |
| 2599 | if (AllocatorsMatch && |
| 2600 | AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc && |
| 2601 | Allocator && PrevAllocator) { |
| 2602 | const Expr *AE = Allocator->IgnoreParenImpCasts(); |
| 2603 | const Expr *PAE = PrevAllocator->IgnoreParenImpCasts(); |
| 2604 | llvm::FoldingSetNodeID AEId, PAEId; |
| 2605 | AE->Profile(AEId, S.Context, /*Canonical=*/true); |
| 2606 | PAE->Profile(PAEId, S.Context, /*Canonical=*/true); |
| 2607 | AllocatorsMatch = AEId == PAEId; |
| 2608 | } |
| 2609 | if (!AllocatorsMatch) { |
| 2610 | SmallString<256> AllocatorBuffer; |
| 2611 | llvm::raw_svector_ostream AllocatorStream(AllocatorBuffer); |
| 2612 | if (Allocator) |
| 2613 | Allocator->printPretty(AllocatorStream, nullptr, S.getPrintingPolicy()); |
| 2614 | SmallString<256> PrevAllocatorBuffer; |
| 2615 | llvm::raw_svector_ostream PrevAllocatorStream(PrevAllocatorBuffer); |
| 2616 | if (PrevAllocator) |
| 2617 | PrevAllocator->printPretty(PrevAllocatorStream, nullptr, |
| 2618 | S.getPrintingPolicy()); |
| 2619 | |
| 2620 | SourceLocation AllocatorLoc = |
| 2621 | Allocator ? Allocator->getExprLoc() : RefExpr->getExprLoc(); |
| 2622 | SourceRange AllocatorRange = |
| 2623 | Allocator ? Allocator->getSourceRange() : RefExpr->getSourceRange(); |
| 2624 | SourceLocation PrevAllocatorLoc = |
| 2625 | PrevAllocator ? PrevAllocator->getExprLoc() : A->getLocation(); |
| 2626 | SourceRange PrevAllocatorRange = |
| 2627 | PrevAllocator ? PrevAllocator->getSourceRange() : A->getRange(); |
| 2628 | S.Diag(AllocatorLoc, diag::warn_omp_used_different_allocator) |
| 2629 | << (Allocator ? 1 : 0) << AllocatorStream.str() |
| 2630 | << (PrevAllocator ? 1 : 0) << PrevAllocatorStream.str() |
| 2631 | << AllocatorRange; |
| 2632 | S.Diag(PrevAllocatorLoc, diag::note_omp_previous_allocator) |
| 2633 | << PrevAllocatorRange; |
| 2634 | return true; |
| 2635 | } |
| 2636 | return false; |
| 2637 | } |
| 2638 | |
| 2639 | static void |
| 2640 | applyOMPAllocateAttribute(Sema &S, VarDecl *VD, |
| 2641 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, |
| 2642 | Expr *Allocator, SourceRange SR) { |
| 2643 | if (VD->hasAttr<OMPAllocateDeclAttr>()) |
| 2644 | return; |
| 2645 | if (Allocator && |
| 2646 | (Allocator->isTypeDependent() || Allocator->isValueDependent() || |
| 2647 | Allocator->isInstantiationDependent() || |
| 2648 | Allocator->containsUnexpandedParameterPack())) |
| 2649 | return; |
| 2650 | auto *A = OMPAllocateDeclAttr::CreateImplicit(S.Context, AllocatorKind, |
| 2651 | Allocator, SR); |
| 2652 | VD->addAttr(A); |
| 2653 | if (ASTMutationListener *ML = S.Context.getASTMutationListener()) |
| 2654 | ML->DeclarationMarkedOpenMPAllocate(VD, A); |
| 2655 | } |
| 2656 | |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2657 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective( |
| 2658 | SourceLocation Loc, ArrayRef<Expr *> VarList, |
| 2659 | ArrayRef<OMPClause *> Clauses, DeclContext *Owner) { |
| 2660 | assert(Clauses.size() <= 1 && "Expected at most one clause."); |
| 2661 | Expr *Allocator = nullptr; |
| Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 2662 | if (Clauses.empty()) { |
| Alexey Bataev | f493607 | 2019-03-22 15:32:02 +0000 | [diff] [blame] | 2663 | // OpenMP 5.0, 2.11.3 allocate Directive, Restrictions. |
| 2664 | // allocate directives that appear in a target region must specify an |
| 2665 | // allocator clause unless a requires directive with the dynamic_allocators |
| 2666 | // clause is present in the same compilation unit. |
| Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 2667 | if (LangOpts.OpenMPIsDevice && |
| 2668 | !DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>()) |
| Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 2669 | targetDiag(Loc, diag::err_expected_allocator_clause); |
| 2670 | } else { |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2671 | Allocator = cast<OMPAllocatorClause>(Clauses.back())->getAllocator(); |
| Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 2672 | } |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 2673 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind = |
| 2674 | getAllocatorKind(*this, DSAStack, Allocator); |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2675 | SmallVector<Expr *, 8> Vars; |
| 2676 | for (Expr *RefExpr : VarList) { |
| 2677 | auto *DE = cast<DeclRefExpr>(RefExpr); |
| 2678 | auto *VD = cast<VarDecl>(DE->getDecl()); |
| 2679 | |
| 2680 | // Check if this is a TLS variable or global register. |
| 2681 | if (VD->getTLSKind() != VarDecl::TLS_None || |
| 2682 | VD->hasAttr<OMPThreadPrivateDeclAttr>() || |
| 2683 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 2684 | !VD->isLocalVarDecl())) |
| 2685 | continue; |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2686 | |
| Alexey Bataev | 282555a | 2019-03-19 20:33:44 +0000 | [diff] [blame] | 2687 | // If the used several times in the allocate directive, the same allocator |
| 2688 | // must be used. |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2689 | if (checkPreviousOMPAllocateAttribute(*this, DSAStack, RefExpr, VD, |
| 2690 | AllocatorKind, Allocator)) |
| 2691 | continue; |
| Alexey Bataev | 282555a | 2019-03-19 20:33:44 +0000 | [diff] [blame] | 2692 | |
| Alexey Bataev | d2fc965 | 2019-03-19 18:39:11 +0000 | [diff] [blame] | 2693 | // OpenMP, 2.11.3 allocate Directive, Restrictions, C / C++ |
| 2694 | // If a list item has a static storage type, the allocator expression in the |
| 2695 | // allocator clause must be a constant expression that evaluates to one of |
| 2696 | // the predefined memory allocator values. |
| 2697 | if (Allocator && VD->hasGlobalStorage()) { |
| Alexey Bataev | 441510e | 2019-03-21 19:05:07 +0000 | [diff] [blame] | 2698 | if (AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) { |
| Alexey Bataev | d2fc965 | 2019-03-19 18:39:11 +0000 | [diff] [blame] | 2699 | Diag(Allocator->getExprLoc(), |
| 2700 | diag::err_omp_expected_predefined_allocator) |
| 2701 | << Allocator->getSourceRange(); |
| 2702 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2703 | VarDecl::DeclarationOnly; |
| 2704 | Diag(VD->getLocation(), |
| 2705 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2706 | << VD; |
| 2707 | continue; |
| 2708 | } |
| 2709 | } |
| 2710 | |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2711 | Vars.push_back(RefExpr); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2712 | applyOMPAllocateAttribute(*this, VD, AllocatorKind, Allocator, |
| 2713 | DE->getSourceRange()); |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2714 | } |
| 2715 | if (Vars.empty()) |
| 2716 | return nullptr; |
| 2717 | if (!Owner) |
| 2718 | Owner = getCurLexicalContext(); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 2719 | auto *D = OMPAllocateDecl::Create(Context, Owner, Loc, Vars, Clauses); |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2720 | D->setAccess(AS_public); |
| 2721 | Owner->addDecl(D); |
| 2722 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 2723 | } |
| 2724 | |
| 2725 | Sema::DeclGroupPtrTy |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2726 | Sema::ActOnOpenMPRequiresDirective(SourceLocation Loc, |
| 2727 | ArrayRef<OMPClause *> ClauseList) { |
| 2728 | OMPRequiresDecl *D = nullptr; |
| 2729 | if (!CurContext->isFileContext()) { |
| 2730 | Diag(Loc, diag::err_omp_invalid_scope) << "requires"; |
| 2731 | } else { |
| 2732 | D = CheckOMPRequiresDecl(Loc, ClauseList); |
| 2733 | if (D) { |
| 2734 | CurContext->addDecl(D); |
| 2735 | DSAStack->addRequiresDecl(D); |
| 2736 | } |
| 2737 | } |
| 2738 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 2739 | } |
| 2740 | |
| 2741 | OMPRequiresDecl *Sema::CheckOMPRequiresDecl(SourceLocation Loc, |
| 2742 | ArrayRef<OMPClause *> ClauseList) { |
| Gheorghe-Teodor Bercea | 411a624 | 2019-04-18 19:53:43 +0000 | [diff] [blame] | 2743 | /// For target specific clauses, the requires directive cannot be |
| 2744 | /// specified after the handling of any of the target regions in the |
| 2745 | /// current compilation unit. |
| 2746 | ArrayRef<SourceLocation> TargetLocations = |
| 2747 | DSAStack->getEncounteredTargetLocs(); |
| 2748 | if (!TargetLocations.empty()) { |
| 2749 | for (const OMPClause *CNew : ClauseList) { |
| 2750 | // Check if any of the requires clauses affect target regions. |
| 2751 | if (isa<OMPUnifiedSharedMemoryClause>(CNew) || |
| 2752 | isa<OMPUnifiedAddressClause>(CNew) || |
| 2753 | isa<OMPReverseOffloadClause>(CNew) || |
| 2754 | isa<OMPDynamicAllocatorsClause>(CNew)) { |
| 2755 | Diag(Loc, diag::err_omp_target_before_requires) |
| 2756 | << getOpenMPClauseName(CNew->getClauseKind()); |
| 2757 | for (SourceLocation TargetLoc : TargetLocations) { |
| 2758 | Diag(TargetLoc, diag::note_omp_requires_encountered_target); |
| 2759 | } |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2764 | if (!DSAStack->hasDuplicateRequiresClause(ClauseList)) |
| 2765 | return OMPRequiresDecl::Create(Context, getCurLexicalContext(), Loc, |
| 2766 | ClauseList); |
| 2767 | return nullptr; |
| 2768 | } |
| 2769 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2770 | static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, |
| 2771 | const ValueDecl *D, |
| 2772 | const DSAStackTy::DSAVarData &DVar, |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2773 | bool IsLoopIterVar = false) { |
| 2774 | if (DVar.RefExpr) { |
| 2775 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2776 | << getOpenMPClauseName(DVar.CKind); |
| 2777 | return; |
| 2778 | } |
| 2779 | enum { |
| 2780 | PDSA_StaticMemberShared, |
| 2781 | PDSA_StaticLocalVarShared, |
| 2782 | PDSA_LoopIterVarPrivate, |
| 2783 | PDSA_LoopIterVarLinear, |
| 2784 | PDSA_LoopIterVarLastprivate, |
| 2785 | PDSA_ConstVarShared, |
| 2786 | PDSA_GlobalVarShared, |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2787 | PDSA_TaskVarFirstprivate, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2788 | PDSA_LocalVarPrivate, |
| 2789 | PDSA_Implicit |
| 2790 | } Reason = PDSA_Implicit; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2791 | bool ReportHint = false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2792 | auto ReportLoc = D->getLocation(); |
| 2793 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2794 | if (IsLoopIterVar) { |
| 2795 | if (DVar.CKind == OMPC_private) |
| 2796 | Reason = PDSA_LoopIterVarPrivate; |
| 2797 | else if (DVar.CKind == OMPC_lastprivate) |
| 2798 | Reason = PDSA_LoopIterVarLastprivate; |
| 2799 | else |
| 2800 | Reason = PDSA_LoopIterVarLinear; |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2801 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 2802 | DVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2803 | Reason = PDSA_TaskVarFirstprivate; |
| 2804 | ReportLoc = DVar.ImplicitDSALoc; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2805 | } else if (VD && VD->isStaticLocal()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2806 | Reason = PDSA_StaticLocalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2807 | else if (VD && VD->isStaticDataMember()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2808 | Reason = PDSA_StaticMemberShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2809 | else if (VD && VD->isFileVarDecl()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2810 | Reason = PDSA_GlobalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2811 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2812 | Reason = PDSA_ConstVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2813 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2814 | ReportHint = true; |
| 2815 | Reason = PDSA_LocalVarPrivate; |
| 2816 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2817 | if (Reason != PDSA_Implicit) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2818 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2819 | << Reason << ReportHint |
| 2820 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 2821 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 2822 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 2823 | << getOpenMPClauseName(DVar.CKind); |
| 2824 | } |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2827 | static OpenMPMapClauseKind |
| 2828 | getMapClauseKindFromModifier(OpenMPDefaultmapClauseModifier M, |
| 2829 | bool IsAggregateOrDeclareTarget) { |
| 2830 | OpenMPMapClauseKind Kind = OMPC_MAP_unknown; |
| 2831 | switch (M) { |
| 2832 | case OMPC_DEFAULTMAP_MODIFIER_alloc: |
| 2833 | Kind = OMPC_MAP_alloc; |
| 2834 | break; |
| 2835 | case OMPC_DEFAULTMAP_MODIFIER_to: |
| 2836 | Kind = OMPC_MAP_to; |
| 2837 | break; |
| 2838 | case OMPC_DEFAULTMAP_MODIFIER_from: |
| 2839 | Kind = OMPC_MAP_from; |
| 2840 | break; |
| 2841 | case OMPC_DEFAULTMAP_MODIFIER_tofrom: |
| 2842 | Kind = OMPC_MAP_tofrom; |
| 2843 | break; |
| 2844 | case OMPC_DEFAULTMAP_MODIFIER_firstprivate: |
| 2845 | case OMPC_DEFAULTMAP_MODIFIER_last: |
| 2846 | llvm_unreachable("Unexpected defaultmap implicit behavior"); |
| 2847 | case OMPC_DEFAULTMAP_MODIFIER_none: |
| 2848 | case OMPC_DEFAULTMAP_MODIFIER_default: |
| 2849 | case OMPC_DEFAULTMAP_MODIFIER_unknown: |
| 2850 | // IsAggregateOrDeclareTarget could be true if: |
| 2851 | // 1. the implicit behavior for aggregate is tofrom |
| 2852 | // 2. it's a declare target link |
| 2853 | if (IsAggregateOrDeclareTarget) { |
| 2854 | Kind = OMPC_MAP_tofrom; |
| 2855 | break; |
| 2856 | } |
| 2857 | llvm_unreachable("Unexpected defaultmap implicit behavior"); |
| 2858 | } |
| 2859 | assert(Kind != OMPC_MAP_unknown && "Expect map kind to be known"); |
| 2860 | return Kind; |
| 2861 | } |
| 2862 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2863 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2864 | class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2865 | DSAStackTy *Stack; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2866 | Sema &SemaRef; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2867 | bool ErrorFound = false; |
| Alexey Bataev | c09c065 | 2019-10-29 10:06:11 -0400 | [diff] [blame] | 2868 | bool TryCaptureCXXThisMembers = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2869 | CapturedStmt *CS = nullptr; |
| 2870 | llvm::SmallVector<Expr *, 4> ImplicitFirstprivate; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2871 | llvm::SmallVector<Expr *, 4> ImplicitMap[OMPC_MAP_delete]; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2872 | Sema::VarsWithInheritedDSAType VarsWithInheritedDSA; |
| 2873 | llvm::SmallDenseSet<const ValueDecl *, 4> ImplicitDeclarations; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2874 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 2875 | void VisitSubCaptures(OMPExecutableDirective *S) { |
| 2876 | // Check implicitly captured variables. |
| 2877 | if (!S->hasAssociatedStmt() || !S->getAssociatedStmt()) |
| 2878 | return; |
| Alexey Bataev | 1242d8f | 2019-06-28 20:45:14 +0000 | [diff] [blame] | 2879 | visitSubCaptures(S->getInnermostCapturedStmt()); |
| Alexey Bataev | c09c065 | 2019-10-29 10:06:11 -0400 | [diff] [blame] | 2880 | // Try to capture inner this->member references to generate correct mappings |
| 2881 | // and diagnostics. |
| 2882 | if (TryCaptureCXXThisMembers || |
| 2883 | (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
| 2884 | llvm::any_of(S->getInnermostCapturedStmt()->captures(), |
| 2885 | [](const CapturedStmt::Capture &C) { |
| 2886 | return C.capturesThis(); |
| 2887 | }))) { |
| 2888 | bool SavedTryCaptureCXXThisMembers = TryCaptureCXXThisMembers; |
| 2889 | TryCaptureCXXThisMembers = true; |
| 2890 | Visit(S->getInnermostCapturedStmt()->getCapturedStmt()); |
| 2891 | TryCaptureCXXThisMembers = SavedTryCaptureCXXThisMembers; |
| 2892 | } |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2895 | public: |
| 2896 | void VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | c09c065 | 2019-10-29 10:06:11 -0400 | [diff] [blame] | 2897 | if (TryCaptureCXXThisMembers || E->isTypeDependent() || |
| 2898 | E->isValueDependent() || E->containsUnexpandedParameterPack() || |
| 2899 | E->isInstantiationDependent()) |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 2900 | return; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2901 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 2902 | // Check the datasharing rules for the expressions in the clauses. |
| 2903 | if (!CS) { |
| 2904 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 2905 | if (!CED->hasAttr<OMPCaptureNoInitAttr>()) { |
| 2906 | Visit(CED->getInit()); |
| 2907 | return; |
| 2908 | } |
| Alexey Bataev | 1242d8f | 2019-06-28 20:45:14 +0000 | [diff] [blame] | 2909 | } else if (VD->isImplicit() || isa<OMPCapturedExprDecl>(VD)) |
| 2910 | // Do not analyze internal variables and do not enclose them into |
| 2911 | // implicit clauses. |
| 2912 | return; |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 2913 | VD = VD->getCanonicalDecl(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2914 | // Skip internally declared variables. |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 2915 | if (VD->hasLocalStorage() && CS && !CS->capturesVariable(VD)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2916 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2917 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2918 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2919 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 2920 | if (DVar.RefExpr || !ImplicitDeclarations.insert(VD).second) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2921 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2922 | |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 2923 | // Skip internally declared static variables. |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 2924 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 2925 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 2926 | if (VD->hasGlobalStorage() && CS && !CS->capturesVariable(VD) && |
| Gheorghe-Teodor Bercea | 5254f0a | 2019-06-14 17:58:26 +0000 | [diff] [blame] | 2927 | (Stack->hasRequiresDeclWithClause<OMPUnifiedSharedMemoryClause>() || |
| 2928 | !Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)) |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 2929 | return; |
| 2930 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2931 | SourceLocation ELoc = E->getExprLoc(); |
| 2932 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2933 | // The default(none) clause requires that each variable that is referenced |
| 2934 | // in the construct, and does not have a predetermined data-sharing |
| 2935 | // attribute, must have its data-sharing attribute explicitly determined |
| 2936 | // by being listed in a data-sharing attribute clause. |
| 2937 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 2938 | isImplicitOrExplicitTaskingRegion(DKind) && |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2939 | VarsWithInheritedDSA.count(VD) == 0) { |
| 2940 | VarsWithInheritedDSA[VD] = E; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2941 | return; |
| 2942 | } |
| 2943 | |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2944 | // OpenMP 5.0 [2.19.7.2, defaultmap clause, Description] |
| 2945 | // If implicit-behavior is none, each variable referenced in the |
| 2946 | // construct that does not have a predetermined data-sharing attribute |
| 2947 | // and does not appear in a to or link clause on a declare target |
| 2948 | // directive must be listed in a data-mapping attribute clause, a |
| 2949 | // data-haring attribute clause (including a data-sharing attribute |
| 2950 | // clause on a combined construct where target. is one of the |
| 2951 | // constituent constructs), or an is_device_ptr clause. |
| Alexey Bataev | 6f7c876 | 2019-11-22 11:09:33 -0500 | [diff] [blame] | 2952 | OpenMPDefaultmapClauseKind ClauseKind = |
| 2953 | getVariableCategoryFromDecl(SemaRef.getLangOpts(), VD); |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2954 | if (SemaRef.getLangOpts().OpenMP >= 50) { |
| 2955 | bool IsModifierNone = Stack->getDefaultmapModifier(ClauseKind) == |
| 2956 | OMPC_DEFAULTMAP_MODIFIER_none; |
| 2957 | if (DVar.CKind == OMPC_unknown && IsModifierNone && |
| 2958 | VarsWithInheritedDSA.count(VD) == 0 && !Res) { |
| 2959 | // Only check for data-mapping attribute and is_device_ptr here |
| 2960 | // since we have already make sure that the declaration does not |
| 2961 | // have a data-sharing attribute above |
| 2962 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2963 | VD, /*CurrentRegionOnly=*/true, |
| 2964 | [VD](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2965 | MapExprComponents, |
| 2966 | OpenMPClauseKind) { |
| 2967 | auto MI = MapExprComponents.rbegin(); |
| 2968 | auto ME = MapExprComponents.rend(); |
| 2969 | return MI != ME && MI->getAssociatedDeclaration() == VD; |
| 2970 | })) { |
| 2971 | VarsWithInheritedDSA[VD] = E; |
| 2972 | return; |
| 2973 | } |
| 2974 | } |
| 2975 | } |
| 2976 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2977 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 2978 | !Stack->isLoopControlVariable(VD).first) { |
| 2979 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2980 | VD, /*CurrentRegionOnly=*/true, |
| 2981 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2982 | StackComponents, |
| 2983 | OpenMPClauseKind) { |
| 2984 | // Variable is used if it has been marked as an array, array |
| 2985 | // section or the variable iself. |
| 2986 | return StackComponents.size() == 1 || |
| 2987 | std::all_of( |
| 2988 | std::next(StackComponents.rbegin()), |
| 2989 | StackComponents.rend(), |
| 2990 | [](const OMPClauseMappableExprCommon:: |
| 2991 | MappableComponent &MC) { |
| 2992 | return MC.getAssociatedDeclaration() == |
| 2993 | nullptr && |
| 2994 | (isa<OMPArraySectionExpr>( |
| 2995 | MC.getAssociatedExpression()) || |
| 2996 | isa<ArraySubscriptExpr>( |
| 2997 | MC.getAssociatedExpression())); |
| 2998 | }); |
| 2999 | })) { |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 3000 | bool IsFirstprivate = false; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3001 | // By default lambdas are captured as firstprivates. |
| 3002 | if (const auto *RD = |
| 3003 | VD->getType().getNonReferenceType()->getAsCXXRecordDecl()) |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 3004 | IsFirstprivate = RD->isLambda(); |
| 3005 | IsFirstprivate = |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 3006 | IsFirstprivate || (Stack->mustBeFirstprivate(ClauseKind) && !Res); |
| 3007 | if (IsFirstprivate) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3008 | ImplicitFirstprivate.emplace_back(E); |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 3009 | } else { |
| 3010 | OpenMPDefaultmapClauseModifier M = |
| 3011 | Stack->getDefaultmapModifier(ClauseKind); |
| 3012 | OpenMPMapClauseKind Kind = getMapClauseKindFromModifier( |
| 3013 | M, ClauseKind == OMPC_DEFAULTMAP_aggregate || Res); |
| 3014 | ImplicitMap[Kind].emplace_back(E); |
| 3015 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3016 | return; |
| 3017 | } |
| 3018 | } |
| 3019 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3020 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 3021 | // A list item that appears in a reduction clause of the innermost |
| 3022 | // enclosing worksharing or parallel construct may not be accessed in an |
| 3023 | // explicit task. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3024 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3025 | VD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 3026 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3027 | return isOpenMPParallelDirective(K) || |
| 3028 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 3029 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 3030 | /*FromParent=*/true); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3031 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3032 | ErrorFound = true; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3033 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3034 | reportOriginalDsa(SemaRef, Stack, VD, DVar); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3035 | return; |
| 3036 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3037 | |
| 3038 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3039 | DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3040 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 3041 | !Stack->isLoopControlVariable(VD).first) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3042 | ImplicitFirstprivate.push_back(E); |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 3043 | return; |
| 3044 | } |
| 3045 | |
| 3046 | // Store implicitly used globals with declare target link for parent |
| 3047 | // target. |
| 3048 | if (!isOpenMPTargetExecutionDirective(DKind) && Res && |
| 3049 | *Res == OMPDeclareTargetDeclAttr::MT_Link) { |
| 3050 | Stack->addToParentTargetRegionLinkGlobals(E); |
| 3051 | return; |
| 3052 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3053 | } |
| 3054 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3055 | void VisitMemberExpr(MemberExpr *E) { |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 3056 | if (E->isTypeDependent() || E->isValueDependent() || |
| 3057 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 3058 | return; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3059 | auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3060 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 3061 | if (auto *TE = dyn_cast<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 3062 | if (!FD) |
| 3063 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3064 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3065 | // Check if the variable has explicit DSA set and stop analysis if it |
| 3066 | // so. |
| 3067 | if (DVar.RefExpr || !ImplicitDeclarations.insert(FD).second) |
| 3068 | return; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3069 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3070 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 3071 | !Stack->isLoopControlVariable(FD).first && |
| 3072 | !Stack->checkMappableExprComponentListsForDecl( |
| 3073 | FD, /*CurrentRegionOnly=*/true, |
| 3074 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 3075 | StackComponents, |
| 3076 | OpenMPClauseKind) { |
| 3077 | return isa<CXXThisExpr>( |
| 3078 | cast<MemberExpr>( |
| 3079 | StackComponents.back().getAssociatedExpression()) |
| 3080 | ->getBase() |
| 3081 | ->IgnoreParens()); |
| 3082 | })) { |
| 3083 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 3084 | // A bit-field cannot appear in a map clause. |
| 3085 | // |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 3086 | if (FD->isBitField()) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3087 | return; |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 3088 | |
| 3089 | // Check to see if the member expression is referencing a class that |
| 3090 | // has already been explicitly mapped |
| 3091 | if (Stack->isClassPreviouslyMapped(TE->getType())) |
| 3092 | return; |
| 3093 | |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 3094 | OpenMPDefaultmapClauseModifier Modifier = |
| 3095 | Stack->getDefaultmapModifier(OMPC_DEFAULTMAP_aggregate); |
| 3096 | OpenMPMapClauseKind Kind = getMapClauseKindFromModifier( |
| 3097 | Modifier, /*IsAggregateOrDeclareTarget*/ true); |
| 3098 | ImplicitMap[Kind].emplace_back(E); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3099 | return; |
| 3100 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3101 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3102 | SourceLocation ELoc = E->getExprLoc(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3103 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 3104 | // A list item that appears in a reduction clause of the innermost |
| 3105 | // enclosing worksharing or parallel construct may not be accessed in |
| 3106 | // an explicit task. |
| 3107 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3108 | FD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 3109 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3110 | return isOpenMPParallelDirective(K) || |
| 3111 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 3112 | }, |
| 3113 | /*FromParent=*/true); |
| 3114 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| 3115 | ErrorFound = true; |
| 3116 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3117 | reportOriginalDsa(SemaRef, Stack, FD, DVar); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3118 | return; |
| 3119 | } |
| 3120 | |
| 3121 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3122 | DVar = Stack->getImplicitDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3123 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| Alexey Bataev | b40e0520 | 2018-10-24 18:53:12 +0000 | [diff] [blame] | 3124 | !Stack->isLoopControlVariable(FD).first) { |
| 3125 | // Check if there is a captured expression for the current field in the |
| 3126 | // region. Do not mark it as firstprivate unless there is no captured |
| 3127 | // expression. |
| 3128 | // TODO: try to make it firstprivate. |
| 3129 | if (DVar.CKind != OMPC_unknown) |
| 3130 | ImplicitFirstprivate.push_back(E); |
| 3131 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3132 | return; |
| 3133 | } |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 3134 | if (isOpenMPTargetExecutionDirective(DKind)) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3135 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3136 | if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 3137 | /*NoDiagnose=*/true)) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 3138 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3139 | const auto *VD = cast<ValueDecl>( |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3140 | CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); |
| 3141 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 3142 | VD, /*CurrentRegionOnly=*/true, |
| 3143 | [&CurComponents]( |
| 3144 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 3145 | StackComponents, |
| 3146 | OpenMPClauseKind) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3147 | auto CCI = CurComponents.rbegin(); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 3148 | auto CCE = CurComponents.rend(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3149 | for (const auto &SC : llvm::reverse(StackComponents)) { |
| 3150 | // Do both expressions have the same kind? |
| 3151 | if (CCI->getAssociatedExpression()->getStmtClass() != |
| 3152 | SC.getAssociatedExpression()->getStmtClass()) |
| 3153 | if (!(isa<OMPArraySectionExpr>( |
| 3154 | SC.getAssociatedExpression()) && |
| 3155 | isa<ArraySubscriptExpr>( |
| 3156 | CCI->getAssociatedExpression()))) |
| 3157 | return false; |
| 3158 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3159 | const Decl *CCD = CCI->getAssociatedDeclaration(); |
| 3160 | const Decl *SCD = SC.getAssociatedDeclaration(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3161 | CCD = CCD ? CCD->getCanonicalDecl() : nullptr; |
| 3162 | SCD = SCD ? SCD->getCanonicalDecl() : nullptr; |
| 3163 | if (SCD != CCD) |
| 3164 | return false; |
| 3165 | std::advance(CCI, 1); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 3166 | if (CCI == CCE) |
| 3167 | break; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3168 | } |
| 3169 | return true; |
| 3170 | })) { |
| 3171 | Visit(E->getBase()); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3172 | } |
| Alexey Bataev | c09c065 | 2019-10-29 10:06:11 -0400 | [diff] [blame] | 3173 | } else if (!TryCaptureCXXThisMembers) { |
| Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 3174 | Visit(E->getBase()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3175 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3176 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3177 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3178 | for (OMPClause *C : S->clauses()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3179 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3180 | // for task|target directives. |
| 3181 | // Skip analysis of arguments of implicitly defined map clause for target |
| 3182 | // directives. |
| 3183 | if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) && |
| 3184 | C->isImplicit())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3185 | for (Stmt *CC : C->children()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3186 | if (CC) |
| 3187 | Visit(CC); |
| 3188 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3189 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3190 | } |
| Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 3191 | // Check implicitly captured variables. |
| 3192 | VisitSubCaptures(S); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3193 | } |
| 3194 | void VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3195 | for (Stmt *C : S->children()) { |
| Alexey Bataev | 8fc7b5f | 2018-10-25 15:35:27 +0000 | [diff] [blame] | 3196 | if (C) { |
| Joel E. Denny | 0fdf5a9 | 2018-12-19 15:59:47 +0000 | [diff] [blame] | 3197 | // Check implicitly captured variables in the task-based directives to |
| 3198 | // check if they must be firstprivatized. |
| 3199 | Visit(C); |
| Alexey Bataev | 8fc7b5f | 2018-10-25 15:35:27 +0000 | [diff] [blame] | 3200 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3201 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3202 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3203 | |
| Alexey Bataev | 1242d8f | 2019-06-28 20:45:14 +0000 | [diff] [blame] | 3204 | void visitSubCaptures(CapturedStmt *S) { |
| 3205 | for (const CapturedStmt::Capture &Cap : S->captures()) { |
| 3206 | if (!Cap.capturesVariable() && !Cap.capturesVariableByCopy()) |
| 3207 | continue; |
| 3208 | VarDecl *VD = Cap.getCapturedVar(); |
| 3209 | // Do not try to map the variable if it or its sub-component was mapped |
| 3210 | // already. |
| 3211 | if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
| 3212 | Stack->checkMappableExprComponentListsForDecl( |
| 3213 | VD, /*CurrentRegionOnly=*/true, |
| 3214 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 3215 | OpenMPClauseKind) { return true; })) |
| 3216 | continue; |
| 3217 | DeclRefExpr *DRE = buildDeclRefExpr( |
| 3218 | SemaRef, VD, VD->getType().getNonLValueExprType(SemaRef.Context), |
| 3219 | Cap.getLocation(), /*RefersToCapture=*/true); |
| 3220 | Visit(DRE); |
| 3221 | } |
| 3222 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3223 | bool isErrorFound() const { return ErrorFound; } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3224 | ArrayRef<Expr *> getImplicitFirstprivate() const { |
| 3225 | return ImplicitFirstprivate; |
| 3226 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 3227 | ArrayRef<Expr *> getImplicitMap(OpenMPDefaultmapClauseKind Kind) const { |
| 3228 | return ImplicitMap[Kind]; |
| 3229 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3230 | const Sema::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const { |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3231 | return VarsWithInheritedDSA; |
| 3232 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3233 | |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3234 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| Alexey Bataev | a495c64 | 2019-03-11 19:51:42 +0000 | [diff] [blame] | 3235 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) { |
| 3236 | // Process declare target link variables for the target directives. |
| 3237 | if (isOpenMPTargetExecutionDirective(S->getCurrentDirective())) { |
| 3238 | for (DeclRefExpr *E : Stack->getLinkGlobals()) |
| 3239 | Visit(E); |
| 3240 | } |
| 3241 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3242 | }; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3243 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3244 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3245 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3246 | switch (DKind) { |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 3247 | case OMPD_parallel: |
| 3248 | case OMPD_parallel_for: |
| 3249 | case OMPD_parallel_for_simd: |
| 3250 | case OMPD_parallel_sections: |
| Carlo Bertolli | ba1487b | 2017-10-04 14:12:09 +0000 | [diff] [blame] | 3251 | case OMPD_teams: |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 3252 | case OMPD_teams_distribute: |
| 3253 | case OMPD_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3254 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 3255 | QualType KmpInt32PtrTy = |
| 3256 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3257 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3258 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3259 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 3260 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3261 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3262 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3263 | Params); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3264 | break; |
| 3265 | } |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 3266 | case OMPD_target_teams: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 3267 | case OMPD_target_parallel: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 3268 | case OMPD_target_parallel_for: |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 3269 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 3270 | case OMPD_target_teams_distribute: |
| 3271 | case OMPD_target_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3272 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 3273 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3274 | QualType KmpInt32PtrTy = |
| 3275 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3276 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3277 | FunctionProtoType::ExtProtoInfo EPI; |
| 3278 | EPI.Variadic = true; |
| 3279 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 3280 | Sema::CapturedParamNameType Params[] = { |
| 3281 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3282 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3283 | std::make_pair(".privates.", VoidPtrTy), |
| 3284 | std::make_pair( |
| 3285 | ".copy_fn.", |
| 3286 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3287 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3288 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3289 | }; |
| 3290 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3291 | Params, /*OpenMPCaptureLevel=*/0); |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 3292 | // Mark this captured region as inlined, because we don't use outlined |
| 3293 | // function directly. |
| 3294 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3295 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3296 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3297 | AlwaysInlineAttr::Keyword_forceinline)); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3298 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 3299 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3300 | }; |
| 3301 | // Start a captured region for 'target' with no implicit parameters. |
| 3302 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3303 | ParamsTarget, /*OpenMPCaptureLevel=*/1); |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 3304 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3305 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3306 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 3307 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3308 | }; |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 3309 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 3310 | // the same implicit parameters. |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3311 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3312 | ParamsTeamsOrParallel, /*OpenMPCaptureLevel=*/2); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3313 | break; |
| 3314 | } |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3315 | case OMPD_target: |
| 3316 | case OMPD_target_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3317 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 3318 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3319 | QualType KmpInt32PtrTy = |
| 3320 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3321 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3322 | FunctionProtoType::ExtProtoInfo EPI; |
| 3323 | EPI.Variadic = true; |
| 3324 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 3325 | Sema::CapturedParamNameType Params[] = { |
| 3326 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3327 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3328 | std::make_pair(".privates.", VoidPtrTy), |
| 3329 | std::make_pair( |
| 3330 | ".copy_fn.", |
| 3331 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3332 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3333 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3334 | }; |
| 3335 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3336 | Params, /*OpenMPCaptureLevel=*/0); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3337 | // Mark this captured region as inlined, because we don't use outlined |
| 3338 | // function directly. |
| 3339 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3340 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3341 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3342 | AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3343 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3344 | std::make_pair(StringRef(), QualType()), |
| 3345 | /*OpenMPCaptureLevel=*/1); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3346 | break; |
| 3347 | } |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 3348 | case OMPD_simd: |
| 3349 | case OMPD_for: |
| 3350 | case OMPD_for_simd: |
| 3351 | case OMPD_sections: |
| 3352 | case OMPD_section: |
| 3353 | case OMPD_single: |
| 3354 | case OMPD_master: |
| 3355 | case OMPD_critical: |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3356 | case OMPD_taskgroup: |
| 3357 | case OMPD_distribute: |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 3358 | case OMPD_distribute_simd: |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 3359 | case OMPD_ordered: |
| 3360 | case OMPD_atomic: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3361 | case OMPD_target_data: { |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3362 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3363 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3364 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3365 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3366 | Params); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3367 | break; |
| 3368 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3369 | case OMPD_task: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3370 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 3371 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3372 | QualType KmpInt32PtrTy = |
| 3373 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3374 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 3375 | FunctionProtoType::ExtProtoInfo EPI; |
| 3376 | EPI.Variadic = true; |
| 3377 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3378 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 3379 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3380 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3381 | std::make_pair(".privates.", VoidPtrTy), |
| 3382 | std::make_pair( |
| 3383 | ".copy_fn.", |
| 3384 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 3385 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3386 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3387 | }; |
| 3388 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3389 | Params); |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 3390 | // Mark this captured region as inlined, because we don't use outlined |
| 3391 | // function directly. |
| 3392 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3393 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3394 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3395 | AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3396 | break; |
| 3397 | } |
| Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 3398 | case OMPD_taskloop: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 3399 | case OMPD_taskloop_simd: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 3400 | case OMPD_master_taskloop: |
| 3401 | case OMPD_master_taskloop_simd: { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3402 | QualType KmpInt32Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3403 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
| 3404 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3405 | QualType KmpUInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3406 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
| 3407 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3408 | QualType KmpInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3409 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
| 3410 | .withConst(); |
| 3411 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3412 | QualType KmpInt32PtrTy = |
| 3413 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3414 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3415 | FunctionProtoType::ExtProtoInfo EPI; |
| 3416 | EPI.Variadic = true; |
| 3417 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3418 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3419 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3420 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3421 | std::make_pair(".privates.", VoidPtrTy), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3422 | std::make_pair( |
| 3423 | ".copy_fn.", |
| 3424 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 3425 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3426 | std::make_pair(".lb.", KmpUInt64Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3427 | std::make_pair(".ub.", KmpUInt64Ty), |
| 3428 | std::make_pair(".st.", KmpInt64Ty), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3429 | std::make_pair(".liter.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3430 | std::make_pair(".reductions.", VoidPtrTy), |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3431 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3432 | }; |
| 3433 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3434 | Params); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3435 | // Mark this captured region as inlined, because we don't use outlined |
| 3436 | // function directly. |
| 3437 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3438 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3439 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3440 | AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 3443 | case OMPD_parallel_master_taskloop: |
| 3444 | case OMPD_parallel_master_taskloop_simd: { |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 3445 | QualType KmpInt32Ty = |
| 3446 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
| 3447 | .withConst(); |
| 3448 | QualType KmpUInt64Ty = |
| 3449 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
| 3450 | .withConst(); |
| 3451 | QualType KmpInt64Ty = |
| 3452 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
| 3453 | .withConst(); |
| 3454 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3455 | QualType KmpInt32PtrTy = |
| 3456 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3457 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 3458 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3459 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 3460 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3461 | }; |
| 3462 | // Start a captured region for 'parallel'. |
| 3463 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3464 | ParamsParallel, /*OpenMPCaptureLevel=*/1); |
| 3465 | QualType Args[] = {VoidPtrTy}; |
| 3466 | FunctionProtoType::ExtProtoInfo EPI; |
| 3467 | EPI.Variadic = true; |
| 3468 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 3469 | Sema::CapturedParamNameType Params[] = { |
| 3470 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 3471 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3472 | std::make_pair(".privates.", VoidPtrTy), |
| 3473 | std::make_pair( |
| 3474 | ".copy_fn.", |
| 3475 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 3476 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3477 | std::make_pair(".lb.", KmpUInt64Ty), |
| 3478 | std::make_pair(".ub.", KmpUInt64Ty), |
| 3479 | std::make_pair(".st.", KmpInt64Ty), |
| 3480 | std::make_pair(".liter.", KmpInt32Ty), |
| 3481 | std::make_pair(".reductions.", VoidPtrTy), |
| 3482 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3483 | }; |
| 3484 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3485 | Params, /*OpenMPCaptureLevel=*/2); |
| 3486 | // Mark this captured region as inlined, because we don't use outlined |
| 3487 | // function directly. |
| 3488 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3489 | AlwaysInlineAttr::CreateImplicit( |
| 3490 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3491 | AlwaysInlineAttr::Keyword_forceinline)); |
| 3492 | break; |
| 3493 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3494 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 3495 | case OMPD_distribute_parallel_for: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3496 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3497 | QualType KmpInt32PtrTy = |
| 3498 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3499 | Sema::CapturedParamNameType Params[] = { |
| 3500 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3501 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3502 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 3503 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3504 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3505 | }; |
| 3506 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3507 | Params); |
| 3508 | break; |
| 3509 | } |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 3510 | case OMPD_target_teams_distribute_parallel_for: |
| 3511 | case OMPD_target_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3512 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3513 | QualType KmpInt32PtrTy = |
| 3514 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3515 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3516 | |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3517 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3518 | FunctionProtoType::ExtProtoInfo EPI; |
| 3519 | EPI.Variadic = true; |
| 3520 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 3521 | Sema::CapturedParamNameType Params[] = { |
| 3522 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3523 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3524 | std::make_pair(".privates.", VoidPtrTy), |
| 3525 | std::make_pair( |
| 3526 | ".copy_fn.", |
| 3527 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 3528 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3529 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3530 | }; |
| 3531 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3532 | Params, /*OpenMPCaptureLevel=*/0); |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 3533 | // Mark this captured region as inlined, because we don't use outlined |
| 3534 | // function directly. |
| 3535 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3536 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3537 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3538 | AlwaysInlineAttr::Keyword_forceinline)); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3539 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 3540 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3541 | }; |
| 3542 | // Start a captured region for 'target' with no implicit parameters. |
| 3543 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3544 | ParamsTarget, /*OpenMPCaptureLevel=*/1); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3545 | |
| 3546 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 3547 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3548 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 3549 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3550 | }; |
| 3551 | // Start a captured region for 'target' with no implicit parameters. |
| 3552 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3553 | ParamsTeams, /*OpenMPCaptureLevel=*/2); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3554 | |
| 3555 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 3556 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3557 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3558 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 3559 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3560 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3561 | }; |
| 3562 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 3563 | // the same implicit parameters. |
| 3564 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3565 | ParamsParallel, /*OpenMPCaptureLevel=*/3); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 3566 | break; |
| 3567 | } |
| 3568 | |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 3569 | case OMPD_teams_distribute_parallel_for: |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 3570 | case OMPD_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3571 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 3572 | QualType KmpInt32PtrTy = |
| 3573 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3574 | |
| 3575 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 3576 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3577 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 3578 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3579 | }; |
| 3580 | // Start a captured region for 'target' with no implicit parameters. |
| 3581 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3582 | ParamsTeams, /*OpenMPCaptureLevel=*/0); |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 3583 | |
| 3584 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 3585 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 3586 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3587 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 3588 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 3589 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3590 | }; |
| 3591 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 3592 | // the same implicit parameters. |
| 3593 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 3594 | ParamsParallel, /*OpenMPCaptureLevel=*/1); |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3597 | case OMPD_target_update: |
| 3598 | case OMPD_target_enter_data: |
| 3599 | case OMPD_target_exit_data: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3600 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 3601 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 3602 | QualType KmpInt32PtrTy = |
| 3603 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 3604 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3605 | FunctionProtoType::ExtProtoInfo EPI; |
| 3606 | EPI.Variadic = true; |
| 3607 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 3608 | Sema::CapturedParamNameType Params[] = { |
| 3609 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 3610 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 3611 | std::make_pair(".privates.", VoidPtrTy), |
| 3612 | std::make_pair( |
| 3613 | ".copy_fn.", |
| 3614 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3615 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 3616 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 3617 | }; |
| 3618 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 3619 | Params); |
| 3620 | // Mark this captured region as inlined, because we don't use outlined |
| 3621 | // function directly. |
| 3622 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 3623 | AlwaysInlineAttr::CreateImplicit( |
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 3624 | Context, {}, AttributeCommonInfo::AS_Keyword, |
| 3625 | AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3628 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 3629 | case OMPD_allocate: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 3630 | case OMPD_taskyield: |
| 3631 | case OMPD_barrier: |
| 3632 | case OMPD_taskwait: |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3633 | case OMPD_cancellation_point: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3634 | case OMPD_cancel: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 3635 | case OMPD_flush: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3636 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 3637 | case OMPD_declare_mapper: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3638 | case OMPD_declare_simd: |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3639 | case OMPD_declare_target: |
| 3640 | case OMPD_end_declare_target: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 3641 | case OMPD_requires: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 3642 | case OMPD_declare_variant: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3643 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3644 | case OMPD_unknown: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3645 | llvm_unreachable("Unknown OpenMP directive"); |
| 3646 | } |
| 3647 | } |
| 3648 | |
| Alexey Bataev | 0e10003 | 2019-10-14 16:44:01 +0000 | [diff] [blame] | 3649 | int Sema::getNumberOfConstructScopes(unsigned Level) const { |
| 3650 | return getOpenMPCaptureLevels(DSAStack->getDirective(Level)); |
| 3651 | } |
| 3652 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3653 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 3654 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 3655 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 3656 | return CaptureRegions.size(); |
| 3657 | } |
| 3658 | |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 3659 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3660 | Expr *CaptureExpr, bool WithInit, |
| 3661 | bool AsExpression) { |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 3662 | assert(CaptureExpr); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3663 | ASTContext &C = S.getASTContext(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3664 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3665 | QualType Ty = Init->getType(); |
| 3666 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3667 | if (S.getLangOpts().CPlusPlus) { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3668 | Ty = C.getLValueReferenceType(Ty); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3669 | } else { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3670 | Ty = C.getPointerType(Ty); |
| 3671 | ExprResult Res = |
| 3672 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 3673 | if (!Res.isUsable()) |
| 3674 | return nullptr; |
| 3675 | Init = Res.get(); |
| 3676 | } |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 3677 | WithInit = true; |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3678 | } |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3679 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3680 | CaptureExpr->getBeginLoc()); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 3681 | if (!WithInit) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3682 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C)); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3683 | S.CurContext->addHiddenDecl(CED); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 3684 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 3685 | return CED; |
| 3686 | } |
| 3687 | |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 3688 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 3689 | bool WithInit) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 3690 | OMPCapturedExprDecl *CD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3691 | if (VarDecl *VD = S.isOpenMPCapturedDecl(D)) |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 3692 | CD = cast<OMPCapturedExprDecl>(VD); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3693 | else |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3694 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 3695 | /*AsExpression=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 3696 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 3697 | CaptureExpr->getExprLoc()); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3700 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3701 | CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3702 | if (!Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3703 | OMPCapturedExprDecl *CD = buildCaptureDecl( |
| 3704 | S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr, |
| 3705 | /*WithInit=*/true, /*AsExpression=*/true); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3706 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 3707 | CaptureExpr->getExprLoc()); |
| 3708 | } |
| 3709 | ExprResult Res = Ref; |
| 3710 | if (!S.getLangOpts().CPlusPlus && |
| 3711 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3712 | Ref->getType()->isPointerType()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3713 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 3714 | if (!Res.isUsable()) |
| 3715 | return ExprError(); |
| 3716 | } |
| 3717 | return S.DefaultLvalueConversion(Res.get()); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3718 | } |
| 3719 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3720 | namespace { |
| 3721 | // OpenMP directives parsed in this section are represented as a |
| 3722 | // CapturedStatement with an associated statement. If a syntax error |
| 3723 | // is detected during the parsing of the associated statement, the |
| 3724 | // compiler must abort processing and close the CapturedStatement. |
| 3725 | // |
| 3726 | // Combined directives such as 'target parallel' have more than one |
| 3727 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 3728 | // of all the nested CapturedStatements when an error is found. |
| 3729 | class CaptureRegionUnwinderRAII { |
| 3730 | private: |
| 3731 | Sema &S; |
| 3732 | bool &ErrorFound; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3733 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3734 | |
| 3735 | public: |
| 3736 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 3737 | OpenMPDirectiveKind DKind) |
| 3738 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 3739 | ~CaptureRegionUnwinderRAII() { |
| 3740 | if (ErrorFound) { |
| 3741 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 3742 | while (--ThisCaptureLevel >= 0) |
| 3743 | S.ActOnCapturedRegionError(); |
| 3744 | } |
| 3745 | } |
| 3746 | }; |
| 3747 | } // namespace |
| 3748 | |
| Alexey Bataev | b600ae3 | 2019-07-01 17:46:52 +0000 | [diff] [blame] | 3749 | void Sema::tryCaptureOpenMPLambdas(ValueDecl *V) { |
| 3750 | // Capture variables captured by reference in lambdas for target-based |
| 3751 | // directives. |
| 3752 | if (!CurContext->isDependentContext() && |
| 3753 | (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) || |
| 3754 | isOpenMPTargetDataManagementDirective( |
| 3755 | DSAStack->getCurrentDirective()))) { |
| 3756 | QualType Type = V->getType(); |
| 3757 | if (const auto *RD = Type.getCanonicalType() |
| 3758 | .getNonReferenceType() |
| 3759 | ->getAsCXXRecordDecl()) { |
| 3760 | bool SavedForceCaptureByReferenceInTargetExecutable = |
| 3761 | DSAStack->isForceCaptureByReferenceInTargetExecutable(); |
| 3762 | DSAStack->setForceCaptureByReferenceInTargetExecutable( |
| 3763 | /*V=*/true); |
| 3764 | if (RD->isLambda()) { |
| 3765 | llvm::DenseMap<const VarDecl *, FieldDecl *> Captures; |
| 3766 | FieldDecl *ThisCapture; |
| 3767 | RD->getCaptureFields(Captures, ThisCapture); |
| 3768 | for (const LambdaCapture &LC : RD->captures()) { |
| 3769 | if (LC.getCaptureKind() == LCK_ByRef) { |
| 3770 | VarDecl *VD = LC.getCapturedVar(); |
| 3771 | DeclContext *VDC = VD->getDeclContext(); |
| 3772 | if (!VDC->Encloses(CurContext)) |
| 3773 | continue; |
| 3774 | MarkVariableReferenced(LC.getLocation(), VD); |
| 3775 | } else if (LC.getCaptureKind() == LCK_This) { |
| 3776 | QualType ThisTy = getCurrentThisType(); |
| 3777 | if (!ThisTy.isNull() && |
| 3778 | Context.typesAreCompatible(ThisTy, ThisCapture->getType())) |
| 3779 | CheckCXXThisCapture(LC.getLocation()); |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | DSAStack->setForceCaptureByReferenceInTargetExecutable( |
| 3784 | SavedForceCaptureByReferenceInTargetExecutable); |
| 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3789 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 3790 | ArrayRef<OMPClause *> Clauses) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3791 | bool ErrorFound = false; |
| 3792 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 3793 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3794 | if (!S.isUsable()) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3795 | ErrorFound = true; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3796 | return StmtError(); |
| 3797 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3798 | |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3799 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 3800 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3801 | OMPOrderedClause *OC = nullptr; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3802 | OMPScheduleClause *SC = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3803 | SmallVector<const OMPLinearClause *, 4> LCs; |
| 3804 | SmallVector<const OMPClauseWithPreInit *, 4> PICs; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 3805 | // This is required for proper codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3806 | for (OMPClause *Clause : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3807 | if (isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) && |
| 3808 | Clause->getClauseKind() == OMPC_in_reduction) { |
| 3809 | // Capture taskgroup task_reduction descriptors inside the tasking regions |
| 3810 | // with the corresponding in_reduction items. |
| 3811 | auto *IRC = cast<OMPInReductionClause>(Clause); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3812 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3813 | if (E) |
| 3814 | MarkDeclarationsReferencedInExpr(E); |
| 3815 | } |
| Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 3816 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 3817 | Clause->getClauseKind() == OMPC_copyprivate || |
| 3818 | (getLangOpts().OpenMPUseTLS && |
| 3819 | getASTContext().getTargetInfo().isTLSSupported() && |
| 3820 | Clause->getClauseKind() == OMPC_copyin)) { |
| 3821 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 3822 | // Mark all variables in private list clauses as used in inner region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3823 | for (Stmt *VarRef : Clause->children()) { |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3824 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 3825 | MarkDeclarationsReferencedInExpr(E); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3826 | } |
| 3827 | } |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 3828 | DSAStack->setForceVarCapturing(/*V=*/false); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3829 | } else if (CaptureRegions.size() > 1 || |
| 3830 | CaptureRegions.back() != OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3831 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 3832 | PICs.push_back(C); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 3833 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3834 | if (Expr *E = C->getPostUpdateExpr()) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 3835 | MarkDeclarationsReferencedInExpr(E); |
| 3836 | } |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3837 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3838 | if (Clause->getClauseKind() == OMPC_schedule) |
| 3839 | SC = cast<OMPScheduleClause>(Clause); |
| 3840 | else if (Clause->getClauseKind() == OMPC_ordered) |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3841 | OC = cast<OMPOrderedClause>(Clause); |
| 3842 | else if (Clause->getClauseKind() == OMPC_linear) |
| 3843 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 3844 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3845 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 3846 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 3847 | // specified. |
| 3848 | if (SC && |
| 3849 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 3850 | SC->getSecondScheduleModifier() == |
| 3851 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 3852 | OC) { |
| 3853 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 3854 | ? SC->getFirstScheduleModifierLoc() |
| 3855 | : SC->getSecondScheduleModifierLoc(), |
| 3856 | diag::err_omp_schedule_nonmonotonic_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3857 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3858 | ErrorFound = true; |
| 3859 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3860 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3861 | for (const OMPLinearClause *C : LCs) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3862 | Diag(C->getBeginLoc(), diag::err_omp_linear_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3863 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3864 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3865 | ErrorFound = true; |
| 3866 | } |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 3867 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 3868 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 3869 | OC->getNumForLoops()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3870 | Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd) |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 3871 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 3872 | ErrorFound = true; |
| 3873 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3874 | if (ErrorFound) { |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3875 | return StmtError(); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3876 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3877 | StmtResult SR = S; |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 3878 | unsigned CompletedRegions = 0; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3879 | for (OpenMPDirectiveKind ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3880 | // Mark all variables in private list clauses as used in inner region. |
| 3881 | // Required for proper codegen of combined directives. |
| 3882 | // TODO: add processing for other clauses. |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3883 | if (ThisCaptureRegion != OMPD_unknown) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3884 | for (const clang::OMPClauseWithPreInit *C : PICs) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3885 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 3886 | // Find the particular capture region for the clause if the |
| 3887 | // directive is a combined one with multiple capture regions. |
| 3888 | // If the directive is not a combined one, the capture region |
| 3889 | // associated with the clause is OMPD_unknown and is generated |
| 3890 | // only once. |
| 3891 | if (CaptureRegion == ThisCaptureRegion || |
| 3892 | CaptureRegion == OMPD_unknown) { |
| 3893 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3894 | for (Decl *D : DS->decls()) |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3895 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | } |
| Richard Smith | 0621a8f | 2019-05-31 00:45:10 +0000 | [diff] [blame] | 3900 | if (++CompletedRegions == CaptureRegions.size()) |
| 3901 | DSAStack->setBodyComplete(); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3902 | SR = ActOnCapturedRegionEnd(SR.get()); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3903 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3904 | return SR; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 3907 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 3908 | OpenMPDirectiveKind CancelRegion, |
| 3909 | SourceLocation StartLoc) { |
| 3910 | // CancelRegion is only needed for cancel and cancellation_point. |
| 3911 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 3912 | return false; |
| 3913 | |
| 3914 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 3915 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 3916 | return false; |
| 3917 | |
| 3918 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 3919 | << getOpenMPDirectiveName(CancelRegion); |
| 3920 | return true; |
| 3921 | } |
| 3922 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3923 | static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3924 | OpenMPDirectiveKind CurrentRegion, |
| 3925 | const DeclarationNameInfo &CurrentName, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3926 | OpenMPDirectiveKind CancelRegion, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3927 | SourceLocation StartLoc) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3928 | if (Stack->getCurScope()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3929 | OpenMPDirectiveKind ParentRegion = Stack->getParentDirective(); |
| 3930 | OpenMPDirectiveKind OffendingRegion = ParentRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3931 | bool NestingProhibited = false; |
| 3932 | bool CloseNesting = true; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3933 | bool OrphanSeen = false; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3934 | enum { |
| 3935 | NoRecommend, |
| 3936 | ShouldBeInParallelRegion, |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3937 | ShouldBeInOrderedRegion, |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3938 | ShouldBeInTargetRegion, |
| 3939 | ShouldBeInTeamsRegion |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3940 | } Recommend = NoRecommend; |
| Alexey Bataev | f8c12ed | 2019-11-11 13:44:42 -0500 | [diff] [blame] | 3941 | if (isOpenMPSimdDirective(ParentRegion) && |
| 3942 | ((SemaRef.LangOpts.OpenMP <= 45 && CurrentRegion != OMPD_ordered) || |
| 3943 | (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion != OMPD_ordered && |
| 3944 | CurrentRegion != OMPD_simd && CurrentRegion != OMPD_atomic))) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3945 | // OpenMP [2.16, Nesting of Regions] |
| 3946 | // OpenMP constructs may not be nested inside a simd region. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3947 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3948 | // An ordered construct with the simd clause is the only OpenMP |
| 3949 | // construct that can appear in the simd region. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3950 | // Allowing a SIMD construct nested in another SIMD construct is an |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3951 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 3952 | // message. |
| Alexey Bataev | f8c12ed | 2019-11-11 13:44:42 -0500 | [diff] [blame] | 3953 | // OpenMP 5.0 [2.9.3.1, simd Construct, Restrictions] |
| 3954 | // The only OpenMP constructs that can be encountered during execution of |
| 3955 | // a simd region are the atomic construct, the loop construct, the simd |
| 3956 | // construct and the ordered construct with the simd clause. |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3957 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 3958 | ? diag::err_omp_prohibited_region_simd |
| Alexey Bataev | f8c12ed | 2019-11-11 13:44:42 -0500 | [diff] [blame] | 3959 | : diag::warn_omp_nesting_simd) |
| 3960 | << (SemaRef.LangOpts.OpenMP >= 50 ? 1 : 0); |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3961 | return CurrentRegion != OMPD_simd; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3962 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3963 | if (ParentRegion == OMPD_atomic) { |
| 3964 | // OpenMP [2.16, Nesting of Regions] |
| 3965 | // OpenMP constructs may not be nested inside an atomic region. |
| 3966 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 3967 | return true; |
| 3968 | } |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3969 | if (CurrentRegion == OMPD_section) { |
| 3970 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 3971 | // Orphaned section directives are prohibited. That is, the section |
| 3972 | // directives must appear within the sections construct and must not be |
| 3973 | // encountered elsewhere in the sections region. |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3974 | if (ParentRegion != OMPD_sections && |
| 3975 | ParentRegion != OMPD_parallel_sections) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3976 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 3977 | << (ParentRegion != OMPD_unknown) |
| 3978 | << getOpenMPDirectiveName(ParentRegion); |
| 3979 | return true; |
| 3980 | } |
| 3981 | return false; |
| 3982 | } |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 3983 | // Allow some constructs (except teams and cancellation constructs) to be |
| 3984 | // orphaned (they could be used in functions, called from OpenMP regions |
| 3985 | // with the required preconditions). |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3986 | if (ParentRegion == OMPD_unknown && |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 3987 | !isOpenMPNestingTeamsDirective(CurrentRegion) && |
| 3988 | CurrentRegion != OMPD_cancellation_point && |
| 3989 | CurrentRegion != OMPD_cancel) |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3990 | return false; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3991 | if (CurrentRegion == OMPD_cancellation_point || |
| 3992 | CurrentRegion == OMPD_cancel) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3993 | // OpenMP [2.16, Nesting of Regions] |
| 3994 | // A cancellation point construct for which construct-type-clause is |
| 3995 | // taskgroup must be nested inside a task construct. A cancellation |
| 3996 | // point construct for which construct-type-clause is not taskgroup must |
| 3997 | // be closely nested inside an OpenMP construct that matches the type |
| 3998 | // specified in construct-type-clause. |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3999 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 4000 | // nested inside a task construct. A cancel construct for which |
| 4001 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 4002 | // OpenMP construct that matches the type specified in |
| 4003 | // construct-type-clause. |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4004 | NestingProhibited = |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 4005 | !((CancelRegion == OMPD_parallel && |
| 4006 | (ParentRegion == OMPD_parallel || |
| 4007 | ParentRegion == OMPD_target_parallel)) || |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4008 | (CancelRegion == OMPD_for && |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 4009 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 4010 | ParentRegion == OMPD_target_parallel_for || |
| 4011 | ParentRegion == OMPD_distribute_parallel_for || |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 4012 | ParentRegion == OMPD_teams_distribute_parallel_for || |
| 4013 | ParentRegion == OMPD_target_teams_distribute_parallel_for)) || |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4014 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 4015 | (CancelRegion == OMPD_sections && |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4016 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 4017 | ParentRegion == OMPD_parallel_sections))); |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 4018 | OrphanSeen = ParentRegion == OMPD_unknown; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4019 | } else if (CurrentRegion == OMPD_master) { |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4020 | // OpenMP [2.16, Nesting of Regions] |
| 4021 | // A master region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4022 | // atomic, or explicit task region. |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4023 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 4024 | isOpenMPTaskingDirective(ParentRegion); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4025 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 4026 | // OpenMP [2.16, Nesting of Regions] |
| 4027 | // A critical region may not be nested (closely or otherwise) inside a |
| 4028 | // critical region with the same name. Note that this restriction is not |
| 4029 | // sufficient to prevent deadlock. |
| 4030 | SourceLocation PreviousCriticalLoc; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4031 | bool DeadLock = Stack->hasDirective( |
| 4032 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 4033 | const DeclarationNameInfo &DNI, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4034 | SourceLocation Loc) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4035 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 4036 | PreviousCriticalLoc = Loc; |
| 4037 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4038 | } |
| 4039 | return false; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4040 | }, |
| 4041 | false /* skip top directive */); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4042 | if (DeadLock) { |
| 4043 | SemaRef.Diag(StartLoc, |
| 4044 | diag::err_omp_prohibited_region_critical_same_name) |
| 4045 | << CurrentName.getName(); |
| 4046 | if (PreviousCriticalLoc.isValid()) |
| 4047 | SemaRef.Diag(PreviousCriticalLoc, |
| 4048 | diag::note_omp_previous_critical_region); |
| 4049 | return true; |
| 4050 | } |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4051 | } else if (CurrentRegion == OMPD_barrier) { |
| 4052 | // OpenMP [2.16, Nesting of Regions] |
| 4053 | // A barrier region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4054 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 4055 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 4056 | isOpenMPTaskingDirective(ParentRegion) || |
| 4057 | ParentRegion == OMPD_master || |
| 4058 | ParentRegion == OMPD_critical || |
| 4059 | ParentRegion == OMPD_ordered; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4060 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 4061 | !isOpenMPParallelDirective(CurrentRegion) && |
| 4062 | !isOpenMPTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4063 | // OpenMP [2.16, Nesting of Regions] |
| 4064 | // A worksharing region may not be closely nested inside a worksharing, |
| 4065 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 4066 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 4067 | isOpenMPTaskingDirective(ParentRegion) || |
| 4068 | ParentRegion == OMPD_master || |
| 4069 | ParentRegion == OMPD_critical || |
| 4070 | ParentRegion == OMPD_ordered; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4071 | Recommend = ShouldBeInParallelRegion; |
| 4072 | } else if (CurrentRegion == OMPD_ordered) { |
| 4073 | // OpenMP [2.16, Nesting of Regions] |
| 4074 | // An ordered region may not be closely nested inside a critical, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4075 | // atomic, or explicit task region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4076 | // An ordered region must be closely nested inside a loop region (or |
| 4077 | // parallel loop region) with an ordered clause. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4078 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4079 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4080 | // that can appear in the simd region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4081 | NestingProhibited = ParentRegion == OMPD_critical || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 4082 | isOpenMPTaskingDirective(ParentRegion) || |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4083 | !(isOpenMPSimdDirective(ParentRegion) || |
| 4084 | Stack->isParentOrderedRegion()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4085 | Recommend = ShouldBeInOrderedRegion; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 4086 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4087 | // OpenMP [2.16, Nesting of Regions] |
| 4088 | // If specified, a teams construct must be contained within a target |
| 4089 | // construct. |
| Alexey Bataev | 7a54d76 | 2019-09-10 20:19:58 +0000 | [diff] [blame] | 4090 | NestingProhibited = |
| 4091 | (SemaRef.LangOpts.OpenMP <= 45 && ParentRegion != OMPD_target) || |
| 4092 | (SemaRef.LangOpts.OpenMP >= 50 && ParentRegion != OMPD_unknown && |
| 4093 | ParentRegion != OMPD_target); |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 4094 | OrphanSeen = ParentRegion == OMPD_unknown; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4095 | Recommend = ShouldBeInTargetRegion; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4096 | } |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 4097 | if (!NestingProhibited && |
| 4098 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 4099 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 4100 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4101 | // OpenMP [2.16, Nesting of Regions] |
| 4102 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 4103 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 4104 | // constructs that can be closely nested in the teams region. |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4105 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 4106 | !isOpenMPDistributeDirective(CurrentRegion); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4107 | Recommend = ShouldBeInParallelRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4108 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4109 | if (!NestingProhibited && |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 4110 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4111 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 4112 | // The region associated with the distribute construct must be strictly |
| 4113 | // nested inside a teams region |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 4114 | NestingProhibited = |
| 4115 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4116 | Recommend = ShouldBeInTeamsRegion; |
| 4117 | } |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 4118 | if (!NestingProhibited && |
| 4119 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 4120 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 4121 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 4122 | // If a target, target update, target data, target enter data, or |
| 4123 | // target exit data construct is encountered during execution of a |
| 4124 | // target region, the behavior is unspecified. |
| 4125 | NestingProhibited = Stack->hasDirective( |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 4126 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4127 | SourceLocation) { |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 4128 | if (isOpenMPTargetExecutionDirective(K)) { |
| 4129 | OffendingRegion = K; |
| 4130 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4131 | } |
| 4132 | return false; |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 4133 | }, |
| 4134 | false /* don't skip top directive */); |
| 4135 | CloseNesting = false; |
| 4136 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4137 | if (NestingProhibited) { |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 4138 | if (OrphanSeen) { |
| 4139 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 4140 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 4141 | } else { |
| 4142 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 4143 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 4144 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 4145 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4146 | return true; |
| 4147 | } |
| 4148 | } |
| 4149 | return false; |
| 4150 | } |
| 4151 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4152 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 4153 | ArrayRef<OMPClause *> Clauses, |
| 4154 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 4155 | bool ErrorFound = false; |
| 4156 | unsigned NamedModifiersNumber = 0; |
| 4157 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 4158 | OMPD_unknown + 1); |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 4159 | SmallVector<SourceLocation, 4> NameModifierLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4160 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4161 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 4162 | // At most one if clause without a directive-name-modifier can appear on |
| 4163 | // the directive. |
| 4164 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 4165 | if (FoundNameModifiers[CurNM]) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4166 | S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4167 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 4168 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 4169 | ErrorFound = true; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 4170 | } else if (CurNM != OMPD_unknown) { |
| 4171 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4172 | ++NamedModifiersNumber; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 4173 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4174 | FoundNameModifiers[CurNM] = IC; |
| 4175 | if (CurNM == OMPD_unknown) |
| 4176 | continue; |
| 4177 | // Check if the specified name modifier is allowed for the current |
| 4178 | // directive. |
| 4179 | // At most one if clause with the particular directive-name-modifier can |
| 4180 | // appear on the directive. |
| 4181 | bool MatchFound = false; |
| 4182 | for (auto NM : AllowedNameModifiers) { |
| 4183 | if (CurNM == NM) { |
| 4184 | MatchFound = true; |
| 4185 | break; |
| 4186 | } |
| 4187 | } |
| 4188 | if (!MatchFound) { |
| 4189 | S.Diag(IC->getNameModifierLoc(), |
| 4190 | diag::err_omp_wrong_if_directive_name_modifier) |
| 4191 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 4192 | ErrorFound = true; |
| 4193 | } |
| 4194 | } |
| 4195 | } |
| 4196 | // If any if clause on the directive includes a directive-name-modifier then |
| 4197 | // all if clauses on the directive must include a directive-name-modifier. |
| 4198 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 4199 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4200 | S.Diag(FoundNameModifiers[OMPD_unknown]->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4201 | diag::err_omp_no_more_if_clause); |
| 4202 | } else { |
| 4203 | std::string Values; |
| 4204 | std::string Sep(", "); |
| 4205 | unsigned AllowedCnt = 0; |
| 4206 | unsigned TotalAllowedNum = |
| 4207 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 4208 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 4209 | ++Cnt) { |
| 4210 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 4211 | if (!FoundNameModifiers[NM]) { |
| 4212 | Values += "'"; |
| 4213 | Values += getOpenMPDirectiveName(NM); |
| 4214 | Values += "'"; |
| 4215 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 4216 | Values += " or "; |
| 4217 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 4218 | Values += Sep; |
| 4219 | ++AllowedCnt; |
| 4220 | } |
| 4221 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4222 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4223 | diag::err_omp_unnamed_if_clause) |
| 4224 | << (TotalAllowedNum > 1) << Values; |
| 4225 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4226 | for (SourceLocation Loc : NameModifierLoc) { |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 4227 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 4228 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4229 | ErrorFound = true; |
| 4230 | } |
| 4231 | return ErrorFound; |
| 4232 | } |
| 4233 | |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 4234 | static std::pair<ValueDecl *, bool> |
| 4235 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 4236 | SourceRange &ERange, bool AllowArraySection = false) { |
| 4237 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 4238 | RefExpr->containsUnexpandedParameterPack()) |
| 4239 | return std::make_pair(nullptr, true); |
| 4240 | |
| 4241 | // OpenMP [3.1, C/C++] |
| 4242 | // A list item is a variable name. |
| 4243 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4244 | // A variable that is part of another variable (as an array or |
| 4245 | // structure element) cannot appear in a private clause. |
| 4246 | RefExpr = RefExpr->IgnoreParens(); |
| 4247 | enum { |
| 4248 | NoArrayExpr = -1, |
| 4249 | ArraySubscript = 0, |
| 4250 | OMPArraySection = 1 |
| 4251 | } IsArrayExpr = NoArrayExpr; |
| 4252 | if (AllowArraySection) { |
| 4253 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 4254 | Expr *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 4255 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 4256 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 4257 | RefExpr = Base; |
| 4258 | IsArrayExpr = ArraySubscript; |
| 4259 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 4260 | Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 4261 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 4262 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 4263 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 4264 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 4265 | RefExpr = Base; |
| 4266 | IsArrayExpr = OMPArraySection; |
| 4267 | } |
| 4268 | } |
| 4269 | ELoc = RefExpr->getExprLoc(); |
| 4270 | ERange = RefExpr->getSourceRange(); |
| 4271 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
| 4272 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 4273 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 4274 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 4275 | (S.getCurrentThisType().isNull() || !ME || |
| 4276 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 4277 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 4278 | if (IsArrayExpr != NoArrayExpr) { |
| 4279 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 4280 | << ERange; |
| 4281 | } else { |
| 4282 | S.Diag(ELoc, |
| 4283 | AllowArraySection |
| 4284 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 4285 | : diag::err_omp_expected_var_name_member_expr) |
| 4286 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 4287 | } |
| 4288 | return std::make_pair(nullptr, false); |
| 4289 | } |
| 4290 | return std::make_pair( |
| 4291 | getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false); |
| 4292 | } |
| 4293 | |
| 4294 | static void checkAllocateClauses(Sema &S, DSAStackTy *Stack, |
| Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 4295 | ArrayRef<OMPClause *> Clauses) { |
| 4296 | assert(!S.CurContext->isDependentContext() && |
| 4297 | "Expected non-dependent context."); |
| Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 4298 | auto AllocateRange = |
| 4299 | llvm::make_filter_range(Clauses, OMPAllocateClause::classof); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 4300 | llvm::DenseMap<CanonicalDeclPtr<Decl>, CanonicalDeclPtr<VarDecl>> |
| 4301 | DeclToCopy; |
| 4302 | auto PrivateRange = llvm::make_filter_range(Clauses, [](const OMPClause *C) { |
| 4303 | return isOpenMPPrivate(C->getClauseKind()); |
| 4304 | }); |
| 4305 | for (OMPClause *Cl : PrivateRange) { |
| 4306 | MutableArrayRef<Expr *>::iterator I, It, Et; |
| 4307 | if (Cl->getClauseKind() == OMPC_private) { |
| 4308 | auto *PC = cast<OMPPrivateClause>(Cl); |
| 4309 | I = PC->private_copies().begin(); |
| 4310 | It = PC->varlist_begin(); |
| 4311 | Et = PC->varlist_end(); |
| 4312 | } else if (Cl->getClauseKind() == OMPC_firstprivate) { |
| 4313 | auto *PC = cast<OMPFirstprivateClause>(Cl); |
| 4314 | I = PC->private_copies().begin(); |
| 4315 | It = PC->varlist_begin(); |
| 4316 | Et = PC->varlist_end(); |
| 4317 | } else if (Cl->getClauseKind() == OMPC_lastprivate) { |
| 4318 | auto *PC = cast<OMPLastprivateClause>(Cl); |
| 4319 | I = PC->private_copies().begin(); |
| 4320 | It = PC->varlist_begin(); |
| 4321 | Et = PC->varlist_end(); |
| 4322 | } else if (Cl->getClauseKind() == OMPC_linear) { |
| 4323 | auto *PC = cast<OMPLinearClause>(Cl); |
| 4324 | I = PC->privates().begin(); |
| 4325 | It = PC->varlist_begin(); |
| 4326 | Et = PC->varlist_end(); |
| 4327 | } else if (Cl->getClauseKind() == OMPC_reduction) { |
| 4328 | auto *PC = cast<OMPReductionClause>(Cl); |
| 4329 | I = PC->privates().begin(); |
| 4330 | It = PC->varlist_begin(); |
| 4331 | Et = PC->varlist_end(); |
| 4332 | } else if (Cl->getClauseKind() == OMPC_task_reduction) { |
| 4333 | auto *PC = cast<OMPTaskReductionClause>(Cl); |
| 4334 | I = PC->privates().begin(); |
| 4335 | It = PC->varlist_begin(); |
| 4336 | Et = PC->varlist_end(); |
| 4337 | } else if (Cl->getClauseKind() == OMPC_in_reduction) { |
| 4338 | auto *PC = cast<OMPInReductionClause>(Cl); |
| 4339 | I = PC->privates().begin(); |
| 4340 | It = PC->varlist_begin(); |
| 4341 | Et = PC->varlist_end(); |
| 4342 | } else { |
| 4343 | llvm_unreachable("Expected private clause."); |
| 4344 | } |
| 4345 | for (Expr *E : llvm::make_range(It, Et)) { |
| 4346 | if (!*I) { |
| 4347 | ++I; |
| 4348 | continue; |
| 4349 | } |
| 4350 | SourceLocation ELoc; |
| 4351 | SourceRange ERange; |
| 4352 | Expr *SimpleRefExpr = E; |
| 4353 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
| 4354 | /*AllowArraySection=*/true); |
| 4355 | DeclToCopy.try_emplace(Res.first, |
| 4356 | cast<VarDecl>(cast<DeclRefExpr>(*I)->getDecl())); |
| 4357 | ++I; |
| 4358 | } |
| 4359 | } |
| Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 4360 | for (OMPClause *C : AllocateRange) { |
| 4361 | auto *AC = cast<OMPAllocateClause>(C); |
| 4362 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind = |
| 4363 | getAllocatorKind(S, Stack, AC->getAllocator()); |
| 4364 | // OpenMP, 2.11.4 allocate Clause, Restrictions. |
| 4365 | // For task, taskloop or target directives, allocation requests to memory |
| 4366 | // allocators with the trait access set to thread result in unspecified |
| 4367 | // behavior. |
| 4368 | if (AllocatorKind == OMPAllocateDeclAttr::OMPThreadMemAlloc && |
| 4369 | (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
| 4370 | isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()))) { |
| 4371 | S.Diag(AC->getAllocator()->getExprLoc(), |
| 4372 | diag::warn_omp_allocate_thread_on_task_target_directive) |
| 4373 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| Alexey Bataev | e106f25 | 2019-04-01 14:25:31 +0000 | [diff] [blame] | 4374 | } |
| 4375 | for (Expr *E : AC->varlists()) { |
| 4376 | SourceLocation ELoc; |
| 4377 | SourceRange ERange; |
| 4378 | Expr *SimpleRefExpr = E; |
| 4379 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange); |
| 4380 | ValueDecl *VD = Res.first; |
| 4381 | DSAStackTy::DSAVarData Data = Stack->getTopDSA(VD, /*FromParent=*/false); |
| 4382 | if (!isOpenMPPrivate(Data.CKind)) { |
| 4383 | S.Diag(E->getExprLoc(), |
| 4384 | diag::err_omp_expected_private_copy_for_allocate); |
| 4385 | continue; |
| 4386 | } |
| 4387 | VarDecl *PrivateVD = DeclToCopy[VD]; |
| 4388 | if (checkPreviousOMPAllocateAttribute(S, Stack, E, PrivateVD, |
| 4389 | AllocatorKind, AC->getAllocator())) |
| 4390 | continue; |
| 4391 | applyOMPAllocateAttribute(S, PrivateVD, AllocatorKind, AC->getAllocator(), |
| 4392 | E->getSourceRange()); |
| Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 4393 | } |
| 4394 | } |
| Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4397 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 4398 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 4399 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 4400 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4401 | StmtResult Res = StmtError(); |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 4402 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 4403 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 4404 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4405 | StartLoc)) |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4406 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4407 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4408 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4409 | VarsWithInheritedDSAType VarsWithInheritedDSA; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4410 | bool ErrorFound = false; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4411 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 4412 | if (AStmt && !CurContext->isDependentContext()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4413 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4414 | |
| 4415 | // Check default data sharing attributes for referenced variables. |
| 4416 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 4417 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 4418 | Stmt *S = AStmt; |
| 4419 | while (--ThisCaptureLevel >= 0) |
| 4420 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 4421 | DSAChecker.Visit(S); |
| Alexey Bataev | 1242d8f | 2019-06-28 20:45:14 +0000 | [diff] [blame] | 4422 | if (!isOpenMPTargetDataManagementDirective(Kind) && |
| 4423 | !isOpenMPTaskingDirective(Kind)) { |
| 4424 | // Visit subcaptures to generate implicit clauses for captured vars. |
| 4425 | auto *CS = cast<CapturedStmt>(AStmt); |
| 4426 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 4427 | getOpenMPCaptureRegions(CaptureRegions, Kind); |
| 4428 | // Ignore outer tasking regions for target directives. |
| 4429 | if (CaptureRegions.size() > 1 && CaptureRegions.front() == OMPD_task) |
| 4430 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 4431 | DSAChecker.visitSubCaptures(CS); |
| 4432 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4433 | if (DSAChecker.isErrorFound()) |
| 4434 | return StmtError(); |
| 4435 | // Generate list of implicitly defined firstprivate variables. |
| 4436 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4437 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4438 | SmallVector<Expr *, 4> ImplicitFirstprivates( |
| 4439 | DSAChecker.getImplicitFirstprivate().begin(), |
| 4440 | DSAChecker.getImplicitFirstprivate().end()); |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4441 | SmallVector<Expr *, 4> ImplicitMaps[OMPC_MAP_delete]; |
| 4442 | for (unsigned I = 0; I < OMPC_MAP_delete; ++I) { |
| 4443 | ArrayRef<Expr *> ImplicitMap = |
| 4444 | DSAChecker.getImplicitMap(static_cast<OpenMPDefaultmapClauseKind>(I)); |
| 4445 | ImplicitMaps[I].append(ImplicitMap.begin(), ImplicitMap.end()); |
| 4446 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4447 | // Mark taskgroup task_reduction descriptors as implicitly firstprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4448 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4449 | if (auto *IRC = dyn_cast<OMPInReductionClause>(C)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4450 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4451 | if (E) |
| 4452 | ImplicitFirstprivates.emplace_back(E); |
| 4453 | } |
| 4454 | } |
| 4455 | if (!ImplicitFirstprivates.empty()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4456 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4457 | ImplicitFirstprivates, SourceLocation(), SourceLocation(), |
| 4458 | SourceLocation())) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4459 | ClausesWithImplicit.push_back(Implicit); |
| 4460 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 4461 | ImplicitFirstprivates.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4462 | } else { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4463 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4464 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4465 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4466 | int ClauseKindCnt = -1; |
| 4467 | for (ArrayRef<Expr *> ImplicitMap : ImplicitMaps) { |
| 4468 | ++ClauseKindCnt; |
| 4469 | if (ImplicitMap.empty()) |
| 4470 | continue; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 4471 | CXXScopeSpec MapperIdScopeSpec; |
| 4472 | DeclarationNameInfo MapperId; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4473 | auto Kind = static_cast<OpenMPMapClauseKind>(ClauseKindCnt); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 4474 | if (OMPClause *Implicit = ActOnOpenMPMapClause( |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4475 | llvm::None, llvm::None, MapperIdScopeSpec, MapperId, Kind, |
| 4476 | /*IsMapTypeImplicit=*/true, SourceLocation(), SourceLocation(), |
| 4477 | ImplicitMap, OMPVarListLocTy())) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 4478 | ClausesWithImplicit.emplace_back(Implicit); |
| 4479 | ErrorFound |= |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4480 | cast<OMPMapClause>(Implicit)->varlist_size() != ImplicitMap.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4481 | } else { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 4482 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4483 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 4484 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4485 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4486 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4487 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4488 | switch (Kind) { |
| 4489 | case OMPD_parallel: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4490 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4491 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4492 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4493 | break; |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4494 | case OMPD_simd: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4495 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 4496 | VarsWithInheritedDSA); |
| Alexey Bataev | d08c056 | 2019-11-19 12:07:54 -0500 | [diff] [blame] | 4497 | if (LangOpts.OpenMP >= 50) |
| 4498 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4499 | break; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4500 | case OMPD_for: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4501 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 4502 | VarsWithInheritedDSA); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4503 | break; |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4504 | case OMPD_for_simd: |
| 4505 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4506 | EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 103f3c9e | 2019-11-20 15:59:03 -0500 | [diff] [blame] | 4507 | if (LangOpts.OpenMP >= 50) |
| 4508 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4509 | break; |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4510 | case OMPD_sections: |
| 4511 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4512 | EndLoc); |
| 4513 | break; |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4514 | case OMPD_section: |
| 4515 | assert(ClausesWithImplicit.empty() && |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4516 | "No clauses are allowed for 'omp section' directive"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4517 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 4518 | break; |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4519 | case OMPD_single: |
| 4520 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4521 | EndLoc); |
| 4522 | break; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4523 | case OMPD_master: |
| 4524 | assert(ClausesWithImplicit.empty() && |
| 4525 | "No clauses are allowed for 'omp master' directive"); |
| 4526 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 4527 | break; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4528 | case OMPD_critical: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4529 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 4530 | StartLoc, EndLoc); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4531 | break; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4532 | case OMPD_parallel_for: |
| 4533 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4534 | EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4535 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4536 | break; |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4537 | case OMPD_parallel_for_simd: |
| 4538 | Res = ActOnOpenMPParallelForSimdDirective( |
| 4539 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4540 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | f59614d | 2019-11-21 10:00:56 -0500 | [diff] [blame] | 4541 | if (LangOpts.OpenMP >= 50) |
| 4542 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4543 | break; |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4544 | case OMPD_parallel_sections: |
| 4545 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 4546 | StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4547 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4548 | break; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4549 | case OMPD_task: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4550 | Res = |
| 4551 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4552 | AllowedNameModifiers.push_back(OMPD_task); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4553 | break; |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4554 | case OMPD_taskyield: |
| 4555 | assert(ClausesWithImplicit.empty() && |
| 4556 | "No clauses are allowed for 'omp taskyield' directive"); |
| 4557 | assert(AStmt == nullptr && |
| 4558 | "No associated statement allowed for 'omp taskyield' directive"); |
| 4559 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 4560 | break; |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4561 | case OMPD_barrier: |
| 4562 | assert(ClausesWithImplicit.empty() && |
| 4563 | "No clauses are allowed for 'omp barrier' directive"); |
| 4564 | assert(AStmt == nullptr && |
| 4565 | "No associated statement allowed for 'omp barrier' directive"); |
| 4566 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 4567 | break; |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4568 | case OMPD_taskwait: |
| 4569 | assert(ClausesWithImplicit.empty() && |
| 4570 | "No clauses are allowed for 'omp taskwait' directive"); |
| 4571 | assert(AStmt == nullptr && |
| 4572 | "No associated statement allowed for 'omp taskwait' directive"); |
| 4573 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 4574 | break; |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4575 | case OMPD_taskgroup: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 4576 | Res = ActOnOpenMPTaskgroupDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4577 | EndLoc); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4578 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4579 | case OMPD_flush: |
| 4580 | assert(AStmt == nullptr && |
| 4581 | "No associated statement allowed for 'omp flush' directive"); |
| 4582 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 4583 | break; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4584 | case OMPD_ordered: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4585 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4586 | EndLoc); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4587 | break; |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4588 | case OMPD_atomic: |
| 4589 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4590 | EndLoc); |
| 4591 | break; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4592 | case OMPD_teams: |
| 4593 | Res = |
| 4594 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 4595 | break; |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4596 | case OMPD_target: |
| 4597 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4598 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4599 | AllowedNameModifiers.push_back(OMPD_target); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4600 | break; |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 4601 | case OMPD_target_parallel: |
| 4602 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 4603 | StartLoc, EndLoc); |
| 4604 | AllowedNameModifiers.push_back(OMPD_target); |
| 4605 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4606 | break; |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 4607 | case OMPD_target_parallel_for: |
| 4608 | Res = ActOnOpenMPTargetParallelForDirective( |
| 4609 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4610 | AllowedNameModifiers.push_back(OMPD_target); |
| 4611 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4612 | break; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4613 | case OMPD_cancellation_point: |
| 4614 | assert(ClausesWithImplicit.empty() && |
| 4615 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 4616 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 4617 | "cancellation point' directive"); |
| 4618 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 4619 | break; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4620 | case OMPD_cancel: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4621 | assert(AStmt == nullptr && |
| 4622 | "No associated statement allowed for 'omp cancel' directive"); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 4623 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 4624 | CancelRegion); |
| 4625 | AllowedNameModifiers.push_back(OMPD_cancel); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4626 | break; |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4627 | case OMPD_target_data: |
| 4628 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4629 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4630 | AllowedNameModifiers.push_back(OMPD_target_data); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4631 | break; |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 4632 | case OMPD_target_enter_data: |
| 4633 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 4634 | EndLoc, AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 4635 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 4636 | break; |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 4637 | case OMPD_target_exit_data: |
| 4638 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 4639 | EndLoc, AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 4640 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 4641 | break; |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 4642 | case OMPD_taskloop: |
| 4643 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4644 | EndLoc, VarsWithInheritedDSA); |
| 4645 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 4646 | break; |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4647 | case OMPD_taskloop_simd: |
| 4648 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4649 | EndLoc, VarsWithInheritedDSA); |
| 4650 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 4651 | if (LangOpts.OpenMP >= 50) |
| 4652 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4653 | break; |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 4654 | case OMPD_master_taskloop: |
| 4655 | Res = ActOnOpenMPMasterTaskLoopDirective( |
| 4656 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4657 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 4658 | break; |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 4659 | case OMPD_master_taskloop_simd: |
| 4660 | Res = ActOnOpenMPMasterTaskLoopSimdDirective( |
| 4661 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4662 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| Alexey Bataev | 853961f | 2019-12-05 09:50:18 -0500 | [diff] [blame] | 4663 | if (LangOpts.OpenMP >= 50) |
| 4664 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 4665 | break; |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 4666 | case OMPD_parallel_master_taskloop: |
| 4667 | Res = ActOnOpenMPParallelMasterTaskLoopDirective( |
| 4668 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4669 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 4670 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4671 | break; |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 4672 | case OMPD_parallel_master_taskloop_simd: |
| 4673 | Res = ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
| 4674 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4675 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 4676 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 5c517a6 | 2019-12-05 11:31:45 -0500 | [diff] [blame] | 4677 | if (LangOpts.OpenMP >= 50) |
| 4678 | AllowedNameModifiers.push_back(OMPD_simd); |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 4679 | break; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4680 | case OMPD_distribute: |
| 4681 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4682 | EndLoc, VarsWithInheritedDSA); |
| 4683 | break; |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 4684 | case OMPD_target_update: |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 4685 | Res = ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, |
| 4686 | EndLoc, AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 4687 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 4688 | break; |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4689 | case OMPD_distribute_parallel_for: |
| 4690 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 4691 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4692 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4693 | break; |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 4694 | case OMPD_distribute_parallel_for_simd: |
| 4695 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 4696 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4697 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 52812f2 | 2019-12-05 13:22:15 -0500 | [diff] [blame] | 4698 | if (LangOpts.OpenMP >= 50) |
| 4699 | AllowedNameModifiers.push_back(OMPD_simd); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 4700 | break; |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 4701 | case OMPD_distribute_simd: |
| 4702 | Res = ActOnOpenMPDistributeSimdDirective( |
| 4703 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4704 | break; |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 4705 | case OMPD_target_parallel_for_simd: |
| 4706 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 4707 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4708 | AllowedNameModifiers.push_back(OMPD_target); |
| 4709 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4710 | break; |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 4711 | case OMPD_target_simd: |
| 4712 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4713 | EndLoc, VarsWithInheritedDSA); |
| 4714 | AllowedNameModifiers.push_back(OMPD_target); |
| 4715 | break; |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 4716 | case OMPD_teams_distribute: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4717 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 4718 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 4719 | break; |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 4720 | case OMPD_teams_distribute_simd: |
| 4721 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 4722 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4723 | break; |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 4724 | case OMPD_teams_distribute_parallel_for_simd: |
| 4725 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 4726 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4727 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4728 | break; |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 4729 | case OMPD_teams_distribute_parallel_for: |
| 4730 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 4731 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4732 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4733 | break; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 4734 | case OMPD_target_teams: |
| 4735 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 4736 | EndLoc); |
| 4737 | AllowedNameModifiers.push_back(OMPD_target); |
| 4738 | break; |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 4739 | case OMPD_target_teams_distribute: |
| 4740 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 4741 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4742 | AllowedNameModifiers.push_back(OMPD_target); |
| 4743 | break; |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 4744 | case OMPD_target_teams_distribute_parallel_for: |
| 4745 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 4746 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4747 | AllowedNameModifiers.push_back(OMPD_target); |
| 4748 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4749 | break; |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 4750 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 4751 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 4752 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4753 | AllowedNameModifiers.push_back(OMPD_target); |
| 4754 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 4755 | break; |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 4756 | case OMPD_target_teams_distribute_simd: |
| 4757 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 4758 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 4759 | AllowedNameModifiers.push_back(OMPD_target); |
| 4760 | break; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 4761 | case OMPD_declare_target: |
| 4762 | case OMPD_end_declare_target: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4763 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 4764 | case OMPD_allocate: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 4765 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 4766 | case OMPD_declare_mapper: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4767 | case OMPD_declare_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 4768 | case OMPD_requires: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 4769 | case OMPD_declare_variant: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4770 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 4771 | case OMPD_unknown: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4772 | llvm_unreachable("Unknown OpenMP directive"); |
| 4773 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4774 | |
| Roman Lebedev | b570060 | 2019-03-20 16:32:36 +0000 | [diff] [blame] | 4775 | ErrorFound = Res.isInvalid() || ErrorFound; |
| 4776 | |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4777 | // Check variables in the clauses if default(none) was specified. |
| 4778 | if (DSAStack->getDefaultDSA() == DSA_none) { |
| 4779 | DSAAttrChecker DSAChecker(DSAStack, *this, nullptr); |
| 4780 | for (OMPClause *C : Clauses) { |
| 4781 | switch (C->getClauseKind()) { |
| 4782 | case OMPC_num_threads: |
| 4783 | case OMPC_dist_schedule: |
| 4784 | // Do not analyse if no parent teams directive. |
| Alexey Bataev | 77d049d | 2019-11-21 11:03:26 -0500 | [diff] [blame] | 4785 | if (isOpenMPTeamsDirective(Kind)) |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4786 | break; |
| 4787 | continue; |
| 4788 | case OMPC_if: |
| Alexey Bataev | 77d049d | 2019-11-21 11:03:26 -0500 | [diff] [blame] | 4789 | if (isOpenMPTeamsDirective(Kind) && |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4790 | cast<OMPIfClause>(C)->getNameModifier() != OMPD_target) |
| 4791 | break; |
| Alexey Bataev | 77d049d | 2019-11-21 11:03:26 -0500 | [diff] [blame] | 4792 | if (isOpenMPParallelDirective(Kind) && |
| 4793 | isOpenMPTaskLoopDirective(Kind) && |
| 4794 | cast<OMPIfClause>(C)->getNameModifier() != OMPD_parallel) |
| 4795 | break; |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4796 | continue; |
| 4797 | case OMPC_schedule: |
| 4798 | break; |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 4799 | case OMPC_grainsize: |
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 4800 | case OMPC_num_tasks: |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 4801 | case OMPC_final: |
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 4802 | case OMPC_priority: |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 4803 | // Do not analyze if no parent parallel directive. |
| Alexey Bataev | 77d049d | 2019-11-21 11:03:26 -0500 | [diff] [blame] | 4804 | if (isOpenMPParallelDirective(Kind)) |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | continue; |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4807 | case OMPC_ordered: |
| 4808 | case OMPC_device: |
| 4809 | case OMPC_num_teams: |
| 4810 | case OMPC_thread_limit: |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4811 | case OMPC_hint: |
| 4812 | case OMPC_collapse: |
| 4813 | case OMPC_safelen: |
| 4814 | case OMPC_simdlen: |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4815 | case OMPC_default: |
| 4816 | case OMPC_proc_bind: |
| 4817 | case OMPC_private: |
| 4818 | case OMPC_firstprivate: |
| 4819 | case OMPC_lastprivate: |
| 4820 | case OMPC_shared: |
| 4821 | case OMPC_reduction: |
| 4822 | case OMPC_task_reduction: |
| 4823 | case OMPC_in_reduction: |
| 4824 | case OMPC_linear: |
| 4825 | case OMPC_aligned: |
| 4826 | case OMPC_copyin: |
| 4827 | case OMPC_copyprivate: |
| 4828 | case OMPC_nowait: |
| 4829 | case OMPC_untied: |
| 4830 | case OMPC_mergeable: |
| 4831 | case OMPC_allocate: |
| 4832 | case OMPC_read: |
| 4833 | case OMPC_write: |
| 4834 | case OMPC_update: |
| 4835 | case OMPC_capture: |
| 4836 | case OMPC_seq_cst: |
| 4837 | case OMPC_depend: |
| 4838 | case OMPC_threads: |
| 4839 | case OMPC_simd: |
| 4840 | case OMPC_map: |
| 4841 | case OMPC_nogroup: |
| 4842 | case OMPC_defaultmap: |
| 4843 | case OMPC_to: |
| 4844 | case OMPC_from: |
| 4845 | case OMPC_use_device_ptr: |
| 4846 | case OMPC_is_device_ptr: |
| 4847 | continue; |
| 4848 | case OMPC_allocator: |
| 4849 | case OMPC_flush: |
| 4850 | case OMPC_threadprivate: |
| 4851 | case OMPC_uniform: |
| 4852 | case OMPC_unknown: |
| 4853 | case OMPC_unified_address: |
| 4854 | case OMPC_unified_shared_memory: |
| 4855 | case OMPC_reverse_offload: |
| 4856 | case OMPC_dynamic_allocators: |
| 4857 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 4858 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 4859 | case OMPC_match: |
| Alexey Bataev | 412254a | 2019-05-09 18:44:53 +0000 | [diff] [blame] | 4860 | llvm_unreachable("Unexpected clause"); |
| 4861 | } |
| 4862 | for (Stmt *CC : C->children()) { |
| 4863 | if (CC) |
| 4864 | DSAChecker.Visit(CC); |
| 4865 | } |
| 4866 | } |
| 4867 | for (auto &P : DSAChecker.getVarsWithInheritedDSA()) |
| 4868 | VarsWithInheritedDSA[P.getFirst()] = P.getSecond(); |
| 4869 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4870 | for (const auto &P : VarsWithInheritedDSA) { |
| Alexey Bataev | 1242d8f | 2019-06-28 20:45:14 +0000 | [diff] [blame] | 4871 | if (P.getFirst()->isImplicit() || isa<OMPCapturedExprDecl>(P.getFirst())) |
| 4872 | continue; |
| 4873 | ErrorFound = true; |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 4874 | if (DSAStack->getDefaultDSA() == DSA_none) { |
| 4875 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 4876 | << P.first << P.second->getSourceRange(); |
| 4877 | Diag(DSAStack->getDefaultDSALocation(), diag::note_omp_default_dsa_none); |
| 4878 | } else if (getLangOpts().OpenMP >= 50) { |
| 4879 | Diag(P.second->getExprLoc(), |
| 4880 | diag::err_omp_defaultmap_no_attr_for_variable) |
| 4881 | << P.first << P.second->getSourceRange(); |
| 4882 | Diag(DSAStack->getDefaultDSALocation(), |
| 4883 | diag::note_omp_defaultmap_attr_none); |
| 4884 | } |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4885 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4886 | |
| 4887 | if (!AllowedNameModifiers.empty()) |
| 4888 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 4889 | ErrorFound; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4890 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4891 | if (ErrorFound) |
| 4892 | return StmtError(); |
| Roman Lebedev | b570060 | 2019-03-20 16:32:36 +0000 | [diff] [blame] | 4893 | |
| 4894 | if (!(Res.getAs<OMPExecutableDirective>()->isStandaloneDirective())) { |
| 4895 | Res.getAs<OMPExecutableDirective>() |
| 4896 | ->getStructuredBlock() |
| 4897 | ->setIsOMPStructuredBlock(true); |
| 4898 | } |
| 4899 | |
| Gheorghe-Teodor Bercea | 411a624 | 2019-04-18 19:53:43 +0000 | [diff] [blame] | 4900 | if (!CurContext->isDependentContext() && |
| 4901 | isOpenMPTargetExecutionDirective(Kind) && |
| 4902 | !(DSAStack->hasRequiresDeclWithClause<OMPUnifiedSharedMemoryClause>() || |
| 4903 | DSAStack->hasRequiresDeclWithClause<OMPUnifiedAddressClause>() || |
| 4904 | DSAStack->hasRequiresDeclWithClause<OMPReverseOffloadClause>() || |
| 4905 | DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>())) { |
| 4906 | // Register target to DSA Stack. |
| 4907 | DSAStack->addTargetDirLocation(StartLoc); |
| 4908 | } |
| 4909 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4910 | return Res; |
| 4911 | } |
| 4912 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4913 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 4914 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4915 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4916 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 4917 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4918 | assert(Aligneds.size() == Alignments.size()); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4919 | assert(Linears.size() == LinModifiers.size()); |
| 4920 | assert(Linears.size() == Steps.size()); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4921 | if (!DG || DG.get().isNull()) |
| 4922 | return DeclGroupPtrTy(); |
| 4923 | |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 4924 | const int SimdId = 0; |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4925 | if (!DG.get().isSingleDecl()) { |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 4926 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd_variant) |
| 4927 | << SimdId; |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4928 | return DG; |
| 4929 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4930 | Decl *ADecl = DG.get().getSingleDecl(); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4931 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 4932 | ADecl = FTD->getTemplatedDecl(); |
| 4933 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4934 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 4935 | if (!FD) { |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 4936 | Diag(ADecl->getLocation(), diag::err_omp_function_expected) << SimdId; |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4937 | return DeclGroupPtrTy(); |
| 4938 | } |
| 4939 | |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 4940 | // OpenMP [2.8.2, declare simd construct, Description] |
| 4941 | // The parameter of the simdlen clause must be a constant positive integer |
| 4942 | // expression. |
| 4943 | ExprResult SL; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4944 | if (Simdlen) |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 4945 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4946 | // OpenMP [2.8.2, declare simd construct, Description] |
| 4947 | // The special this pointer can be used as if was one of the arguments to the |
| 4948 | // function in any of the linear, aligned, or uniform clauses. |
| 4949 | // The uniform clause declares one or more arguments to have an invariant |
| 4950 | // value for all concurrent invocations of the function in the execution of a |
| 4951 | // single SIMD loop. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4952 | llvm::DenseMap<const Decl *, const Expr *> UniformedArgs; |
| 4953 | const Expr *UniformedLinearThis = nullptr; |
| 4954 | for (const Expr *E : Uniforms) { |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4955 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4956 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 4957 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4958 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 4959 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4960 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 4961 | UniformedArgs.try_emplace(PVD->getCanonicalDecl(), E); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4962 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4963 | } |
| 4964 | if (isa<CXXThisExpr>(E)) { |
| 4965 | UniformedLinearThis = E; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4966 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4967 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4968 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 4969 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 4970 | } |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4971 | // OpenMP [2.8.2, declare simd construct, Description] |
| 4972 | // The aligned clause declares that the object to which each list item points |
| 4973 | // is aligned to the number of bytes expressed in the optional parameter of |
| 4974 | // the aligned clause. |
| 4975 | // The special this pointer can be used as if was one of the arguments to the |
| 4976 | // function in any of the linear, aligned, or uniform clauses. |
| 4977 | // The type of list items appearing in the aligned clause must be array, |
| 4978 | // pointer, reference to array, or reference to pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4979 | llvm::DenseMap<const Decl *, const Expr *> AlignedArgs; |
| 4980 | const Expr *AlignedThis = nullptr; |
| 4981 | for (const Expr *E : Aligneds) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4982 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4983 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 4984 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 4985 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4986 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 4987 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 4988 | ->getCanonicalDecl() == CanonPVD) { |
| 4989 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4990 | // A list-item cannot appear in more than one aligned clause. |
| 4991 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 4992 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 4993 | << 1 << E->getSourceRange(); |
| 4994 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 4995 | diag::note_omp_explicit_dsa) |
| 4996 | << getOpenMPClauseName(OMPC_aligned); |
| 4997 | continue; |
| 4998 | } |
| 4999 | AlignedArgs[CanonPVD] = E; |
| 5000 | QualType QTy = PVD->getType() |
| 5001 | .getNonReferenceType() |
| 5002 | .getUnqualifiedType() |
| 5003 | .getCanonicalType(); |
| 5004 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 5005 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 5006 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 5007 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 5008 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 5009 | } |
| 5010 | continue; |
| 5011 | } |
| 5012 | } |
| 5013 | if (isa<CXXThisExpr>(E)) { |
| 5014 | if (AlignedThis) { |
| 5015 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 5016 | << 2 << E->getSourceRange(); |
| 5017 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 5018 | << getOpenMPClauseName(OMPC_aligned); |
| 5019 | } |
| 5020 | AlignedThis = E; |
| 5021 | continue; |
| 5022 | } |
| 5023 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 5024 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 5025 | } |
| 5026 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 5027 | // positive integer expression. If no optional parameter is specified, |
| 5028 | // implementation-defined default alignments for SIMD instructions on the |
| 5029 | // target platforms are assumed. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5030 | SmallVector<const Expr *, 4> NewAligns; |
| 5031 | for (Expr *E : Alignments) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 5032 | ExprResult Align; |
| 5033 | if (E) |
| 5034 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 5035 | NewAligns.push_back(Align.get()); |
| 5036 | } |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5037 | // OpenMP [2.8.2, declare simd construct, Description] |
| 5038 | // The linear clause declares one or more list items to be private to a SIMD |
| 5039 | // lane and to have a linear relationship with respect to the iteration space |
| 5040 | // of a loop. |
| 5041 | // The special this pointer can be used as if was one of the arguments to the |
| 5042 | // function in any of the linear, aligned, or uniform clauses. |
| 5043 | // When a linear-step expression is specified in a linear clause it must be |
| 5044 | // either a constant integer expression or an integer-typed parameter that is |
| 5045 | // specified in a uniform clause on the directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5046 | llvm::DenseMap<const Decl *, const Expr *> LinearArgs; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5047 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 5048 | auto MI = LinModifiers.begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5049 | for (const Expr *E : Linears) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5050 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 5051 | ++MI; |
| 5052 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5053 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 5054 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 5055 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5056 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 5057 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 5058 | ->getCanonicalDecl() == CanonPVD) { |
| 5059 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 5060 | // A list-item cannot appear in more than one linear clause. |
| 5061 | if (LinearArgs.count(CanonPVD) > 0) { |
| 5062 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 5063 | << getOpenMPClauseName(OMPC_linear) |
| 5064 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 5065 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 5066 | diag::note_omp_explicit_dsa) |
| 5067 | << getOpenMPClauseName(OMPC_linear); |
| 5068 | continue; |
| 5069 | } |
| 5070 | // Each argument can appear in at most one uniform or linear clause. |
| 5071 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 5072 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 5073 | << getOpenMPClauseName(OMPC_linear) |
| 5074 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 5075 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 5076 | diag::note_omp_explicit_dsa) |
| 5077 | << getOpenMPClauseName(OMPC_uniform); |
| 5078 | continue; |
| 5079 | } |
| 5080 | LinearArgs[CanonPVD] = E; |
| 5081 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5082 | E->isInstantiationDependent() || |
| 5083 | E->containsUnexpandedParameterPack()) |
| 5084 | continue; |
| 5085 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 5086 | PVD->getOriginalType()); |
| 5087 | continue; |
| 5088 | } |
| 5089 | } |
| 5090 | if (isa<CXXThisExpr>(E)) { |
| 5091 | if (UniformedLinearThis) { |
| 5092 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 5093 | << getOpenMPClauseName(OMPC_linear) |
| 5094 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 5095 | << E->getSourceRange(); |
| 5096 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 5097 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 5098 | : OMPC_linear); |
| 5099 | continue; |
| 5100 | } |
| 5101 | UniformedLinearThis = E; |
| 5102 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5103 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 5104 | continue; |
| 5105 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 5106 | E->getType()); |
| 5107 | continue; |
| 5108 | } |
| 5109 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 5110 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 5111 | } |
| 5112 | Expr *Step = nullptr; |
| 5113 | Expr *NewStep = nullptr; |
| 5114 | SmallVector<Expr *, 4> NewSteps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5115 | for (Expr *E : Steps) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5116 | // Skip the same step expression, it was checked already. |
| 5117 | if (Step == E || !E) { |
| 5118 | NewSteps.push_back(E ? NewStep : nullptr); |
| 5119 | continue; |
| 5120 | } |
| 5121 | Step = E; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5122 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 5123 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 5124 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5125 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 5126 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 5127 | << Step->getSourceRange(); |
| 5128 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 5129 | E->isInstantiationDependent() || |
| 5130 | E->containsUnexpandedParameterPack() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5131 | CanonPVD->getType()->hasIntegerRepresentation()) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5132 | NewSteps.push_back(Step); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5133 | } else { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5134 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 5135 | << Step->getSourceRange(); |
| 5136 | } |
| 5137 | continue; |
| 5138 | } |
| 5139 | NewStep = Step; |
| 5140 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 5141 | !Step->isInstantiationDependent() && |
| 5142 | !Step->containsUnexpandedParameterPack()) { |
| 5143 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 5144 | .get(); |
| 5145 | if (NewStep) |
| 5146 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 5147 | } |
| 5148 | NewSteps.push_back(NewStep); |
| 5149 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 5150 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 5151 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 5152 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 5153 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 5154 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 5155 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 5156 | NewSteps.data(), NewSteps.size(), SR); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 5157 | ADecl->addAttr(NewAttr); |
| Alexey Bataev | a006307 | 2019-09-16 17:06:31 +0000 | [diff] [blame] | 5158 | return DG; |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5161 | Optional<std::pair<FunctionDecl *, Expr *>> |
| 5162 | Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG, |
| 5163 | Expr *VariantRef, SourceRange SR) { |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5164 | if (!DG || DG.get().isNull()) |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5165 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5166 | |
| 5167 | const int VariantId = 1; |
| 5168 | // Must be applied only to single decl. |
| 5169 | if (!DG.get().isSingleDecl()) { |
| 5170 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd_variant) |
| 5171 | << VariantId << SR; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5172 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5173 | } |
| 5174 | Decl *ADecl = DG.get().getSingleDecl(); |
| 5175 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 5176 | ADecl = FTD->getTemplatedDecl(); |
| 5177 | |
| 5178 | // Decl must be a function. |
| 5179 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 5180 | if (!FD) { |
| 5181 | Diag(ADecl->getLocation(), diag::err_omp_function_expected) |
| 5182 | << VariantId << SR; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5183 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | auto &&HasMultiVersionAttributes = [](const FunctionDecl *FD) { |
| 5187 | return FD->hasAttrs() && |
| 5188 | (FD->hasAttr<CPUDispatchAttr>() || FD->hasAttr<CPUSpecificAttr>() || |
| 5189 | FD->hasAttr<TargetAttr>()); |
| 5190 | }; |
| 5191 | // OpenMP is not compatible with CPU-specific attributes. |
| 5192 | if (HasMultiVersionAttributes(FD)) { |
| 5193 | Diag(FD->getLocation(), diag::err_omp_declare_variant_incompat_attributes) |
| 5194 | << SR; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5195 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | // Allow #pragma omp declare variant only if the function is not used. |
| Alexey Bataev | 1202614 | 2019-09-26 20:04:15 +0000 | [diff] [blame] | 5199 | if (FD->isUsed(false)) |
| 5200 | Diag(SR.getBegin(), diag::warn_omp_declare_variant_after_used) |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5201 | << FD->getLocation(); |
| Alexey Bataev | 1202614 | 2019-09-26 20:04:15 +0000 | [diff] [blame] | 5202 | |
| 5203 | // Check if the function was emitted already. |
| Alexey Bataev | 218bea9 | 2019-09-30 18:24:35 +0000 | [diff] [blame] | 5204 | const FunctionDecl *Definition; |
| 5205 | if (!FD->isThisDeclarationADefinition() && FD->isDefined(Definition) && |
| 5206 | (LangOpts.EmitAllDecls || Context.DeclMustBeEmitted(Definition))) |
| Alexey Bataev | 1202614 | 2019-09-26 20:04:15 +0000 | [diff] [blame] | 5207 | Diag(SR.getBegin(), diag::warn_omp_declare_variant_after_emitted) |
| 5208 | << FD->getLocation(); |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5209 | |
| 5210 | // The VariantRef must point to function. |
| 5211 | if (!VariantRef) { |
| 5212 | Diag(SR.getBegin(), diag::err_omp_function_expected) << VariantId; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5213 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | // Do not check templates, wait until instantiation. |
| 5217 | if (VariantRef->isTypeDependent() || VariantRef->isValueDependent() || |
| 5218 | VariantRef->containsUnexpandedParameterPack() || |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5219 | VariantRef->isInstantiationDependent() || FD->isDependentContext()) |
| 5220 | return std::make_pair(FD, VariantRef); |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5221 | |
| 5222 | // Convert VariantRef expression to the type of the original function to |
| 5223 | // resolve possible conflicts. |
| 5224 | ExprResult VariantRefCast; |
| 5225 | if (LangOpts.CPlusPlus) { |
| 5226 | QualType FnPtrType; |
| 5227 | auto *Method = dyn_cast<CXXMethodDecl>(FD); |
| 5228 | if (Method && !Method->isStatic()) { |
| 5229 | const Type *ClassType = |
| 5230 | Context.getTypeDeclType(Method->getParent()).getTypePtr(); |
| 5231 | FnPtrType = Context.getMemberPointerType(FD->getType(), ClassType); |
| 5232 | ExprResult ER; |
| 5233 | { |
| 5234 | // Build adrr_of unary op to correctly handle type checks for member |
| 5235 | // functions. |
| 5236 | Sema::TentativeAnalysisScope Trap(*this); |
| 5237 | ER = CreateBuiltinUnaryOp(VariantRef->getBeginLoc(), UO_AddrOf, |
| 5238 | VariantRef); |
| 5239 | } |
| 5240 | if (!ER.isUsable()) { |
| 5241 | Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected) |
| 5242 | << VariantId << VariantRef->getSourceRange(); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5243 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5244 | } |
| 5245 | VariantRef = ER.get(); |
| 5246 | } else { |
| 5247 | FnPtrType = Context.getPointerType(FD->getType()); |
| 5248 | } |
| 5249 | ImplicitConversionSequence ICS = |
| 5250 | TryImplicitConversion(VariantRef, FnPtrType.getUnqualifiedType(), |
| 5251 | /*SuppressUserConversions=*/false, |
| 5252 | /*AllowExplicit=*/false, |
| 5253 | /*InOverloadResolution=*/false, |
| 5254 | /*CStyle=*/false, |
| 5255 | /*AllowObjCWritebackConversion=*/false); |
| 5256 | if (ICS.isFailure()) { |
| 5257 | Diag(VariantRef->getExprLoc(), |
| 5258 | diag::err_omp_declare_variant_incompat_types) |
| 5259 | << VariantRef->getType() << FnPtrType << VariantRef->getSourceRange(); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5260 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5261 | } |
| 5262 | VariantRefCast = PerformImplicitConversion( |
| 5263 | VariantRef, FnPtrType.getUnqualifiedType(), AA_Converting); |
| 5264 | if (!VariantRefCast.isUsable()) |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5265 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5266 | // Drop previously built artificial addr_of unary op for member functions. |
| 5267 | if (Method && !Method->isStatic()) { |
| 5268 | Expr *PossibleAddrOfVariantRef = VariantRefCast.get(); |
| 5269 | if (auto *UO = dyn_cast<UnaryOperator>( |
| 5270 | PossibleAddrOfVariantRef->IgnoreImplicit())) |
| 5271 | VariantRefCast = UO->getSubExpr(); |
| 5272 | } |
| 5273 | } else { |
| 5274 | VariantRefCast = VariantRef; |
| 5275 | } |
| 5276 | |
| 5277 | ExprResult ER = CheckPlaceholderExpr(VariantRefCast.get()); |
| 5278 | if (!ER.isUsable() || |
| 5279 | !ER.get()->IgnoreParenImpCasts()->getType()->isFunctionType()) { |
| 5280 | Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected) |
| 5281 | << VariantId << VariantRef->getSourceRange(); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5282 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | // The VariantRef must point to function. |
| 5286 | auto *DRE = dyn_cast<DeclRefExpr>(ER.get()->IgnoreParenImpCasts()); |
| 5287 | if (!DRE) { |
| 5288 | Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected) |
| 5289 | << VariantId << VariantRef->getSourceRange(); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5290 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5291 | } |
| 5292 | auto *NewFD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl()); |
| 5293 | if (!NewFD) { |
| 5294 | Diag(VariantRef->getExprLoc(), diag::err_omp_function_expected) |
| 5295 | << VariantId << VariantRef->getSourceRange(); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5296 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
| Alexey Bataev | bf5d429 | 2019-09-17 17:36:49 +0000 | [diff] [blame] | 5299 | // Check if variant function is not marked with declare variant directive. |
| 5300 | if (NewFD->hasAttrs() && NewFD->hasAttr<OMPDeclareVariantAttr>()) { |
| 5301 | Diag(VariantRef->getExprLoc(), |
| 5302 | diag::warn_omp_declare_variant_marked_as_declare_variant) |
| 5303 | << VariantRef->getSourceRange(); |
| 5304 | SourceRange SR = |
| 5305 | NewFD->specific_attr_begin<OMPDeclareVariantAttr>()->getRange(); |
| 5306 | Diag(SR.getBegin(), diag::note_omp_marked_declare_variant_here) << SR; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5307 | return None; |
| Alexey Bataev | bf5d429 | 2019-09-17 17:36:49 +0000 | [diff] [blame] | 5308 | } |
| 5309 | |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5310 | enum DoesntSupport { |
| 5311 | VirtFuncs = 1, |
| 5312 | Constructors = 3, |
| 5313 | Destructors = 4, |
| 5314 | DeletedFuncs = 5, |
| 5315 | DefaultedFuncs = 6, |
| 5316 | ConstexprFuncs = 7, |
| 5317 | ConstevalFuncs = 8, |
| 5318 | }; |
| 5319 | if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) { |
| 5320 | if (CXXFD->isVirtual()) { |
| 5321 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5322 | << VirtFuncs; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5323 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | if (isa<CXXConstructorDecl>(FD)) { |
| 5327 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5328 | << Constructors; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5329 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | if (isa<CXXDestructorDecl>(FD)) { |
| 5333 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5334 | << Destructors; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5335 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | if (FD->isDeleted()) { |
| 5340 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5341 | << DeletedFuncs; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5342 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | if (FD->isDefaulted()) { |
| 5346 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5347 | << DefaultedFuncs; |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5348 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | if (FD->isConstexpr()) { |
| 5352 | Diag(FD->getLocation(), diag::err_omp_declare_variant_doesnt_support) |
| 5353 | << (NewFD->isConsteval() ? ConstevalFuncs : ConstexprFuncs); |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5354 | return None; |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | // Check general compatibility. |
| 5358 | if (areMultiversionVariantFunctionsCompatible( |
| 5359 | FD, NewFD, PDiag(diag::err_omp_declare_variant_noproto), |
| 5360 | PartialDiagnosticAt( |
| 5361 | SR.getBegin(), |
| 5362 | PDiag(diag::note_omp_declare_variant_specified_here) << SR), |
| 5363 | PartialDiagnosticAt( |
| 5364 | VariantRef->getExprLoc(), |
| 5365 | PDiag(diag::err_omp_declare_variant_doesnt_support)), |
| 5366 | PartialDiagnosticAt(VariantRef->getExprLoc(), |
| 5367 | PDiag(diag::err_omp_declare_variant_diff) |
| 5368 | << FD->getLocation()), |
| Alexey Bataev | 6b06ead | 2019-10-08 14:56:20 +0000 | [diff] [blame] | 5369 | /*TemplatesSupported=*/true, /*ConstexprSupported=*/false, |
| 5370 | /*CLinkageMayDiffer=*/true)) |
| Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 5371 | return None; |
| 5372 | return std::make_pair(FD, cast<Expr>(DRE)); |
| 5373 | } |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5374 | |
| Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 5375 | void Sema::ActOnOpenMPDeclareVariantDirective( |
| 5376 | FunctionDecl *FD, Expr *VariantRef, SourceRange SR, |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5377 | ArrayRef<OMPCtxSelectorData> Data) { |
| 5378 | if (Data.empty()) |
| Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 5379 | return; |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5380 | SmallVector<Expr *, 4> CtxScores; |
| 5381 | SmallVector<unsigned, 4> CtxSets; |
| 5382 | SmallVector<unsigned, 4> Ctxs; |
| Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 5383 | SmallVector<StringRef, 4> ImplVendors, DeviceKinds; |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5384 | bool IsError = false; |
| 5385 | for (const OMPCtxSelectorData &D : Data) { |
| 5386 | OpenMPContextSelectorSetKind CtxSet = D.CtxSet; |
| 5387 | OpenMPContextSelectorKind Ctx = D.Ctx; |
| 5388 | if (CtxSet == OMP_CTX_SET_unknown || Ctx == OMP_CTX_unknown) |
| 5389 | return; |
| 5390 | Expr *Score = nullptr; |
| 5391 | if (D.Score.isUsable()) { |
| 5392 | Score = D.Score.get(); |
| 5393 | if (!Score->isTypeDependent() && !Score->isValueDependent() && |
| 5394 | !Score->isInstantiationDependent() && |
| 5395 | !Score->containsUnexpandedParameterPack()) { |
| 5396 | Score = |
| 5397 | PerformOpenMPImplicitIntegerConversion(Score->getExprLoc(), Score) |
| 5398 | .get(); |
| 5399 | if (Score) |
| 5400 | Score = VerifyIntegerConstantExpression(Score).get(); |
| 5401 | } |
| 5402 | } else { |
| Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 5403 | // OpenMP 5.0, 2.3.3 Matching and Scoring Context Selectors. |
| 5404 | // The kind, arch, and isa selectors are given the values 2^l, 2^(l+1) and |
| 5405 | // 2^(l+2), respectively, where l is the number of traits in the construct |
| 5406 | // set. |
| 5407 | // TODO: implement correct logic for isa and arch traits. |
| 5408 | // TODO: take the construct context set into account when it is |
| 5409 | // implemented. |
| 5410 | int L = 0; // Currently set the number of traits in construct set to 0, |
| 5411 | // since the construct trait set in not supported yet. |
| 5412 | if (CtxSet == OMP_CTX_SET_device && Ctx == OMP_CTX_kind) |
| 5413 | Score = ActOnIntegerConstant(SourceLocation(), std::pow(2, L)).get(); |
| 5414 | else |
| 5415 | Score = ActOnIntegerConstant(SourceLocation(), 0).get(); |
| Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 5416 | } |
| Alexey Bataev | 5459a90 | 2019-11-22 11:42:08 -0500 | [diff] [blame] | 5417 | switch (Ctx) { |
| 5418 | case OMP_CTX_vendor: |
| 5419 | assert(CtxSet == OMP_CTX_SET_implementation && |
| 5420 | "Expected implementation context selector set."); |
| 5421 | ImplVendors.append(D.Names.begin(), D.Names.end()); |
| Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 5422 | break; |
| Alexey Bataev | 5459a90 | 2019-11-22 11:42:08 -0500 | [diff] [blame] | 5423 | case OMP_CTX_kind: |
| 5424 | assert(CtxSet == OMP_CTX_SET_device && |
| 5425 | "Expected device context selector set."); |
| 5426 | DeviceKinds.append(D.Names.begin(), D.Names.end()); |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5427 | break; |
| Alexey Bataev | 5459a90 | 2019-11-22 11:42:08 -0500 | [diff] [blame] | 5428 | case OMP_CTX_unknown: |
| 5429 | llvm_unreachable("Unknown context selector kind."); |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5430 | } |
| 5431 | IsError = IsError || !Score; |
| 5432 | CtxSets.push_back(CtxSet); |
| 5433 | Ctxs.push_back(Ctx); |
| 5434 | CtxScores.push_back(Score); |
| Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 5435 | } |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5436 | if (!IsError) { |
| 5437 | auto *NewAttr = OMPDeclareVariantAttr::CreateImplicit( |
| 5438 | Context, VariantRef, CtxScores.begin(), CtxScores.size(), |
| 5439 | CtxSets.begin(), CtxSets.size(), Ctxs.begin(), Ctxs.size(), |
| Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 5440 | ImplVendors.begin(), ImplVendors.size(), DeviceKinds.begin(), |
| 5441 | DeviceKinds.size(), SR); |
| Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 5442 | FD->addAttr(NewAttr); |
| 5443 | } |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
| Alexey Bataev | bf5d429 | 2019-09-17 17:36:49 +0000 | [diff] [blame] | 5446 | void Sema::markOpenMPDeclareVariantFuncsReferenced(SourceLocation Loc, |
| 5447 | FunctionDecl *Func, |
| 5448 | bool MightBeOdrUse) { |
| 5449 | assert(LangOpts.OpenMP && "Expected OpenMP mode."); |
| 5450 | |
| 5451 | if (!Func->isDependentContext() && Func->hasAttrs()) { |
| 5452 | for (OMPDeclareVariantAttr *A : |
| 5453 | Func->specific_attrs<OMPDeclareVariantAttr>()) { |
| 5454 | // TODO: add checks for active OpenMP context where possible. |
| 5455 | Expr *VariantRef = A->getVariantFuncRef(); |
| Alexey Bataev | f17a1d8 | 2019-12-02 14:15:38 -0500 | [diff] [blame] | 5456 | auto *DRE = cast<DeclRefExpr>(VariantRef->IgnoreParenImpCasts()); |
| Alexey Bataev | bf5d429 | 2019-09-17 17:36:49 +0000 | [diff] [blame] | 5457 | auto *F = cast<FunctionDecl>(DRE->getDecl()); |
| 5458 | if (!F->isDefined() && F->isTemplateInstantiation()) |
| 5459 | InstantiateFunctionDefinition(Loc, F->getFirstDecl()); |
| 5460 | MarkFunctionReferenced(Loc, F, MightBeOdrUse); |
| 5461 | } |
| 5462 | } |
| 5463 | } |
| 5464 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5465 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5466 | Stmt *AStmt, |
| 5467 | SourceLocation StartLoc, |
| 5468 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5469 | if (!AStmt) |
| 5470 | return StmtError(); |
| 5471 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5472 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 5473 | // 1.2.2 OpenMP Language Terminology |
| 5474 | // Structured block - An executable statement with a single entry at the |
| 5475 | // top and a single exit at the bottom. |
| 5476 | // The point of exit cannot be a branch out of the structured block. |
| 5477 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5478 | CS->getCapturedDecl()->setNothrow(); |
| 5479 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5480 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5481 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5482 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5483 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5486 | namespace { |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5487 | /// Iteration space of a single for loop. |
| 5488 | struct LoopIterationSpace final { |
| 5489 | /// True if the condition operator is the strict compare operator (<, > or |
| 5490 | /// !=). |
| 5491 | bool IsStrictCompare = false; |
| 5492 | /// Condition of the loop. |
| 5493 | Expr *PreCond = nullptr; |
| 5494 | /// This expression calculates the number of iterations in the loop. |
| 5495 | /// It is always possible to calculate it before starting the loop. |
| 5496 | Expr *NumIterations = nullptr; |
| 5497 | /// The loop counter variable. |
| 5498 | Expr *CounterVar = nullptr; |
| 5499 | /// Private loop counter variable. |
| 5500 | Expr *PrivateCounterVar = nullptr; |
| 5501 | /// This is initializer for the initial value of #CounterVar. |
| 5502 | Expr *CounterInit = nullptr; |
| 5503 | /// This is step for the #CounterVar used to generate its update: |
| 5504 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 5505 | Expr *CounterStep = nullptr; |
| 5506 | /// Should step be subtracted? |
| 5507 | bool Subtract = false; |
| 5508 | /// Source range of the loop init. |
| 5509 | SourceRange InitSrcRange; |
| 5510 | /// Source range of the loop condition. |
| 5511 | SourceRange CondSrcRange; |
| 5512 | /// Source range of the loop increment. |
| 5513 | SourceRange IncSrcRange; |
| 5514 | /// Minimum value that can have the loop control variable. Used to support |
| 5515 | /// non-rectangular loops. Applied only for LCV with the non-iterator types, |
| 5516 | /// since only such variables can be used in non-loop invariant expressions. |
| 5517 | Expr *MinValue = nullptr; |
| 5518 | /// Maximum value that can have the loop control variable. Used to support |
| 5519 | /// non-rectangular loops. Applied only for LCV with the non-iterator type, |
| 5520 | /// since only such variables can be used in non-loop invariant expressions. |
| 5521 | Expr *MaxValue = nullptr; |
| 5522 | /// true, if the lower bound depends on the outer loop control var. |
| 5523 | bool IsNonRectangularLB = false; |
| 5524 | /// true, if the upper bound depends on the outer loop control var. |
| 5525 | bool IsNonRectangularUB = false; |
| 5526 | /// Index of the loop this loop depends on and forms non-rectangular loop |
| 5527 | /// nest. |
| 5528 | unsigned LoopDependentIdx = 0; |
| 5529 | /// Final condition for the non-rectangular loop nest support. It is used to |
| 5530 | /// check that the number of iterations for this particular counter must be |
| 5531 | /// finished. |
| 5532 | Expr *FinalCondition = nullptr; |
| 5533 | }; |
| 5534 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5535 | /// Helper class for checking canonical form of the OpenMP loops and |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5536 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 5537 | /// for IR generation. |
| 5538 | class OpenMPIterationSpaceChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5539 | /// Reference to Sema. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5540 | Sema &SemaRef; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5541 | /// Data-sharing stack. |
| 5542 | DSAStackTy &Stack; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5543 | /// A location for diagnostics (when there is no some better location). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5544 | SourceLocation DefaultLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5545 | /// A location for diagnostics (when increment is not compatible). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5546 | SourceLocation ConditionLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5547 | /// A source location for referring to loop init later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5548 | SourceRange InitSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5549 | /// A source location for referring to condition later. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5550 | SourceRange ConditionSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5551 | /// A source location for referring to increment later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5552 | SourceRange IncrementSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5553 | /// Loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5554 | ValueDecl *LCDecl = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5555 | /// Reference to loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5556 | Expr *LCRef = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5557 | /// Lower bound (initializer for the var). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5558 | Expr *LB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5559 | /// Upper bound. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5560 | Expr *UB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5561 | /// Loop step (increment). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5562 | Expr *Step = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5563 | /// This flag is true when condition is one of: |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5564 | /// Var < UB |
| 5565 | /// Var <= UB |
| 5566 | /// UB > Var |
| 5567 | /// UB >= Var |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5568 | /// This will have no value when the condition is != |
| 5569 | llvm::Optional<bool> TestIsLessOp; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5570 | /// This flag is true when condition is strict ( < or > ). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5571 | bool TestIsStrictOp = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5572 | /// This flag is true when step is subtracted on each iteration. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5573 | bool SubtractStep = false; |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5574 | /// The outer loop counter this loop depends on (if any). |
| 5575 | const ValueDecl *DepDecl = nullptr; |
| 5576 | /// Contains number of loop (starts from 1) on which loop counter init |
| 5577 | /// expression of this loop depends on. |
| 5578 | Optional<unsigned> InitDependOnLC; |
| 5579 | /// Contains number of loop (starts from 1) on which loop counter condition |
| 5580 | /// expression of this loop depends on. |
| 5581 | Optional<unsigned> CondDependOnLC; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5582 | /// Checks if the provide statement depends on the loop counter. |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5583 | Optional<unsigned> doesDependOnLoopCounter(const Stmt *S, bool IsInitializer); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5584 | /// Original condition required for checking of the exit condition for |
| 5585 | /// non-rectangular loop. |
| 5586 | Expr *Condition = nullptr; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5587 | |
| 5588 | public: |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5589 | OpenMPIterationSpaceChecker(Sema &SemaRef, DSAStackTy &Stack, |
| 5590 | SourceLocation DefaultLoc) |
| 5591 | : SemaRef(SemaRef), Stack(Stack), DefaultLoc(DefaultLoc), |
| 5592 | ConditionLoc(DefaultLoc) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5593 | /// Check init-expr for canonical loop form and save loop counter |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5594 | /// variable - #Var and its initialization value - #LB. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5595 | bool checkAndSetInit(Stmt *S, bool EmitDiags = true); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5596 | /// Check test-expr for canonical form, save upper-bound (#UB), flags |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5597 | /// for less/greater and for strict/non-strict comparison. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5598 | bool checkAndSetCond(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5599 | /// Check incr-expr for canonical loop form and return true if it |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5600 | /// does not conform, otherwise save loop step (#Step). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5601 | bool checkAndSetInc(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5602 | /// Return the loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5603 | ValueDecl *getLoopDecl() const { return LCDecl; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5604 | /// Return the reference expression to loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5605 | Expr *getLoopDeclRefExpr() const { return LCRef; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5606 | /// Source range of the loop init. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5607 | SourceRange getInitSrcRange() const { return InitSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5608 | /// Source range of the loop condition. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5609 | SourceRange getConditionSrcRange() const { return ConditionSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5610 | /// Source range of the loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5611 | SourceRange getIncrementSrcRange() const { return IncrementSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5612 | /// True if the step should be subtracted. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5613 | bool shouldSubtractStep() const { return SubtractStep; } |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5614 | /// True, if the compare operator is strict (<, > or !=). |
| 5615 | bool isStrictTestOp() const { return TestIsStrictOp; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5616 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5617 | Expr *buildNumIterations( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5618 | Scope *S, ArrayRef<LoopIterationSpace> ResultIterSpaces, bool LimitedType, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5619 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5620 | /// Build the precondition expression for the loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5621 | Expr * |
| 5622 | buildPreCond(Scope *S, Expr *Cond, |
| 5623 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5624 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5625 | DeclRefExpr * |
| 5626 | buildCounterVar(llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 5627 | DSAStackTy &DSA) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5628 | /// Build reference expression to the private counter be used for |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5629 | /// codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5630 | Expr *buildPrivateCounterVar() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5631 | /// Build initialization of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5632 | Expr *buildCounterInit() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5633 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5634 | Expr *buildCounterStep() const; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5635 | /// Build loop data with counter value for depend clauses in ordered |
| 5636 | /// directives. |
| 5637 | Expr * |
| 5638 | buildOrderedLoopData(Scope *S, Expr *Counter, |
| 5639 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 5640 | SourceLocation Loc, Expr *Inc = nullptr, |
| 5641 | OverloadedOperatorKind OOK = OO_Amp); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5642 | /// Builds the minimum value for the loop counter. |
| 5643 | std::pair<Expr *, Expr *> buildMinMaxValues( |
| 5644 | Scope *S, llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| 5645 | /// Builds final condition for the non-rectangular loops. |
| 5646 | Expr *buildFinalCondition(Scope *S) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5647 | /// Return true if any expression is dependent. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5648 | bool dependent() const; |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5649 | /// Returns true if the initializer forms non-rectangular loop. |
| 5650 | bool doesInitDependOnLC() const { return InitDependOnLC.hasValue(); } |
| 5651 | /// Returns true if the condition forms non-rectangular loop. |
| 5652 | bool doesCondDependOnLC() const { return CondDependOnLC.hasValue(); } |
| 5653 | /// Returns index of the loop we depend on (starting from 1), or 0 otherwise. |
| 5654 | unsigned getLoopDependentIdx() const { |
| 5655 | return InitDependOnLC.getValueOr(CondDependOnLC.getValueOr(0)); |
| 5656 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5657 | |
| 5658 | private: |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5659 | /// Check the right-hand side of an assignment in the increment |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5660 | /// expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5661 | bool checkAndSetIncRHS(Expr *RHS); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5662 | /// Helper to set loop counter variable and its initializer. |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5663 | bool setLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB, |
| 5664 | bool EmitDiags); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5665 | /// Helper to set upper bound. |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5666 | bool setUB(Expr *NewUB, llvm::Optional<bool> LessOp, bool StrictOp, |
| 5667 | SourceRange SR, SourceLocation SL); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5668 | /// Helper to set loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5669 | bool setStep(Expr *NewStep, bool Subtract); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5670 | }; |
| 5671 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5672 | bool OpenMPIterationSpaceChecker::dependent() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5673 | if (!LCDecl) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5674 | assert(!LB && !UB && !Step); |
| 5675 | return false; |
| 5676 | } |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5677 | return LCDecl->getType()->isDependentType() || |
| 5678 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 5679 | (Step && Step->isValueDependent()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5682 | bool OpenMPIterationSpaceChecker::setLCDeclAndLB(ValueDecl *NewLCDecl, |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5683 | Expr *NewLCRefExpr, |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5684 | Expr *NewLB, bool EmitDiags) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5685 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5686 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
| Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 5687 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5688 | if (!NewLCDecl || !NewLB) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5689 | return true; |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5690 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 5691 | LCRef = NewLCRefExpr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5692 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 5693 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 5694 | if ((Ctor->isCopyOrMoveConstructor() || |
| 5695 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 5696 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5697 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5698 | LB = NewLB; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5699 | if (EmitDiags) |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5700 | InitDependOnLC = doesDependOnLoopCounter(LB, /*IsInitializer=*/true); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5701 | return false; |
| 5702 | } |
| 5703 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5704 | bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB, |
| 5705 | llvm::Optional<bool> LessOp, |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5706 | bool StrictOp, SourceRange SR, |
| 5707 | SourceLocation SL) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5708 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5709 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 5710 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5711 | if (!NewUB) |
| 5712 | return true; |
| 5713 | UB = NewUB; |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5714 | if (LessOp) |
| 5715 | TestIsLessOp = LessOp; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5716 | TestIsStrictOp = StrictOp; |
| 5717 | ConditionSrcRange = SR; |
| 5718 | ConditionLoc = SL; |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5719 | CondDependOnLC = doesDependOnLoopCounter(UB, /*IsInitializer=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5720 | return false; |
| 5721 | } |
| 5722 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5723 | bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5724 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5725 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5726 | if (!NewStep) |
| 5727 | return true; |
| 5728 | if (!NewStep->isValueDependent()) { |
| 5729 | // Check that the step is integer expression. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5730 | SourceLocation StepLoc = NewStep->getBeginLoc(); |
| Alexey Bataev | 5372fb8 | 2017-08-31 23:06:52 +0000 | [diff] [blame] | 5731 | ExprResult Val = SemaRef.PerformOpenMPImplicitIntegerConversion( |
| 5732 | StepLoc, getExprAsWritten(NewStep)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5733 | if (Val.isInvalid()) |
| 5734 | return true; |
| 5735 | NewStep = Val.get(); |
| 5736 | |
| 5737 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 5738 | // If test-expr is of form var relational-op b and relational-op is < or |
| 5739 | // <= then incr-expr must cause var to increase on each iteration of the |
| 5740 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 5741 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 5742 | // the loop. |
| 5743 | // If test-expr is of form b relational-op var and relational-op is < or |
| 5744 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 5745 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 5746 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 5747 | // the loop. |
| 5748 | llvm::APSInt Result; |
| 5749 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5750 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 5751 | bool IsConstNeg = |
| 5752 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5753 | bool IsConstPos = |
| 5754 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5755 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5756 | |
| 5757 | // != with increment is treated as <; != with decrement is treated as > |
| 5758 | if (!TestIsLessOp.hasValue()) |
| 5759 | TestIsLessOp = IsConstPos || (IsUnsigned && !Subtract); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5760 | if (UB && (IsConstZero || |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 5761 | (TestIsLessOp.getValue() ? |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5762 | (IsConstNeg || (IsUnsigned && Subtract)) : |
| 5763 | (IsConstPos || (IsUnsigned && !Subtract))))) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5764 | SemaRef.Diag(NewStep->getExprLoc(), |
| 5765 | diag::err_omp_loop_incr_not_compatible) |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5766 | << LCDecl << TestIsLessOp.getValue() << NewStep->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5767 | SemaRef.Diag(ConditionLoc, |
| 5768 | diag::note_omp_loop_cond_requres_compatible_incr) |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5769 | << TestIsLessOp.getValue() << ConditionSrcRange; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5770 | return true; |
| 5771 | } |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 5772 | if (TestIsLessOp.getValue() == Subtract) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5773 | NewStep = |
| 5774 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 5775 | .get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5776 | Subtract = !Subtract; |
| 5777 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | Step = NewStep; |
| 5781 | SubtractStep = Subtract; |
| 5782 | return false; |
| 5783 | } |
| 5784 | |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5785 | namespace { |
| 5786 | /// Checker for the non-rectangular loops. Checks if the initializer or |
| 5787 | /// condition expression references loop counter variable. |
| 5788 | class LoopCounterRefChecker final |
| 5789 | : public ConstStmtVisitor<LoopCounterRefChecker, bool> { |
| 5790 | Sema &SemaRef; |
| 5791 | DSAStackTy &Stack; |
| 5792 | const ValueDecl *CurLCDecl = nullptr; |
| Alexey Bataev | 2f9ef33 | 2019-04-25 16:21:13 +0000 | [diff] [blame] | 5793 | const ValueDecl *DepDecl = nullptr; |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5794 | const ValueDecl *PrevDepDecl = nullptr; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5795 | bool IsInitializer = true; |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5796 | unsigned BaseLoopId = 0; |
| 5797 | bool checkDecl(const Expr *E, const ValueDecl *VD) { |
| 5798 | if (getCanonicalDecl(VD) == getCanonicalDecl(CurLCDecl)) { |
| 5799 | SemaRef.Diag(E->getExprLoc(), diag::err_omp_stmt_depends_on_loop_counter) |
| 5800 | << (IsInitializer ? 0 : 1); |
| 5801 | return false; |
| 5802 | } |
| 5803 | const auto &&Data = Stack.isLoopControlVariable(VD); |
| 5804 | // OpenMP, 2.9.1 Canonical Loop Form, Restrictions. |
| 5805 | // The type of the loop iterator on which we depend may not have a random |
| 5806 | // access iterator type. |
| 5807 | if (Data.first && VD->getType()->isRecordType()) { |
| 5808 | SmallString<128> Name; |
| 5809 | llvm::raw_svector_ostream OS(Name); |
| 5810 | VD->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(), |
| 5811 | /*Qualified=*/true); |
| 5812 | SemaRef.Diag(E->getExprLoc(), |
| 5813 | diag::err_omp_wrong_dependency_iterator_type) |
| 5814 | << OS.str(); |
| 5815 | SemaRef.Diag(VD->getLocation(), diag::note_previous_decl) << VD; |
| 5816 | return false; |
| 5817 | } |
| 5818 | if (Data.first && |
| 5819 | (DepDecl || (PrevDepDecl && |
| 5820 | getCanonicalDecl(VD) != getCanonicalDecl(PrevDepDecl)))) { |
| 5821 | if (!DepDecl && PrevDepDecl) |
| 5822 | DepDecl = PrevDepDecl; |
| 5823 | SmallString<128> Name; |
| 5824 | llvm::raw_svector_ostream OS(Name); |
| 5825 | DepDecl->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(), |
| 5826 | /*Qualified=*/true); |
| 5827 | SemaRef.Diag(E->getExprLoc(), |
| 5828 | diag::err_omp_invariant_or_linear_dependency) |
| 5829 | << OS.str(); |
| 5830 | return false; |
| 5831 | } |
| 5832 | if (Data.first) { |
| 5833 | DepDecl = VD; |
| 5834 | BaseLoopId = Data.first; |
| 5835 | } |
| 5836 | return Data.first; |
| 5837 | } |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5838 | |
| 5839 | public: |
| 5840 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 5841 | const ValueDecl *VD = E->getDecl(); |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5842 | if (isa<VarDecl>(VD)) |
| 5843 | return checkDecl(E, VD); |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5844 | return false; |
| 5845 | } |
| 5846 | bool VisitMemberExpr(const MemberExpr *E) { |
| 5847 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 5848 | const ValueDecl *VD = E->getMemberDecl(); |
| Mike Rice | 552c2c0 | 2019-07-17 15:18:45 +0000 | [diff] [blame] | 5849 | if (isa<VarDecl>(VD) || isa<FieldDecl>(VD)) |
| 5850 | return checkDecl(E, VD); |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5851 | } |
| 5852 | return false; |
| 5853 | } |
| 5854 | bool VisitStmt(const Stmt *S) { |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5855 | bool Res = false; |
| Alexey Bataev | 2f9ef33 | 2019-04-25 16:21:13 +0000 | [diff] [blame] | 5856 | for (const Stmt *Child : S->children()) |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 5857 | Res = (Child && Visit(Child)) || Res; |
| Alexey Bataev | 2f9ef33 | 2019-04-25 16:21:13 +0000 | [diff] [blame] | 5858 | return Res; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5859 | } |
| 5860 | explicit LoopCounterRefChecker(Sema &SemaRef, DSAStackTy &Stack, |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5861 | const ValueDecl *CurLCDecl, bool IsInitializer, |
| 5862 | const ValueDecl *PrevDepDecl = nullptr) |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5863 | : SemaRef(SemaRef), Stack(Stack), CurLCDecl(CurLCDecl), |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5864 | PrevDepDecl(PrevDepDecl), IsInitializer(IsInitializer) {} |
| 5865 | unsigned getBaseLoopId() const { |
| 5866 | assert(CurLCDecl && "Expected loop dependency."); |
| 5867 | return BaseLoopId; |
| 5868 | } |
| 5869 | const ValueDecl *getDepDecl() const { |
| 5870 | assert(CurLCDecl && "Expected loop dependency."); |
| 5871 | return DepDecl; |
| 5872 | } |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5873 | }; |
| 5874 | } // namespace |
| 5875 | |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5876 | Optional<unsigned> |
| 5877 | OpenMPIterationSpaceChecker::doesDependOnLoopCounter(const Stmt *S, |
| 5878 | bool IsInitializer) { |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5879 | // Check for the non-rectangular loops. |
| Alexey Bataev | 5ddc6d1 | 2019-04-26 19:28:37 +0000 | [diff] [blame] | 5880 | LoopCounterRefChecker LoopStmtChecker(SemaRef, Stack, LCDecl, IsInitializer, |
| 5881 | DepDecl); |
| 5882 | if (LoopStmtChecker.Visit(S)) { |
| 5883 | DepDecl = LoopStmtChecker.getDepDecl(); |
| 5884 | return LoopStmtChecker.getBaseLoopId(); |
| 5885 | } |
| 5886 | return llvm::None; |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5889 | bool OpenMPIterationSpaceChecker::checkAndSetInit(Stmt *S, bool EmitDiags) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5890 | // Check init-expr for canonical loop form and save loop counter |
| 5891 | // variable - #Var and its initialization value - #LB. |
| 5892 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 5893 | // var = lb |
| 5894 | // integer-type var = lb |
| 5895 | // random-access-iterator-type var = lb |
| 5896 | // pointer-type var = lb |
| 5897 | // |
| 5898 | if (!S) { |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5899 | if (EmitDiags) { |
| 5900 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 5901 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5902 | return true; |
| 5903 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 5904 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 5905 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 5906 | S = ExprTemp->getSubExpr(); |
| 5907 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5908 | InitSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5909 | if (Expr *E = dyn_cast<Expr>(S)) |
| 5910 | S = E->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5911 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5912 | if (BO->getOpcode() == BO_Assign) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5913 | Expr *LHS = BO->getLHS()->IgnoreParens(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5914 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 5915 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 5916 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5917 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(), |
| 5918 | EmitDiags); |
| 5919 | return setLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS(), EmitDiags); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5920 | } |
| 5921 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 5922 | if (ME->isArrow() && |
| 5923 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5924 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(), |
| 5925 | EmitDiags); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5926 | } |
| 5927 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5928 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5929 | if (DS->isSingleDecl()) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5930 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5931 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5932 | // Accept non-canonical init form here but emit ext. warning. |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5933 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5934 | SemaRef.Diag(S->getBeginLoc(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5935 | diag::ext_omp_loop_not_canonical_init) |
| 5936 | << S->getSourceRange(); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5937 | return setLCDeclAndLB( |
| 5938 | Var, |
| 5939 | buildDeclRefExpr(SemaRef, Var, |
| 5940 | Var->getType().getNonReferenceType(), |
| 5941 | DS->getBeginLoc()), |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5942 | Var->getInit(), EmitDiags); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5946 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5947 | if (CE->getOperator() == OO_Equal) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5948 | Expr *LHS = CE->getArg(0); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5949 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5950 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 5951 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5952 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(), |
| 5953 | EmitDiags); |
| 5954 | return setLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1), EmitDiags); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5955 | } |
| 5956 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 5957 | if (ME->isArrow() && |
| 5958 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 5959 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS(), |
| 5960 | EmitDiags); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5961 | } |
| 5962 | } |
| 5963 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5964 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5965 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5966 | return false; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5967 | if (EmitDiags) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5968 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_init) |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5969 | << S->getSourceRange(); |
| 5970 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5971 | return true; |
| 5972 | } |
| 5973 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5974 | /// Ignore parenthesizes, implicit casts, copy constructor and return the |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5975 | /// variable (which may be the loop variable) if possible. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5976 | static const ValueDecl *getInitLCDecl(const Expr *E) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5977 | if (!E) |
| Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 5978 | return nullptr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5979 | E = getExprAsWritten(E); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5980 | if (const auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5981 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 5982 | if ((Ctor->isCopyOrMoveConstructor() || |
| 5983 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 5984 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5985 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5986 | if (const auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 5987 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5988 | return getCanonicalDecl(VD); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5989 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5990 | if (const auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 5991 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 5992 | return getCanonicalDecl(ME->getMemberDecl()); |
| 5993 | return nullptr; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5996 | bool OpenMPIterationSpaceChecker::checkAndSetCond(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5997 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 5998 | // less/greater and for strict/non-strict comparison. |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 5999 | // OpenMP [2.9] Canonical loop form. Test-expr may be one of the following: |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6000 | // var relational-op b |
| 6001 | // b relational-op var |
| 6002 | // |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 6003 | bool IneqCondIsCanonical = SemaRef.getLangOpts().OpenMP >= 50; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6004 | if (!S) { |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 6005 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) |
| 6006 | << (IneqCondIsCanonical ? 1 : 0) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6007 | return true; |
| 6008 | } |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6009 | Condition = S; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 6010 | S = getExprAsWritten(S); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6011 | SourceLocation CondLoc = S->getBeginLoc(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6012 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6013 | if (BO->isRelationalOp()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6014 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 6015 | return setUB(BO->getRHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6016 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 6017 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 6018 | BO->getSourceRange(), BO->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6019 | if (getInitLCDecl(BO->getRHS()) == LCDecl) |
| 6020 | return setUB(BO->getLHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6021 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 6022 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 6023 | BO->getSourceRange(), BO->getOperatorLoc()); |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 6024 | } else if (IneqCondIsCanonical && BO->getOpcode() == BO_NE) |
| 6025 | return setUB( |
| 6026 | getInitLCDecl(BO->getLHS()) == LCDecl ? BO->getRHS() : BO->getLHS(), |
| 6027 | /*LessOp=*/llvm::None, |
| 6028 | /*StrictOp=*/true, BO->getSourceRange(), BO->getOperatorLoc()); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6029 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6030 | if (CE->getNumArgs() == 2) { |
| 6031 | auto Op = CE->getOperator(); |
| 6032 | switch (Op) { |
| 6033 | case OO_Greater: |
| 6034 | case OO_GreaterEqual: |
| 6035 | case OO_Less: |
| 6036 | case OO_LessEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6037 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 6038 | return setUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6039 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 6040 | CE->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6041 | if (getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 6042 | return setUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6043 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 6044 | CE->getOperatorLoc()); |
| 6045 | break; |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 6046 | case OO_ExclaimEqual: |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 6047 | if (IneqCondIsCanonical) |
| 6048 | return setUB(getInitLCDecl(CE->getArg(0)) == LCDecl ? CE->getArg(1) |
| 6049 | : CE->getArg(0), |
| 6050 | /*LessOp=*/llvm::None, |
| 6051 | /*StrictOp=*/true, CE->getSourceRange(), |
| 6052 | CE->getOperatorLoc()); |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 6053 | break; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6054 | default: |
| 6055 | break; |
| 6056 | } |
| 6057 | } |
| 6058 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6059 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6060 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6061 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| Alexey Bataev | 1be6340 | 2019-09-11 15:44:06 +0000 | [diff] [blame] | 6062 | << (IneqCondIsCanonical ? 1 : 0) << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6063 | return true; |
| 6064 | } |
| 6065 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6066 | bool OpenMPIterationSpaceChecker::checkAndSetIncRHS(Expr *RHS) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6067 | // RHS of canonical loop form increment can be: |
| 6068 | // var + incr |
| 6069 | // incr + var |
| 6070 | // var - incr |
| 6071 | // |
| 6072 | RHS = RHS->IgnoreParenImpCasts(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6073 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6074 | if (BO->isAdditiveOp()) { |
| 6075 | bool IsAdd = BO->getOpcode() == BO_Add; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6076 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 6077 | return setStep(BO->getRHS(), !IsAdd); |
| 6078 | if (IsAdd && getInitLCDecl(BO->getRHS()) == LCDecl) |
| 6079 | return setStep(BO->getLHS(), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6080 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6081 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6082 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 6083 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6084 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 6085 | return setStep(CE->getArg(1), !IsAdd); |
| 6086 | if (IsAdd && getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 6087 | return setStep(CE->getArg(0), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6088 | } |
| 6089 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6090 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6091 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6092 | SemaRef.Diag(RHS->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6093 | << RHS->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6094 | return true; |
| 6095 | } |
| 6096 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6097 | bool OpenMPIterationSpaceChecker::checkAndSetInc(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6098 | // Check incr-expr for canonical loop form and return true if it |
| 6099 | // does not conform. |
| 6100 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 6101 | // ++var |
| 6102 | // var++ |
| 6103 | // --var |
| 6104 | // var-- |
| 6105 | // var += incr |
| 6106 | // var -= incr |
| 6107 | // var = var + incr |
| 6108 | // var = incr + var |
| 6109 | // var = var - incr |
| 6110 | // |
| 6111 | if (!S) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6112 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6113 | return true; |
| 6114 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 6115 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 6116 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 6117 | S = ExprTemp->getSubExpr(); |
| 6118 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6119 | IncrementSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6120 | S = S->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6121 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6122 | if (UO->isIncrementDecrementOp() && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6123 | getInitLCDecl(UO->getSubExpr()) == LCDecl) |
| 6124 | return setStep(SemaRef |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6125 | .ActOnIntegerConstant(UO->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6126 | (UO->isDecrementOp() ? -1 : 1)) |
| 6127 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6128 | /*Subtract=*/false); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6129 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6130 | switch (BO->getOpcode()) { |
| 6131 | case BO_AddAssign: |
| 6132 | case BO_SubAssign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6133 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 6134 | return setStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6135 | break; |
| 6136 | case BO_Assign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6137 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 6138 | return checkAndSetIncRHS(BO->getRHS()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6139 | break; |
| 6140 | default: |
| 6141 | break; |
| 6142 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6143 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6144 | switch (CE->getOperator()) { |
| 6145 | case OO_PlusPlus: |
| 6146 | case OO_MinusMinus: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6147 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 6148 | return setStep(SemaRef |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6149 | .ActOnIntegerConstant( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6150 | CE->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6151 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 6152 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6153 | /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6154 | break; |
| 6155 | case OO_PlusEqual: |
| 6156 | case OO_MinusEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6157 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 6158 | return setStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6159 | break; |
| 6160 | case OO_Equal: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6161 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 6162 | return checkAndSetIncRHS(CE->getArg(1)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6163 | break; |
| 6164 | default: |
| 6165 | break; |
| 6166 | } |
| 6167 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6168 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6169 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6170 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6171 | << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6172 | return true; |
| 6173 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6174 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6175 | static ExprResult |
| 6176 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6177 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 6178 | if (SemaRef.CurContext->isDependentContext()) |
| 6179 | return ExprResult(Capture); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6180 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 6181 | return SemaRef.PerformImplicitConversion( |
| 6182 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 6183 | /*AllowExplicit=*/true); |
| 6184 | auto I = Captures.find(Capture); |
| 6185 | if (I != Captures.end()) |
| 6186 | return buildCapture(SemaRef, Capture, I->second); |
| 6187 | DeclRefExpr *Ref = nullptr; |
| 6188 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 6189 | Captures[Capture] = Ref; |
| 6190 | return Res; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6191 | } |
| 6192 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6193 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6194 | Expr *OpenMPIterationSpaceChecker::buildNumIterations( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6195 | Scope *S, ArrayRef<LoopIterationSpace> ResultIterSpaces, bool LimitedType, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6196 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6197 | ExprResult Diff; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6198 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6199 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6200 | SemaRef.getLangOpts().CPlusPlus) { |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6201 | Expr *LBVal = LB; |
| 6202 | Expr *UBVal = UB; |
| 6203 | // LB = TestIsLessOp.getValue() ? min(LB(MinVal), LB(MaxVal)) : |
| 6204 | // max(LB(MinVal), LB(MaxVal)) |
| 6205 | if (InitDependOnLC) { |
| 6206 | const LoopIterationSpace &IS = |
| 6207 | ResultIterSpaces[ResultIterSpaces.size() - 1 - |
| 6208 | InitDependOnLC.getValueOr( |
| 6209 | CondDependOnLC.getValueOr(0))]; |
| 6210 | if (!IS.MinValue || !IS.MaxValue) |
| 6211 | return nullptr; |
| 6212 | // OuterVar = Min |
| 6213 | ExprResult MinValue = |
| 6214 | SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, IS.MinValue); |
| 6215 | if (!MinValue.isUsable()) |
| 6216 | return nullptr; |
| 6217 | |
| 6218 | ExprResult LBMinVal = SemaRef.BuildBinOp(S, DefaultLoc, BO_Assign, |
| 6219 | IS.CounterVar, MinValue.get()); |
| 6220 | if (!LBMinVal.isUsable()) |
| 6221 | return nullptr; |
| 6222 | // OuterVar = Min, LBVal |
| 6223 | LBMinVal = |
| 6224 | SemaRef.BuildBinOp(S, DefaultLoc, BO_Comma, LBMinVal.get(), LBVal); |
| 6225 | if (!LBMinVal.isUsable()) |
| 6226 | return nullptr; |
| 6227 | // (OuterVar = Min, LBVal) |
| 6228 | LBMinVal = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, LBMinVal.get()); |
| 6229 | if (!LBMinVal.isUsable()) |
| 6230 | return nullptr; |
| 6231 | |
| 6232 | // OuterVar = Max |
| 6233 | ExprResult MaxValue = |
| 6234 | SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, IS.MaxValue); |
| 6235 | if (!MaxValue.isUsable()) |
| 6236 | return nullptr; |
| 6237 | |
| 6238 | ExprResult LBMaxVal = SemaRef.BuildBinOp(S, DefaultLoc, BO_Assign, |
| 6239 | IS.CounterVar, MaxValue.get()); |
| 6240 | if (!LBMaxVal.isUsable()) |
| 6241 | return nullptr; |
| 6242 | // OuterVar = Max, LBVal |
| 6243 | LBMaxVal = |
| 6244 | SemaRef.BuildBinOp(S, DefaultLoc, BO_Comma, LBMaxVal.get(), LBVal); |
| 6245 | if (!LBMaxVal.isUsable()) |
| 6246 | return nullptr; |
| 6247 | // (OuterVar = Max, LBVal) |
| 6248 | LBMaxVal = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, LBMaxVal.get()); |
| 6249 | if (!LBMaxVal.isUsable()) |
| 6250 | return nullptr; |
| 6251 | |
| 6252 | Expr *LBMin = tryBuildCapture(SemaRef, LBMinVal.get(), Captures).get(); |
| 6253 | Expr *LBMax = tryBuildCapture(SemaRef, LBMaxVal.get(), Captures).get(); |
| 6254 | if (!LBMin || !LBMax) |
| 6255 | return nullptr; |
| 6256 | // LB(MinVal) < LB(MaxVal) |
| 6257 | ExprResult MinLessMaxRes = |
| 6258 | SemaRef.BuildBinOp(S, DefaultLoc, BO_LT, LBMin, LBMax); |
| 6259 | if (!MinLessMaxRes.isUsable()) |
| 6260 | return nullptr; |
| 6261 | Expr *MinLessMax = |
| 6262 | tryBuildCapture(SemaRef, MinLessMaxRes.get(), Captures).get(); |
| 6263 | if (!MinLessMax) |
| 6264 | return nullptr; |
| 6265 | if (TestIsLessOp.getValue()) { |
| 6266 | // LB(MinVal) < LB(MaxVal) ? LB(MinVal) : LB(MaxVal) - min(LB(MinVal), |
| 6267 | // LB(MaxVal)) |
| 6268 | ExprResult MinLB = SemaRef.ActOnConditionalOp(DefaultLoc, DefaultLoc, |
| 6269 | MinLessMax, LBMin, LBMax); |
| 6270 | if (!MinLB.isUsable()) |
| 6271 | return nullptr; |
| 6272 | LBVal = MinLB.get(); |
| 6273 | } else { |
| 6274 | // LB(MinVal) < LB(MaxVal) ? LB(MaxVal) : LB(MinVal) - max(LB(MinVal), |
| 6275 | // LB(MaxVal)) |
| 6276 | ExprResult MaxLB = SemaRef.ActOnConditionalOp(DefaultLoc, DefaultLoc, |
| 6277 | MinLessMax, LBMax, LBMin); |
| 6278 | if (!MaxLB.isUsable()) |
| 6279 | return nullptr; |
| 6280 | LBVal = MaxLB.get(); |
| 6281 | } |
| 6282 | } |
| 6283 | // UB = TestIsLessOp.getValue() ? max(UB(MinVal), UB(MaxVal)) : |
| 6284 | // min(UB(MinVal), UB(MaxVal)) |
| 6285 | if (CondDependOnLC) { |
| 6286 | const LoopIterationSpace &IS = |
| 6287 | ResultIterSpaces[ResultIterSpaces.size() - 1 - |
| 6288 | InitDependOnLC.getValueOr( |
| 6289 | CondDependOnLC.getValueOr(0))]; |
| 6290 | if (!IS.MinValue || !IS.MaxValue) |
| 6291 | return nullptr; |
| 6292 | // OuterVar = Min |
| 6293 | ExprResult MinValue = |
| 6294 | SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, IS.MinValue); |
| 6295 | if (!MinValue.isUsable()) |
| 6296 | return nullptr; |
| 6297 | |
| 6298 | ExprResult UBMinVal = SemaRef.BuildBinOp(S, DefaultLoc, BO_Assign, |
| 6299 | IS.CounterVar, MinValue.get()); |
| 6300 | if (!UBMinVal.isUsable()) |
| 6301 | return nullptr; |
| 6302 | // OuterVar = Min, UBVal |
| 6303 | UBMinVal = |
| 6304 | SemaRef.BuildBinOp(S, DefaultLoc, BO_Comma, UBMinVal.get(), UBVal); |
| 6305 | if (!UBMinVal.isUsable()) |
| 6306 | return nullptr; |
| 6307 | // (OuterVar = Min, UBVal) |
| 6308 | UBMinVal = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, UBMinVal.get()); |
| 6309 | if (!UBMinVal.isUsable()) |
| 6310 | return nullptr; |
| 6311 | |
| 6312 | // OuterVar = Max |
| 6313 | ExprResult MaxValue = |
| 6314 | SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, IS.MaxValue); |
| 6315 | if (!MaxValue.isUsable()) |
| 6316 | return nullptr; |
| 6317 | |
| 6318 | ExprResult UBMaxVal = SemaRef.BuildBinOp(S, DefaultLoc, BO_Assign, |
| 6319 | IS.CounterVar, MaxValue.get()); |
| 6320 | if (!UBMaxVal.isUsable()) |
| 6321 | return nullptr; |
| 6322 | // OuterVar = Max, UBVal |
| 6323 | UBMaxVal = |
| 6324 | SemaRef.BuildBinOp(S, DefaultLoc, BO_Comma, UBMaxVal.get(), UBVal); |
| 6325 | if (!UBMaxVal.isUsable()) |
| 6326 | return nullptr; |
| 6327 | // (OuterVar = Max, UBVal) |
| 6328 | UBMaxVal = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, UBMaxVal.get()); |
| 6329 | if (!UBMaxVal.isUsable()) |
| 6330 | return nullptr; |
| 6331 | |
| 6332 | Expr *UBMin = tryBuildCapture(SemaRef, UBMinVal.get(), Captures).get(); |
| 6333 | Expr *UBMax = tryBuildCapture(SemaRef, UBMaxVal.get(), Captures).get(); |
| 6334 | if (!UBMin || !UBMax) |
| 6335 | return nullptr; |
| 6336 | // UB(MinVal) > UB(MaxVal) |
| 6337 | ExprResult MinGreaterMaxRes = |
| 6338 | SemaRef.BuildBinOp(S, DefaultLoc, BO_GT, UBMin, UBMax); |
| 6339 | if (!MinGreaterMaxRes.isUsable()) |
| 6340 | return nullptr; |
| 6341 | Expr *MinGreaterMax = |
| 6342 | tryBuildCapture(SemaRef, MinGreaterMaxRes.get(), Captures).get(); |
| 6343 | if (!MinGreaterMax) |
| 6344 | return nullptr; |
| 6345 | if (TestIsLessOp.getValue()) { |
| 6346 | // UB(MinVal) > UB(MaxVal) ? UB(MinVal) : UB(MaxVal) - max(UB(MinVal), |
| 6347 | // UB(MaxVal)) |
| 6348 | ExprResult MaxUB = SemaRef.ActOnConditionalOp( |
| 6349 | DefaultLoc, DefaultLoc, MinGreaterMax, UBMin, UBMax); |
| 6350 | if (!MaxUB.isUsable()) |
| 6351 | return nullptr; |
| 6352 | UBVal = MaxUB.get(); |
| 6353 | } else { |
| 6354 | // UB(MinVal) > UB(MaxVal) ? UB(MaxVal) : UB(MinVal) - min(UB(MinVal), |
| 6355 | // UB(MaxVal)) |
| 6356 | ExprResult MinUB = SemaRef.ActOnConditionalOp( |
| 6357 | DefaultLoc, DefaultLoc, MinGreaterMax, UBMax, UBMin); |
| 6358 | if (!MinUB.isUsable()) |
| 6359 | return nullptr; |
| 6360 | UBVal = MinUB.get(); |
| 6361 | } |
| 6362 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6363 | // Upper - Lower |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6364 | Expr *UBExpr = TestIsLessOp.getValue() ? UBVal : LBVal; |
| 6365 | Expr *LBExpr = TestIsLessOp.getValue() ? LBVal : UBVal; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6366 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 6367 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6368 | if (!Upper || !Lower) |
| 6369 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6370 | |
| 6371 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 6372 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6373 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6374 | // BuildBinOp already emitted error, this one is to point user to upper |
| 6375 | // and lower bound, and to tell what is passed to 'operator-'. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6376 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6377 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 6378 | return nullptr; |
| 6379 | } |
| 6380 | } |
| 6381 | |
| 6382 | if (!Diff.isUsable()) |
| 6383 | return nullptr; |
| 6384 | |
| 6385 | // Upper - Lower [- 1] |
| 6386 | if (TestIsStrictOp) |
| 6387 | Diff = SemaRef.BuildBinOp( |
| 6388 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 6389 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 6390 | if (!Diff.isUsable()) |
| 6391 | return nullptr; |
| 6392 | |
| 6393 | // Upper - Lower [- 1] + Step |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6394 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6395 | if (!NewStep.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6396 | return nullptr; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6397 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6398 | if (!Diff.isUsable()) |
| 6399 | return nullptr; |
| 6400 | |
| 6401 | // Parentheses (for dumping/debugging purposes only). |
| 6402 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 6403 | if (!Diff.isUsable()) |
| 6404 | return nullptr; |
| 6405 | |
| 6406 | // (Upper - Lower [- 1] + Step) / Step |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6407 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6408 | if (!Diff.isUsable()) |
| 6409 | return nullptr; |
| 6410 | |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 6411 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6412 | QualType Type = Diff.get()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6413 | ASTContext &C = SemaRef.Context; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6414 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 6415 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 6416 | if (!Type->isIntegerType() || UseVarType) { |
| 6417 | unsigned NewSize = |
| 6418 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 6419 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 6420 | : Type->hasSignedIntegerRepresentation(); |
| 6421 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 6422 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 6423 | Diff = SemaRef.PerformImplicitConversion( |
| 6424 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 6425 | if (!Diff.isUsable()) |
| 6426 | return nullptr; |
| 6427 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6428 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 6429 | if (LimitedType) { |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 6430 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 6431 | if (NewSize != C.getTypeSize(Type)) { |
| 6432 | if (NewSize < C.getTypeSize(Type)) { |
| 6433 | assert(NewSize == 64 && "incorrect loop var size"); |
| 6434 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 6435 | << InitSrcRange << ConditionSrcRange; |
| 6436 | } |
| 6437 | QualType NewType = C.getIntTypeForBitwidth( |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6438 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 6439 | C.getTypeSize(Type) < NewSize); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 6440 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 6441 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 6442 | Sema::AA_Converting, true); |
| 6443 | if (!Diff.isUsable()) |
| 6444 | return nullptr; |
| 6445 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 6446 | } |
| 6447 | } |
| 6448 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6449 | return Diff.get(); |
| 6450 | } |
| 6451 | |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6452 | std::pair<Expr *, Expr *> OpenMPIterationSpaceChecker::buildMinMaxValues( |
| 6453 | Scope *S, llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| 6454 | // Do not build for iterators, they cannot be used in non-rectangular loop |
| 6455 | // nests. |
| 6456 | if (LCDecl->getType()->isRecordType()) |
| 6457 | return std::make_pair(nullptr, nullptr); |
| 6458 | // If we subtract, the min is in the condition, otherwise the min is in the |
| 6459 | // init value. |
| 6460 | Expr *MinExpr = nullptr; |
| 6461 | Expr *MaxExpr = nullptr; |
| 6462 | Expr *LBExpr = TestIsLessOp.getValue() ? LB : UB; |
| 6463 | Expr *UBExpr = TestIsLessOp.getValue() ? UB : LB; |
| 6464 | bool LBNonRect = TestIsLessOp.getValue() ? InitDependOnLC.hasValue() |
| 6465 | : CondDependOnLC.hasValue(); |
| 6466 | bool UBNonRect = TestIsLessOp.getValue() ? CondDependOnLC.hasValue() |
| 6467 | : InitDependOnLC.hasValue(); |
| 6468 | Expr *Lower = |
| 6469 | LBNonRect ? LBExpr : tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
| 6470 | Expr *Upper = |
| 6471 | UBNonRect ? UBExpr : tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 6472 | if (!Upper || !Lower) |
| 6473 | return std::make_pair(nullptr, nullptr); |
| 6474 | |
| 6475 | if (TestIsLessOp.getValue()) |
| 6476 | MinExpr = Lower; |
| 6477 | else |
| 6478 | MaxExpr = Upper; |
| 6479 | |
| 6480 | // Build minimum/maximum value based on number of iterations. |
| 6481 | ExprResult Diff; |
| 6482 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| 6483 | |
| 6484 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 6485 | if (!Diff.isUsable()) |
| 6486 | return std::make_pair(nullptr, nullptr); |
| 6487 | |
| 6488 | // Upper - Lower [- 1] |
| 6489 | if (TestIsStrictOp) |
| 6490 | Diff = SemaRef.BuildBinOp( |
| 6491 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 6492 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 6493 | if (!Diff.isUsable()) |
| 6494 | return std::make_pair(nullptr, nullptr); |
| 6495 | |
| 6496 | // Upper - Lower [- 1] + Step |
| 6497 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 6498 | if (!NewStep.isUsable()) |
| 6499 | return std::make_pair(nullptr, nullptr); |
| 6500 | |
| 6501 | // Parentheses (for dumping/debugging purposes only). |
| 6502 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 6503 | if (!Diff.isUsable()) |
| 6504 | return std::make_pair(nullptr, nullptr); |
| 6505 | |
| 6506 | // (Upper - Lower [- 1]) / Step |
| 6507 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| 6508 | if (!Diff.isUsable()) |
| 6509 | return std::make_pair(nullptr, nullptr); |
| 6510 | |
| 6511 | // ((Upper - Lower [- 1]) / Step) * Step |
| 6512 | // Parentheses (for dumping/debugging purposes only). |
| 6513 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 6514 | if (!Diff.isUsable()) |
| 6515 | return std::make_pair(nullptr, nullptr); |
| 6516 | |
| 6517 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Mul, Diff.get(), NewStep.get()); |
| 6518 | if (!Diff.isUsable()) |
| 6519 | return std::make_pair(nullptr, nullptr); |
| 6520 | |
| 6521 | // Convert to the original type or ptrdiff_t, if original type is pointer. |
| 6522 | if (!VarType->isAnyPointerType() && |
| 6523 | !SemaRef.Context.hasSameType(Diff.get()->getType(), VarType)) { |
| 6524 | Diff = SemaRef.PerformImplicitConversion( |
| 6525 | Diff.get(), VarType, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 6526 | } else if (VarType->isAnyPointerType() && |
| 6527 | !SemaRef.Context.hasSameType( |
| 6528 | Diff.get()->getType(), |
| 6529 | SemaRef.Context.getUnsignedPointerDiffType())) { |
| 6530 | Diff = SemaRef.PerformImplicitConversion( |
| 6531 | Diff.get(), SemaRef.Context.getUnsignedPointerDiffType(), |
| 6532 | Sema::AA_Converting, /*AllowExplicit=*/true); |
| 6533 | } |
| 6534 | if (!Diff.isUsable()) |
| 6535 | return std::make_pair(nullptr, nullptr); |
| 6536 | |
| 6537 | // Parentheses (for dumping/debugging purposes only). |
| 6538 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 6539 | if (!Diff.isUsable()) |
| 6540 | return std::make_pair(nullptr, nullptr); |
| 6541 | |
| 6542 | if (TestIsLessOp.getValue()) { |
| 6543 | // MinExpr = Lower; |
| 6544 | // MaxExpr = Lower + (((Upper - Lower [- 1]) / Step) * Step) |
| 6545 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Lower, Diff.get()); |
| 6546 | if (!Diff.isUsable()) |
| 6547 | return std::make_pair(nullptr, nullptr); |
| 6548 | Diff = SemaRef.ActOnFinishFullExpr(Diff.get(), /*DiscardedValue*/ false); |
| 6549 | if (!Diff.isUsable()) |
| 6550 | return std::make_pair(nullptr, nullptr); |
| 6551 | MaxExpr = Diff.get(); |
| 6552 | } else { |
| 6553 | // MaxExpr = Upper; |
| 6554 | // MinExpr = Upper - (((Upper - Lower [- 1]) / Step) * Step) |
| 6555 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Diff.get()); |
| 6556 | if (!Diff.isUsable()) |
| 6557 | return std::make_pair(nullptr, nullptr); |
| 6558 | Diff = SemaRef.ActOnFinishFullExpr(Diff.get(), /*DiscardedValue*/ false); |
| 6559 | if (!Diff.isUsable()) |
| 6560 | return std::make_pair(nullptr, nullptr); |
| 6561 | MinExpr = Diff.get(); |
| 6562 | } |
| 6563 | |
| 6564 | return std::make_pair(MinExpr, MaxExpr); |
| 6565 | } |
| 6566 | |
| 6567 | Expr *OpenMPIterationSpaceChecker::buildFinalCondition(Scope *S) const { |
| 6568 | if (InitDependOnLC || CondDependOnLC) |
| 6569 | return Condition; |
| 6570 | return nullptr; |
| 6571 | } |
| 6572 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6573 | Expr *OpenMPIterationSpaceChecker::buildPreCond( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6574 | Scope *S, Expr *Cond, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6575 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexey Bataev | 658ad4d | 2019-10-01 16:19:10 +0000 | [diff] [blame] | 6576 | // Do not build a precondition when the condition/initialization is dependent |
| 6577 | // to prevent pessimistic early loop exit. |
| 6578 | // TODO: this can be improved by calculating min/max values but not sure that |
| 6579 | // it will be very effective. |
| 6580 | if (CondDependOnLC || InitDependOnLC) |
| 6581 | return SemaRef.PerformImplicitConversion( |
| 6582 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(), |
| 6583 | SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 6584 | /*AllowExplicit=*/true).get(); |
| 6585 | |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 6586 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| Richard Smith | 2e3ed4a | 2019-08-16 19:53:22 +0000 | [diff] [blame] | 6587 | Sema::TentativeAnalysisScope Trap(SemaRef); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6588 | |
| Alexey Bataev | 658ad4d | 2019-10-01 16:19:10 +0000 | [diff] [blame] | 6589 | ExprResult NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 6590 | ExprResult NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6591 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 6592 | return nullptr; |
| 6593 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6594 | ExprResult CondExpr = |
| 6595 | SemaRef.BuildBinOp(S, DefaultLoc, |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 6596 | TestIsLessOp.getValue() ? |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 6597 | (TestIsStrictOp ? BO_LT : BO_LE) : |
| 6598 | (TestIsStrictOp ? BO_GT : BO_GE), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6599 | NewLB.get(), NewUB.get()); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 6600 | if (CondExpr.isUsable()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6601 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 6602 | SemaRef.Context.BoolTy)) |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 6603 | CondExpr = SemaRef.PerformImplicitConversion( |
| 6604 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 6605 | /*AllowExplicit=*/true); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 6606 | } |
| Richard Smith | 2e3ed4a | 2019-08-16 19:53:22 +0000 | [diff] [blame] | 6607 | |
| Sergi Mateo Bellido | f3e00fe | 2019-02-01 08:39:01 +0000 | [diff] [blame] | 6608 | // Otherwise use original loop condition and evaluate it in runtime. |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 6609 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 6610 | } |
| 6611 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6612 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6613 | DeclRefExpr *OpenMPIterationSpaceChecker::buildCounterVar( |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6614 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 6615 | DSAStackTy &DSA) const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6616 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 6617 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6618 | VD = SemaRef.isOpenMPCapturedDecl(LCDecl); |
| 6619 | DeclRefExpr *Ref = buildDeclRefExpr( |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6620 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6621 | const DSAStackTy::DSAVarData Data = |
| 6622 | DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6623 | // If the loop control decl is explicitly marked as private, do not mark it |
| 6624 | // as captured again. |
| 6625 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 6626 | Captures.insert(std::make_pair(LCRef, Ref)); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6627 | return Ref; |
| 6628 | } |
| Alexey Bataev | 0d8fcdf | 2019-03-14 20:36:00 +0000 | [diff] [blame] | 6629 | return cast<DeclRefExpr>(LCRef); |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 6630 | } |
| 6631 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6632 | Expr *OpenMPIterationSpaceChecker::buildPrivateCounterVar() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6633 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6634 | QualType Type = LCDecl->getType().getNonReferenceType(); |
| 6635 | VarDecl *PrivateVar = buildVarDecl( |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 6636 | SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 6637 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr, |
| 6638 | isa<VarDecl>(LCDecl) |
| 6639 | ? buildDeclRefExpr(SemaRef, cast<VarDecl>(LCDecl), Type, DefaultLoc) |
| 6640 | : nullptr); |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 6641 | if (PrivateVar->isInvalidDecl()) |
| 6642 | return nullptr; |
| 6643 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 6644 | } |
| 6645 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6646 | } |
| 6647 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6648 | /// Build initialization of the counter to be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6649 | Expr *OpenMPIterationSpaceChecker::buildCounterInit() const { return LB; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6650 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6651 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6652 | Expr *OpenMPIterationSpaceChecker::buildCounterStep() const { return Step; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6653 | |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6654 | Expr *OpenMPIterationSpaceChecker::buildOrderedLoopData( |
| 6655 | Scope *S, Expr *Counter, |
| 6656 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, SourceLocation Loc, |
| 6657 | Expr *Inc, OverloadedOperatorKind OOK) { |
| 6658 | Expr *Cnt = SemaRef.DefaultLvalueConversion(Counter).get(); |
| 6659 | if (!Cnt) |
| 6660 | return nullptr; |
| 6661 | if (Inc) { |
| 6662 | assert((OOK == OO_Plus || OOK == OO_Minus) && |
| 6663 | "Expected only + or - operations for depend clauses."); |
| 6664 | BinaryOperatorKind BOK = (OOK == OO_Plus) ? BO_Add : BO_Sub; |
| 6665 | Cnt = SemaRef.BuildBinOp(S, Loc, BOK, Cnt, Inc).get(); |
| 6666 | if (!Cnt) |
| 6667 | return nullptr; |
| 6668 | } |
| 6669 | ExprResult Diff; |
| 6670 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| 6671 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| 6672 | SemaRef.getLangOpts().CPlusPlus) { |
| 6673 | // Upper - Lower |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 6674 | Expr *Upper = TestIsLessOp.getValue() |
| 6675 | ? Cnt |
| 6676 | : tryBuildCapture(SemaRef, UB, Captures).get(); |
| 6677 | Expr *Lower = TestIsLessOp.getValue() |
| 6678 | ? tryBuildCapture(SemaRef, LB, Captures).get() |
| 6679 | : Cnt; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6680 | if (!Upper || !Lower) |
| 6681 | return nullptr; |
| 6682 | |
| 6683 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 6684 | |
| 6685 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| 6686 | // BuildBinOp already emitted error, this one is to point user to upper |
| 6687 | // and lower bound, and to tell what is passed to 'operator-'. |
| 6688 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| 6689 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 6690 | return nullptr; |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | if (!Diff.isUsable()) |
| 6695 | return nullptr; |
| 6696 | |
| 6697 | // Parentheses (for dumping/debugging purposes only). |
| 6698 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 6699 | if (!Diff.isUsable()) |
| 6700 | return nullptr; |
| 6701 | |
| 6702 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 6703 | if (!NewStep.isUsable()) |
| 6704 | return nullptr; |
| 6705 | // (Upper - Lower) / Step |
| 6706 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| 6707 | if (!Diff.isUsable()) |
| 6708 | return nullptr; |
| 6709 | |
| 6710 | return Diff.get(); |
| 6711 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6712 | } // namespace |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6713 | |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 6714 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 6715 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 6716 | assert(Init && "Expected loop in canonical form."); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6717 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 6718 | if (AssociatedLoops > 0 && |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 6719 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| Alexey Bataev | ce90181 | 2018-12-19 18:16:37 +0000 | [diff] [blame] | 6720 | DSAStack->loopStart(); |
| Alexey Bataev | 622af1d | 2019-04-24 19:58:30 +0000 | [diff] [blame] | 6721 | OpenMPIterationSpaceChecker ISC(*this, *DSAStack, ForLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6722 | if (!ISC.checkAndSetInit(Init, /*EmitDiags=*/false)) { |
| 6723 | if (ValueDecl *D = ISC.getLoopDecl()) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6724 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 6725 | DeclRefExpr *PrivateRef = nullptr; |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6726 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6727 | if (VarDecl *Private = isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6728 | VD = Private; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6729 | } else { |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 6730 | PrivateRef = buildCapture(*this, D, ISC.getLoopDeclRefExpr(), |
| 6731 | /*WithInit=*/false); |
| 6732 | VD = cast<VarDecl>(PrivateRef->getDecl()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6733 | } |
| 6734 | } |
| 6735 | DSAStack->addLoopControlVariable(D, VD); |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 6736 | const Decl *LD = DSAStack->getPossiblyLoopCunter(); |
| 6737 | if (LD != D->getCanonicalDecl()) { |
| 6738 | DSAStack->resetPossibleLoopCounter(); |
| 6739 | if (auto *Var = dyn_cast_or_null<VarDecl>(LD)) |
| 6740 | MarkDeclarationsReferencedInExpr( |
| 6741 | buildDeclRefExpr(*this, const_cast<VarDecl *>(Var), |
| 6742 | Var->getType().getNonLValueExprType(Context), |
| 6743 | ForLoc, /*RefersToCapture=*/true)); |
| 6744 | } |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 6745 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 6746 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables |
| 6747 | // Referenced in a Construct, C/C++]. The loop iteration variable in the |
| 6748 | // associated for-loop of a simd construct with just one associated |
| 6749 | // for-loop may be listed in a linear clause with a constant-linear-step |
| 6750 | // that is the increment of the associated for-loop. The loop iteration |
| 6751 | // variable(s) in the associated for-loop(s) of a for or parallel for |
| 6752 | // construct may be listed in a private or lastprivate clause. |
| 6753 | DSAStackTy::DSAVarData DVar = |
| 6754 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| 6755 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable |
| 6756 | // is declared in the loop and it is predetermined as a private. |
| 6757 | Expr *LoopDeclRefExpr = ISC.getLoopDeclRefExpr(); |
| 6758 | OpenMPClauseKind PredeterminedCKind = |
| 6759 | isOpenMPSimdDirective(DKind) |
| 6760 | ? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear) |
| 6761 | : OMPC_private; |
| 6762 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 6763 | DVar.CKind != PredeterminedCKind && DVar.RefExpr && |
| 6764 | (LangOpts.OpenMP <= 45 || (DVar.CKind != OMPC_lastprivate && |
| 6765 | DVar.CKind != OMPC_private))) || |
| 6766 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 6767 | DKind == OMPD_master_taskloop || |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 6768 | DKind == OMPD_parallel_master_taskloop || |
| Alexey Bataev | 05be1da | 2019-07-18 17:49:13 +0000 | [diff] [blame] | 6769 | isOpenMPDistributeDirective(DKind)) && |
| 6770 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 6771 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 6772 | (DVar.CKind != OMPC_private || DVar.RefExpr)) { |
| 6773 | Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa) |
| 6774 | << getOpenMPClauseName(DVar.CKind) |
| 6775 | << getOpenMPDirectiveName(DKind) |
| 6776 | << getOpenMPClauseName(PredeterminedCKind); |
| 6777 | if (DVar.RefExpr == nullptr) |
| 6778 | DVar.CKind = PredeterminedCKind; |
| 6779 | reportOriginalDsa(*this, DSAStack, D, DVar, |
| 6780 | /*IsLoopIterVar=*/true); |
| 6781 | } else if (LoopDeclRefExpr) { |
| 6782 | // Make the loop iteration variable private (for worksharing |
| 6783 | // constructs), linear (for simd directives with the only one |
| 6784 | // associated loop) or lastprivate (for simd directives with several |
| 6785 | // collapsed or ordered loops). |
| 6786 | if (DVar.CKind == OMPC_unknown) |
| 6787 | DSAStack->addDSA(D, LoopDeclRefExpr, PredeterminedCKind, |
| 6788 | PrivateRef); |
| 6789 | } |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6790 | } |
| 6791 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6792 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 6793 | } |
| 6794 | } |
| 6795 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6796 | /// Called on a for stmt to check and extract its iteration space |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6797 | /// for further processing (such as collapsing). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6798 | static bool checkOpenMPIterationSpace( |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6799 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 6800 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6801 | unsigned TotalNestedLoopCount, Expr *CollapseLoopCountExpr, |
| 6802 | Expr *OrderedLoopCountExpr, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6803 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6804 | llvm::MutableArrayRef<LoopIterationSpace> ResultIterSpaces, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6805 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6806 | // OpenMP [2.9.1, Canonical Loop Form] |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6807 | // for (init-expr; test-expr; incr-expr) structured-block |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6808 | // for (range-decl: range-expr) structured-block |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6809 | auto *For = dyn_cast_or_null<ForStmt>(S); |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6810 | auto *CXXFor = dyn_cast_or_null<CXXForRangeStmt>(S); |
| 6811 | // Ranged for is supported only in OpenMP 5.0. |
| 6812 | if (!For && (SemaRef.LangOpts.OpenMP <= 45 || !CXXFor)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6813 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6814 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6815 | << getOpenMPDirectiveName(DKind) << TotalNestedLoopCount |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6816 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6817 | if (TotalNestedLoopCount > 1) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6818 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 6819 | SemaRef.Diag(DSA.getConstructLoc(), |
| 6820 | diag::note_omp_collapse_ordered_expr) |
| 6821 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 6822 | << OrderedLoopCountExpr->getSourceRange(); |
| 6823 | else if (CollapseLoopCountExpr) |
| 6824 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 6825 | diag::note_omp_collapse_ordered_expr) |
| 6826 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 6827 | else |
| 6828 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 6829 | diag::note_omp_collapse_ordered_expr) |
| 6830 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 6831 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6832 | return true; |
| 6833 | } |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6834 | assert(((For && For->getBody()) || (CXXFor && CXXFor->getBody())) && |
| 6835 | "No loop body."); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6836 | |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6837 | OpenMPIterationSpaceChecker ISC(SemaRef, DSA, |
| 6838 | For ? For->getForLoc() : CXXFor->getForLoc()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6839 | |
| 6840 | // Check init. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6841 | Stmt *Init = For ? For->getInit() : CXXFor->getBeginStmt(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6842 | if (ISC.checkAndSetInit(Init)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6843 | return true; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6844 | |
| 6845 | bool HasErrors = false; |
| 6846 | |
| 6847 | // Check loop variable's type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6848 | if (ValueDecl *LCDecl = ISC.getLoopDecl()) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6849 | // OpenMP [2.6, Canonical Loop Form] |
| 6850 | // Var is one of the following: |
| 6851 | // A variable of signed or unsigned integer type. |
| 6852 | // For C++, a variable of a random access iterator type. |
| 6853 | // For C, a variable of a pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6854 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6855 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 6856 | !VarType->isPointerType() && |
| 6857 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6858 | SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_variable_type) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6859 | << SemaRef.getLangOpts().CPlusPlus; |
| 6860 | HasErrors = true; |
| 6861 | } |
| 6862 | |
| 6863 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 6864 | // a Construct |
| 6865 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 6866 | // parallel for construct is (are) private. |
| 6867 | // The loop iteration variable in the associated for-loop of a simd |
| 6868 | // construct with just one associated for-loop is linear with a |
| 6869 | // constant-linear-step that is the increment of the associated for-loop. |
| 6870 | // Exclude loop var from the list of variables with implicitly defined data |
| 6871 | // sharing attributes. |
| 6872 | VarsWithImplicitDSA.erase(LCDecl); |
| 6873 | |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6874 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 6875 | |
| 6876 | // Check test-expr. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6877 | HasErrors |= ISC.checkAndSetCond(For ? For->getCond() : CXXFor->getCond()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 6878 | |
| 6879 | // Check incr-expr. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6880 | HasErrors |= ISC.checkAndSetInc(For ? For->getInc() : CXXFor->getInc()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6883 | if (ISC.dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6884 | return HasErrors; |
| 6885 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6886 | // Build the loop's iteration space representation. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 6887 | ResultIterSpaces[CurrentNestedLoopCount].PreCond = ISC.buildPreCond( |
| 6888 | DSA.getCurScope(), For ? For->getCond() : CXXFor->getCond(), Captures); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6889 | ResultIterSpaces[CurrentNestedLoopCount].NumIterations = |
| 6890 | ISC.buildNumIterations(DSA.getCurScope(), ResultIterSpaces, |
| 6891 | (isOpenMPWorksharingDirective(DKind) || |
| 6892 | isOpenMPTaskLoopDirective(DKind) || |
| 6893 | isOpenMPDistributeDirective(DKind)), |
| 6894 | Captures); |
| 6895 | ResultIterSpaces[CurrentNestedLoopCount].CounterVar = |
| 6896 | ISC.buildCounterVar(Captures, DSA); |
| 6897 | ResultIterSpaces[CurrentNestedLoopCount].PrivateCounterVar = |
| 6898 | ISC.buildPrivateCounterVar(); |
| 6899 | ResultIterSpaces[CurrentNestedLoopCount].CounterInit = ISC.buildCounterInit(); |
| 6900 | ResultIterSpaces[CurrentNestedLoopCount].CounterStep = ISC.buildCounterStep(); |
| 6901 | ResultIterSpaces[CurrentNestedLoopCount].InitSrcRange = ISC.getInitSrcRange(); |
| 6902 | ResultIterSpaces[CurrentNestedLoopCount].CondSrcRange = |
| 6903 | ISC.getConditionSrcRange(); |
| 6904 | ResultIterSpaces[CurrentNestedLoopCount].IncSrcRange = |
| 6905 | ISC.getIncrementSrcRange(); |
| 6906 | ResultIterSpaces[CurrentNestedLoopCount].Subtract = ISC.shouldSubtractStep(); |
| 6907 | ResultIterSpaces[CurrentNestedLoopCount].IsStrictCompare = |
| 6908 | ISC.isStrictTestOp(); |
| 6909 | std::tie(ResultIterSpaces[CurrentNestedLoopCount].MinValue, |
| 6910 | ResultIterSpaces[CurrentNestedLoopCount].MaxValue) = |
| 6911 | ISC.buildMinMaxValues(DSA.getCurScope(), Captures); |
| 6912 | ResultIterSpaces[CurrentNestedLoopCount].FinalCondition = |
| 6913 | ISC.buildFinalCondition(DSA.getCurScope()); |
| 6914 | ResultIterSpaces[CurrentNestedLoopCount].IsNonRectangularLB = |
| 6915 | ISC.doesInitDependOnLC(); |
| 6916 | ResultIterSpaces[CurrentNestedLoopCount].IsNonRectangularUB = |
| 6917 | ISC.doesCondDependOnLC(); |
| 6918 | ResultIterSpaces[CurrentNestedLoopCount].LoopDependentIdx = |
| 6919 | ISC.getLoopDependentIdx(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6920 | |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6921 | HasErrors |= |
| 6922 | (ResultIterSpaces[CurrentNestedLoopCount].PreCond == nullptr || |
| 6923 | ResultIterSpaces[CurrentNestedLoopCount].NumIterations == nullptr || |
| 6924 | ResultIterSpaces[CurrentNestedLoopCount].CounterVar == nullptr || |
| 6925 | ResultIterSpaces[CurrentNestedLoopCount].PrivateCounterVar == nullptr || |
| 6926 | ResultIterSpaces[CurrentNestedLoopCount].CounterInit == nullptr || |
| 6927 | ResultIterSpaces[CurrentNestedLoopCount].CounterStep == nullptr); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6928 | if (!HasErrors && DSA.isOrderedRegion()) { |
| 6929 | if (DSA.getOrderedRegionParam().second->getNumForLoops()) { |
| 6930 | if (CurrentNestedLoopCount < |
| 6931 | DSA.getOrderedRegionParam().second->getLoopNumIterations().size()) { |
| 6932 | DSA.getOrderedRegionParam().second->setLoopNumIterations( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6933 | CurrentNestedLoopCount, |
| 6934 | ResultIterSpaces[CurrentNestedLoopCount].NumIterations); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6935 | DSA.getOrderedRegionParam().second->setLoopCounter( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6936 | CurrentNestedLoopCount, |
| 6937 | ResultIterSpaces[CurrentNestedLoopCount].CounterVar); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6938 | } |
| 6939 | } |
| 6940 | for (auto &Pair : DSA.getDoacrossDependClauses()) { |
| 6941 | if (CurrentNestedLoopCount >= Pair.first->getNumLoops()) { |
| 6942 | // Erroneous case - clause has some problems. |
| 6943 | continue; |
| 6944 | } |
| 6945 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_sink && |
| 6946 | Pair.second.size() <= CurrentNestedLoopCount) { |
| 6947 | // Erroneous case - clause has some problems. |
| 6948 | Pair.first->setLoopData(CurrentNestedLoopCount, nullptr); |
| 6949 | continue; |
| 6950 | } |
| 6951 | Expr *CntValue; |
| 6952 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 6953 | CntValue = ISC.buildOrderedLoopData( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6954 | DSA.getCurScope(), |
| 6955 | ResultIterSpaces[CurrentNestedLoopCount].CounterVar, Captures, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6956 | Pair.first->getDependencyLoc()); |
| 6957 | else |
| 6958 | CntValue = ISC.buildOrderedLoopData( |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6959 | DSA.getCurScope(), |
| 6960 | ResultIterSpaces[CurrentNestedLoopCount].CounterVar, Captures, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6961 | Pair.first->getDependencyLoc(), |
| 6962 | Pair.second[CurrentNestedLoopCount].first, |
| 6963 | Pair.second[CurrentNestedLoopCount].second); |
| 6964 | Pair.first->setLoopData(CurrentNestedLoopCount, CntValue); |
| 6965 | } |
| 6966 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6967 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6968 | return HasErrors; |
| 6969 | } |
| 6970 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6971 | /// Build 'VarRef = Start. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6972 | static ExprResult |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6973 | buildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6974 | ExprResult Start, bool IsNonRectangularLB, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6975 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6976 | // Build 'VarRef = Start. |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 6977 | ExprResult NewStart = IsNonRectangularLB |
| 6978 | ? Start.get() |
| 6979 | : tryBuildCapture(SemaRef, Start.get(), Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6980 | if (!NewStart.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6981 | return ExprError(); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 6982 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 6983 | VarRef.get()->getType())) { |
| 6984 | NewStart = SemaRef.PerformImplicitConversion( |
| 6985 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 6986 | /*AllowExplicit=*/true); |
| 6987 | if (!NewStart.isUsable()) |
| 6988 | return ExprError(); |
| 6989 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6990 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6991 | ExprResult Init = |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 6992 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 6993 | return Init; |
| 6994 | } |
| 6995 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6996 | /// Build 'VarRef = Start + Iter * Step'. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6997 | static ExprResult buildCounterUpdate( |
| 6998 | Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 6999 | ExprResult Start, ExprResult Iter, ExprResult Step, bool Subtract, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7000 | bool IsNonRectangularLB, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7001 | llvm::MapVector<const Expr *, DeclRefExpr *> *Captures = nullptr) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7002 | // Add parentheses (for debugging purposes only). |
| 7003 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 7004 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 7005 | !Step.isUsable()) |
| 7006 | return ExprError(); |
| 7007 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7008 | ExprResult NewStep = Step; |
| 7009 | if (Captures) |
| 7010 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7011 | if (NewStep.isInvalid()) |
| 7012 | return ExprError(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7013 | ExprResult Update = |
| 7014 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7015 | if (!Update.isUsable()) |
| 7016 | return ExprError(); |
| 7017 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7018 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 7019 | // 'VarRef = Start (+|-) Iter * Step'. |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7020 | if (!Start.isUsable()) |
| 7021 | return ExprError(); |
| 7022 | ExprResult NewStart = SemaRef.ActOnParenExpr(Loc, Loc, Start.get()); |
| 7023 | if (!NewStart.isUsable()) |
| 7024 | return ExprError(); |
| 7025 | if (Captures && !IsNonRectangularLB) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7026 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7027 | if (NewStart.isInvalid()) |
| 7028 | return ExprError(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7029 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7030 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 7031 | ExprResult SavedUpdate = Update; |
| 7032 | ExprResult UpdateVal; |
| 7033 | if (VarRef.get()->getType()->isOverloadableType() || |
| 7034 | NewStart.get()->getType()->isOverloadableType() || |
| 7035 | Update.get()->getType()->isOverloadableType()) { |
| Richard Smith | 2e3ed4a | 2019-08-16 19:53:22 +0000 | [diff] [blame] | 7036 | Sema::TentativeAnalysisScope Trap(SemaRef); |
| 7037 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7038 | Update = |
| 7039 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 7040 | if (Update.isUsable()) { |
| 7041 | UpdateVal = |
| 7042 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 7043 | VarRef.get(), SavedUpdate.get()); |
| 7044 | if (UpdateVal.isUsable()) { |
| 7045 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 7046 | UpdateVal.get()); |
| 7047 | } |
| 7048 | } |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7049 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7050 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7051 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 7052 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 7053 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 7054 | NewStart.get(), SavedUpdate.get()); |
| 7055 | if (!Update.isUsable()) |
| 7056 | return ExprError(); |
| 7057 | |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 7058 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 7059 | VarRef.get()->getType())) { |
| 7060 | Update = SemaRef.PerformImplicitConversion( |
| 7061 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 7062 | if (!Update.isUsable()) |
| 7063 | return ExprError(); |
| 7064 | } |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 7065 | |
| 7066 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 7067 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7068 | return Update; |
| 7069 | } |
| 7070 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7071 | /// Convert integer expression \a E to make it have at least \a Bits |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7072 | /// bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7073 | static ExprResult widenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7074 | if (E == nullptr) |
| 7075 | return ExprError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7076 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7077 | QualType OldType = E->getType(); |
| 7078 | unsigned HasBits = C.getTypeSize(OldType); |
| 7079 | if (HasBits >= Bits) |
| 7080 | return ExprResult(E); |
| 7081 | // OK to convert to signed, because new type has more bits than old. |
| 7082 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 7083 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 7084 | true); |
| 7085 | } |
| 7086 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7087 | /// Check if the given expression \a E is a constant integer that fits |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7088 | /// into \a Bits bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7089 | static bool fitsInto(unsigned Bits, bool Signed, const Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7090 | if (E == nullptr) |
| 7091 | return false; |
| 7092 | llvm::APSInt Result; |
| 7093 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 7094 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 7095 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7098 | /// Build preinits statement for the given declarations. |
| 7099 | static Stmt *buildPreInits(ASTContext &Context, |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 7100 | MutableArrayRef<Decl *> PreInits) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7101 | if (!PreInits.empty()) { |
| 7102 | return new (Context) DeclStmt( |
| 7103 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 7104 | SourceLocation(), SourceLocation()); |
| 7105 | } |
| 7106 | return nullptr; |
| 7107 | } |
| 7108 | |
| 7109 | /// Build preinits statement for the given declarations. |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 7110 | static Stmt * |
| 7111 | buildPreInits(ASTContext &Context, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7112 | const llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7113 | if (!Captures.empty()) { |
| 7114 | SmallVector<Decl *, 16> PreInits; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7115 | for (const auto &Pair : Captures) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7116 | PreInits.push_back(Pair.second->getDecl()); |
| 7117 | return buildPreInits(Context, PreInits); |
| 7118 | } |
| 7119 | return nullptr; |
| 7120 | } |
| 7121 | |
| 7122 | /// Build postupdate expression for the given list of postupdates expressions. |
| 7123 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 7124 | Expr *PostUpdate = nullptr; |
| 7125 | if (!PostUpdates.empty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7126 | for (Expr *E : PostUpdates) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7127 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 7128 | E->getExprLoc(), |
| 7129 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 7130 | E->getExprLoc(), E) |
| 7131 | .get(); |
| 7132 | PostUpdate = PostUpdate |
| 7133 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 7134 | PostUpdate, ConvE) |
| 7135 | .get() |
| 7136 | : ConvE; |
| 7137 | } |
| 7138 | } |
| 7139 | return PostUpdate; |
| 7140 | } |
| 7141 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7142 | /// Called on a for stmt to check itself and nested loops (if any). |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 7143 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 7144 | /// number of collapsed loops otherwise. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7145 | static unsigned |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7146 | checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7147 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 7148 | DSAStackTy &DSA, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7149 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7150 | OMPLoopDirective::HelperExprs &Built) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 7151 | unsigned NestedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7152 | if (CollapseLoopCountExpr) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 7153 | // Found 'collapse' clause - calculate collapse number. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 7154 | Expr::EvalResult Result; |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7155 | if (!CollapseLoopCountExpr->isValueDependent() && |
| 7156 | CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 7157 | NestedLoopCount = Result.Val.getInt().getLimitedValue(); |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7158 | } else { |
| Rui Ueyama | 49a3ad2 | 2019-07-16 04:46:31 +0000 | [diff] [blame] | 7159 | Built.clear(/*Size=*/1); |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7160 | return 1; |
| 7161 | } |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7162 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7163 | unsigned OrderedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7164 | if (OrderedLoopCountExpr) { |
| 7165 | // Found 'ordered' clause - calculate collapse number. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 7166 | Expr::EvalResult EVResult; |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7167 | if (!OrderedLoopCountExpr->isValueDependent() && |
| 7168 | OrderedLoopCountExpr->EvaluateAsInt(EVResult, |
| 7169 | SemaRef.getASTContext())) { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 7170 | llvm::APSInt Result = EVResult.Val.getInt(); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7171 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 7172 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 7173 | diag::err_omp_wrong_ordered_loop_count) |
| 7174 | << OrderedLoopCountExpr->getSourceRange(); |
| 7175 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 7176 | diag::note_collapse_loop_count) |
| 7177 | << CollapseLoopCountExpr->getSourceRange(); |
| 7178 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7179 | OrderedLoopCount = Result.getLimitedValue(); |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7180 | } else { |
| Rui Ueyama | 49a3ad2 | 2019-07-16 04:46:31 +0000 | [diff] [blame] | 7181 | Built.clear(/*Size=*/1); |
| Dmitri Gribenko | 04323c2 | 2019-05-17 17:16:53 +0000 | [diff] [blame] | 7182 | return 1; |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7183 | } |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 7184 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7185 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 7186 | // 'for simd', etc.). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7187 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7188 | SmallVector<LoopIterationSpace, 4> IterSpaces( |
| 7189 | std::max(OrderedLoopCount, NestedLoopCount)); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7190 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7191 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7192 | if (checkOpenMPIterationSpace( |
| 7193 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 7194 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7195 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces, Captures)) |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 7196 | return 0; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7197 | // Move on to the next nested for loop, or to the loop body. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7198 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7199 | // All loops associated with the construct must be perfectly nested; that |
| 7200 | // is, there must be no intervening code nor any OpenMP directive between |
| 7201 | // any two loops. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 7202 | if (auto *For = dyn_cast<ForStmt>(CurStmt)) { |
| 7203 | CurStmt = For->getBody(); |
| 7204 | } else { |
| 7205 | assert(isa<CXXForRangeStmt>(CurStmt) && |
| 7206 | "Expected canonical for or range-based for loops."); |
| 7207 | CurStmt = cast<CXXForRangeStmt>(CurStmt)->getBody(); |
| 7208 | } |
| Alexey Bataev | 8bbf2e3 | 2019-11-04 09:59:11 -0500 | [diff] [blame] | 7209 | CurStmt = OMPLoopDirective::tryToFindNextInnerLoop( |
| 7210 | CurStmt, SemaRef.LangOpts.OpenMP >= 50); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7211 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7212 | for (unsigned Cnt = NestedLoopCount; Cnt < OrderedLoopCount; ++Cnt) { |
| 7213 | if (checkOpenMPIterationSpace( |
| 7214 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 7215 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7216 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces, Captures)) |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7217 | return 0; |
| 7218 | if (Cnt > 0 && IterSpaces[Cnt].CounterVar) { |
| 7219 | // Handle initialization of captured loop iterator variables. |
| 7220 | auto *DRE = cast<DeclRefExpr>(IterSpaces[Cnt].CounterVar); |
| 7221 | if (isa<OMPCapturedExprDecl>(DRE->getDecl())) { |
| 7222 | Captures[DRE] = DRE; |
| 7223 | } |
| 7224 | } |
| 7225 | // Move on to the next nested for loop, or to the loop body. |
| 7226 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7227 | // All loops associated with the construct must be perfectly nested; that |
| 7228 | // is, there must be no intervening code nor any OpenMP directive between |
| 7229 | // any two loops. |
| Alexey Bataev | bef93a9 | 2019-10-07 18:54:57 +0000 | [diff] [blame] | 7230 | if (auto *For = dyn_cast<ForStmt>(CurStmt)) { |
| 7231 | CurStmt = For->getBody(); |
| 7232 | } else { |
| 7233 | assert(isa<CXXForRangeStmt>(CurStmt) && |
| 7234 | "Expected canonical for or range-based for loops."); |
| 7235 | CurStmt = cast<CXXForRangeStmt>(CurStmt)->getBody(); |
| 7236 | } |
| Alexey Bataev | 8bbf2e3 | 2019-11-04 09:59:11 -0500 | [diff] [blame] | 7237 | CurStmt = OMPLoopDirective::tryToFindNextInnerLoop( |
| 7238 | CurStmt, SemaRef.LangOpts.OpenMP >= 50); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 7239 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7240 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7241 | Built.clear(/* size */ NestedLoopCount); |
| 7242 | |
| 7243 | if (SemaRef.CurContext->isDependentContext()) |
| 7244 | return NestedLoopCount; |
| 7245 | |
| 7246 | // An example of what is generated for the following code: |
| 7247 | // |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7248 | // #pragma omp simd collapse(2) ordered(2) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7249 | // for (i = 0; i < NI; ++i) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7250 | // for (k = 0; k < NK; ++k) |
| 7251 | // for (j = J0; j < NJ; j+=2) { |
| 7252 | // <loop body> |
| 7253 | // } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7254 | // |
| 7255 | // We generate the code below. |
| 7256 | // Note: the loop body may be outlined in CodeGen. |
| 7257 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 7258 | // iterations and operator+= to calculate counter value. |
| 7259 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 7260 | // or i64 is currently supported). |
| 7261 | // |
| 7262 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 7263 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 7264 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 7265 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 7266 | // // similar updates for vars in clauses (e.g. 'linear') |
| 7267 | // <loop body (using local i and j)> |
| 7268 | // } |
| 7269 | // i = NI; // assign final values of counters |
| 7270 | // j = NJ; |
| 7271 | // |
| 7272 | |
| 7273 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 7274 | // the iteration counts of the collapsed for loops. |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 7275 | // Precondition tests if there is at least one iteration (all conditions are |
| 7276 | // true). |
| 7277 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7278 | Expr *N0 = IterSpaces[0].NumIterations; |
| 7279 | ExprResult LastIteration32 = |
| 7280 | widenIterationCount(/*Bits=*/32, |
| 7281 | SemaRef |
| 7282 | .PerformImplicitConversion( |
| 7283 | N0->IgnoreImpCasts(), N0->getType(), |
| 7284 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 7285 | .get(), |
| 7286 | SemaRef); |
| 7287 | ExprResult LastIteration64 = widenIterationCount( |
| 7288 | /*Bits=*/64, |
| 7289 | SemaRef |
| 7290 | .PerformImplicitConversion(N0->IgnoreImpCasts(), N0->getType(), |
| 7291 | Sema::AA_Converting, |
| 7292 | /*AllowExplicit=*/true) |
| 7293 | .get(), |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7294 | SemaRef); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7295 | |
| 7296 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 7297 | return NestedLoopCount; |
| 7298 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7299 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7300 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 7301 | |
| 7302 | Scope *CurScope = DSA.getCurScope(); |
| 7303 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 7304 | if (PreCond.isUsable()) { |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7305 | PreCond = |
| 7306 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 7307 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 7308 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7309 | Expr *N = IterSpaces[Cnt].NumIterations; |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7310 | SourceLocation Loc = N->getExprLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7311 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 7312 | if (LastIteration32.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7313 | LastIteration32 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7314 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7315 | SemaRef |
| 7316 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 7317 | Sema::AA_Converting, |
| 7318 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7319 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7320 | if (LastIteration64.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7321 | LastIteration64 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7322 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7323 | SemaRef |
| 7324 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 7325 | Sema::AA_Converting, |
| 7326 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7327 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | // Choose either the 32-bit or 64-bit version. |
| 7331 | ExprResult LastIteration = LastIteration64; |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 7332 | if (SemaRef.getLangOpts().OpenMPOptimisticCollapse || |
| 7333 | (LastIteration32.isUsable() && |
| 7334 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 7335 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 7336 | fitsInto( |
| 7337 | /*Bits=*/32, |
| 7338 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 7339 | LastIteration64.get(), SemaRef)))) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7340 | LastIteration = LastIteration32; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 7341 | QualType VType = LastIteration.get()->getType(); |
| 7342 | QualType RealVType = VType; |
| 7343 | QualType StrideVType = VType; |
| 7344 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 7345 | VType = |
| 7346 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 7347 | StrideVType = |
| 7348 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 7349 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7350 | |
| 7351 | if (!LastIteration.isUsable()) |
| 7352 | return 0; |
| 7353 | |
| 7354 | // Save the number of iterations. |
| 7355 | ExprResult NumIterations = LastIteration; |
| 7356 | { |
| 7357 | LastIteration = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7358 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 7359 | LastIteration.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7360 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 7361 | if (!LastIteration.isUsable()) |
| 7362 | return 0; |
| 7363 | } |
| 7364 | |
| 7365 | // Calculate the last iteration number beforehand instead of doing this on |
| 7366 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 7367 | llvm::APSInt Result; |
| 7368 | bool IsConstant = |
| 7369 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 7370 | ExprResult CalcLastIteration; |
| 7371 | if (!IsConstant) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7372 | ExprResult SaveRef = |
| 7373 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7374 | LastIteration = SaveRef; |
| 7375 | |
| 7376 | // Prepare SaveRef + 1. |
| 7377 | NumIterations = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 7378 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7379 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 7380 | if (!NumIterations.isUsable()) |
| 7381 | return 0; |
| 7382 | } |
| 7383 | |
| 7384 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 7385 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7386 | // Build variables passed into runtime, necessary for worksharing directives. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7387 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7388 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 7389 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7390 | // Lower bound variable, initialized with zero. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7391 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 7392 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7393 | SemaRef.AddInitializerToDecl(LBDecl, |
| 7394 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 7395 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7396 | |
| 7397 | // Upper bound variable, initialized with last iteration number. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7398 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 7399 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7400 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7401 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7402 | |
| 7403 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 7404 | // This will be used to implement clause 'lastprivate'. |
| 7405 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7406 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 7407 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7408 | SemaRef.AddInitializerToDecl(ILDecl, |
| 7409 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 7410 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7411 | |
| 7412 | // Stride variable returned by runtime (we initialize it to 1 by default). |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 7413 | VarDecl *STDecl = |
| 7414 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 7415 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7416 | SemaRef.AddInitializerToDecl(STDecl, |
| 7417 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 7418 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7419 | |
| 7420 | // Build expression: UB = min(UB, LastIteration) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7421 | // It is necessary for CodeGen of directives with static scheduling. |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7422 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 7423 | UB.get(), LastIteration.get()); |
| 7424 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| Alexey Bataev | 86ec3fe | 2018-07-25 14:40:26 +0000 | [diff] [blame] | 7425 | LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(), |
| 7426 | LastIteration.get(), UB.get()); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7427 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 7428 | CondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7429 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7430 | |
| 7431 | // If we have a combined directive that combines 'distribute', 'for' or |
| 7432 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 7433 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 7434 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 7435 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7436 | // Lower bound variable, initialized with zero. |
| 7437 | VarDecl *CombLBDecl = |
| 7438 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 7439 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 7440 | SemaRef.AddInitializerToDecl( |
| 7441 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 7442 | /*DirectInit*/ false); |
| 7443 | |
| 7444 | // Upper bound variable, initialized with last iteration number. |
| 7445 | VarDecl *CombUBDecl = |
| 7446 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 7447 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 7448 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 7449 | /*DirectInit*/ false); |
| 7450 | |
| 7451 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 7452 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 7453 | ExprResult CombCondOp = |
| 7454 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 7455 | LastIteration.get(), CombUB.get()); |
| 7456 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 7457 | CombCondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7458 | CombEUB = |
| 7459 | SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7460 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7461 | const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7462 | // We expect to have at least 2 more parameters than the 'parallel' |
| 7463 | // directive does - the lower and upper bounds of the previous schedule. |
| 7464 | assert(CD->getNumParams() >= 4 && |
| 7465 | "Unexpected number of parameters in loop combined directive"); |
| 7466 | |
| 7467 | // Set the proper type for the bounds given what we learned from the |
| 7468 | // enclosed loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7469 | ImplicitParamDecl *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 7470 | ImplicitParamDecl *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7471 | |
| 7472 | // Previous lower and upper bounds are obtained from the region |
| 7473 | // parameters. |
| 7474 | PrevLB = |
| 7475 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 7476 | PrevUB = |
| 7477 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 7478 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | // Build the iteration variable and its initialization before loop. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7482 | ExprResult IV; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7483 | ExprResult Init, CombInit; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7484 | { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 7485 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 7486 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7487 | Expr *RHS = |
| 7488 | (isOpenMPWorksharingDirective(DKind) || |
| 7489 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 7490 | ? LB.get() |
| 7491 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7492 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7493 | Init = SemaRef.ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7494 | |
| 7495 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 7496 | Expr *CombRHS = |
| 7497 | (isOpenMPWorksharingDirective(DKind) || |
| 7498 | isOpenMPTaskLoopDirective(DKind) || |
| 7499 | isOpenMPDistributeDirective(DKind)) |
| 7500 | ? CombLB.get() |
| 7501 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 7502 | CombInit = |
| 7503 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7504 | CombInit = |
| 7505 | SemaRef.ActOnFinishFullExpr(CombInit.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7506 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7507 | } |
| 7508 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7509 | bool UseStrictCompare = |
| 7510 | RealVType->hasUnsignedIntegerRepresentation() && |
| 7511 | llvm::all_of(IterSpaces, [](const LoopIterationSpace &LIS) { |
| 7512 | return LIS.IsStrictCompare; |
| 7513 | }); |
| 7514 | // Loop condition (IV < NumIterations) or (IV <= UB or IV < UB + 1 (for |
| 7515 | // unsigned IV)) for worksharing loops. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7516 | SourceLocation CondLoc = AStmt->getBeginLoc(); |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7517 | Expr *BoundUB = UB.get(); |
| 7518 | if (UseStrictCompare) { |
| 7519 | BoundUB = |
| 7520 | SemaRef |
| 7521 | .BuildBinOp(CurScope, CondLoc, BO_Add, BoundUB, |
| 7522 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 7523 | .get(); |
| 7524 | BoundUB = |
| 7525 | SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get(); |
| 7526 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7527 | ExprResult Cond = |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7528 | (isOpenMPWorksharingDirective(DKind) || |
| 7529 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7530 | ? SemaRef.BuildBinOp(CurScope, CondLoc, |
| 7531 | UseStrictCompare ? BO_LT : BO_LE, IV.get(), |
| 7532 | BoundUB) |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7533 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 7534 | NumIterations.get()); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7535 | ExprResult CombDistCond; |
| 7536 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7537 | CombDistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 7538 | NumIterations.get()); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7539 | } |
| 7540 | |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7541 | ExprResult CombCond; |
| 7542 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7543 | Expr *BoundCombUB = CombUB.get(); |
| 7544 | if (UseStrictCompare) { |
| 7545 | BoundCombUB = |
| 7546 | SemaRef |
| 7547 | .BuildBinOp( |
| 7548 | CurScope, CondLoc, BO_Add, BoundCombUB, |
| 7549 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 7550 | .get(); |
| 7551 | BoundCombUB = |
| 7552 | SemaRef.ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false) |
| 7553 | .get(); |
| 7554 | } |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7555 | CombCond = |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7556 | SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, |
| 7557 | IV.get(), BoundCombUB); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7558 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7559 | // Loop increment (IV = IV + 1) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7560 | SourceLocation IncLoc = AStmt->getBeginLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7561 | ExprResult Inc = |
| 7562 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 7563 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 7564 | if (!Inc.isUsable()) |
| 7565 | return 0; |
| 7566 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7567 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7568 | if (!Inc.isUsable()) |
| 7569 | return 0; |
| 7570 | |
| 7571 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 7572 | // Used for directives with static scheduling. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7573 | // In combined construct, add combined version that use CombLB and CombUB |
| 7574 | // base variables for the update |
| 7575 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7576 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 7577 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7578 | // LB + ST |
| 7579 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 7580 | if (!NextLB.isUsable()) |
| 7581 | return 0; |
| 7582 | // LB = LB + ST |
| 7583 | NextLB = |
| 7584 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7585 | NextLB = |
| 7586 | SemaRef.ActOnFinishFullExpr(NextLB.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7587 | if (!NextLB.isUsable()) |
| 7588 | return 0; |
| 7589 | // UB + ST |
| 7590 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 7591 | if (!NextUB.isUsable()) |
| 7592 | return 0; |
| 7593 | // UB = UB + ST |
| 7594 | NextUB = |
| 7595 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7596 | NextUB = |
| 7597 | SemaRef.ActOnFinishFullExpr(NextUB.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7598 | if (!NextUB.isUsable()) |
| 7599 | return 0; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7600 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 7601 | CombNextLB = |
| 7602 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 7603 | if (!NextLB.isUsable()) |
| 7604 | return 0; |
| 7605 | // LB = LB + ST |
| 7606 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 7607 | CombNextLB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7608 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get(), |
| 7609 | /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7610 | if (!CombNextLB.isUsable()) |
| 7611 | return 0; |
| 7612 | // UB + ST |
| 7613 | CombNextUB = |
| 7614 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 7615 | if (!CombNextUB.isUsable()) |
| 7616 | return 0; |
| 7617 | // UB = UB + ST |
| 7618 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 7619 | CombNextUB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7620 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get(), |
| 7621 | /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7622 | if (!CombNextUB.isUsable()) |
| 7623 | return 0; |
| 7624 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7625 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7626 | |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7627 | // Create increment expression for distribute loop when combined in a same |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7628 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 7629 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 7630 | // in combination with 'distribute', like in 'distribute parallel for' |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7631 | SourceLocation DistIncLoc = AStmt->getBeginLoc(); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7632 | ExprResult DistCond, DistInc, PrevEUB, ParForInDistCond; |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7633 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7634 | DistCond = SemaRef.BuildBinOp( |
| 7635 | CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, IV.get(), BoundUB); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7636 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 7637 | |
| 7638 | DistInc = |
| 7639 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 7640 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 7641 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 7642 | DistInc.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7643 | DistInc = |
| 7644 | SemaRef.ActOnFinishFullExpr(DistInc.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7645 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 7646 | |
| 7647 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 7648 | // construct |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7649 | SourceLocation DistEUBLoc = AStmt->getBeginLoc(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7650 | ExprResult IsUBGreater = |
| 7651 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 7652 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 7653 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 7654 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 7655 | CondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7656 | PrevEUB = |
| 7657 | SemaRef.ActOnFinishFullExpr(PrevEUB.get(), /*DiscardedValue*/ false); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7658 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7659 | // Build IV <= PrevUB or IV < PrevUB + 1 for unsigned IV to be used in |
| 7660 | // parallel for is in combination with a distribute directive with |
| 7661 | // schedule(static, 1) |
| 7662 | Expr *BoundPrevUB = PrevUB.get(); |
| 7663 | if (UseStrictCompare) { |
| 7664 | BoundPrevUB = |
| 7665 | SemaRef |
| 7666 | .BuildBinOp( |
| 7667 | CurScope, CondLoc, BO_Add, BoundPrevUB, |
| 7668 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 7669 | .get(); |
| 7670 | BoundPrevUB = |
| 7671 | SemaRef.ActOnFinishFullExpr(BoundPrevUB, /*DiscardedValue*/ false) |
| 7672 | .get(); |
| 7673 | } |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7674 | ParForInDistCond = |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 7675 | SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, |
| 7676 | IV.get(), BoundPrevUB); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7677 | } |
| 7678 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7679 | // Build updates and final values of the loop counters. |
| 7680 | bool HasErrors = false; |
| 7681 | Built.Counters.resize(NestedLoopCount); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7682 | Built.Inits.resize(NestedLoopCount); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7683 | Built.Updates.resize(NestedLoopCount); |
| 7684 | Built.Finals.resize(NestedLoopCount); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7685 | Built.DependentCounters.resize(NestedLoopCount); |
| 7686 | Built.DependentInits.resize(NestedLoopCount); |
| 7687 | Built.FinalsConditions.resize(NestedLoopCount); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7688 | { |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 7689 | // We implement the following algorithm for obtaining the |
| 7690 | // original loop iteration variable values based on the |
| 7691 | // value of the collapsed loop iteration variable IV. |
| 7692 | // |
| 7693 | // Let n+1 be the number of collapsed loops in the nest. |
| 7694 | // Iteration variables (I0, I1, .... In) |
| 7695 | // Iteration counts (N0, N1, ... Nn) |
| 7696 | // |
| 7697 | // Acc = IV; |
| 7698 | // |
| 7699 | // To compute Ik for loop k, 0 <= k <= n, generate: |
| 7700 | // Prod = N(k+1) * N(k+2) * ... * Nn; |
| 7701 | // Ik = Acc / Prod; |
| 7702 | // Acc -= Ik * Prod; |
| 7703 | // |
| 7704 | ExprResult Acc = IV; |
| 7705 | for (unsigned int Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7706 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 7707 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7708 | ExprResult Iter; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7709 | |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 7710 | // Compute prod |
| 7711 | ExprResult Prod = |
| 7712 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7713 | for (unsigned int K = Cnt+1; K < NestedLoopCount; ++K) |
| 7714 | Prod = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Prod.get(), |
| 7715 | IterSpaces[K].NumIterations); |
| 7716 | |
| 7717 | // Iter = Acc / Prod |
| 7718 | // If there is at least one more inner loop to avoid |
| 7719 | // multiplication by 1. |
| 7720 | if (Cnt + 1 < NestedLoopCount) |
| 7721 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, |
| 7722 | Acc.get(), Prod.get()); |
| 7723 | else |
| 7724 | Iter = Acc; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7725 | if (!Iter.isUsable()) { |
| 7726 | HasErrors = true; |
| 7727 | break; |
| 7728 | } |
| 7729 | |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 7730 | // Update Acc: |
| 7731 | // Acc -= Iter * Prod |
| 7732 | // Check if there is at least one more inner loop to avoid |
| 7733 | // multiplication by 1. |
| 7734 | if (Cnt + 1 < NestedLoopCount) |
| 7735 | Prod = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, |
| 7736 | Iter.get(), Prod.get()); |
| 7737 | else |
| 7738 | Prod = Iter; |
| 7739 | Acc = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Sub, |
| 7740 | Acc.get(), Prod.get()); |
| 7741 | |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7742 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7743 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7744 | DeclRefExpr *CounterVar = buildDeclRefExpr( |
| 7745 | SemaRef, VD, IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 7746 | /*RefersToCapture=*/true); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7747 | ExprResult Init = |
| 7748 | buildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 7749 | IS.CounterInit, IS.IsNonRectangularLB, Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7750 | if (!Init.isUsable()) { |
| 7751 | HasErrors = true; |
| 7752 | break; |
| 7753 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7754 | ExprResult Update = buildCounterUpdate( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7755 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7756 | IS.CounterStep, IS.Subtract, IS.IsNonRectangularLB, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7757 | if (!Update.isUsable()) { |
| 7758 | HasErrors = true; |
| 7759 | break; |
| 7760 | } |
| 7761 | |
| 7762 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7763 | ExprResult Final = |
| 7764 | buildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
| 7765 | IS.CounterInit, IS.NumIterations, IS.CounterStep, |
| 7766 | IS.Subtract, IS.IsNonRectangularLB, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7767 | if (!Final.isUsable()) { |
| 7768 | HasErrors = true; |
| 7769 | break; |
| 7770 | } |
| 7771 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7772 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7773 | HasErrors = true; |
| 7774 | break; |
| 7775 | } |
| 7776 | // Save results |
| 7777 | Built.Counters[Cnt] = IS.CounterVar; |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 7778 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 7779 | Built.Inits[Cnt] = Init.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7780 | Built.Updates[Cnt] = Update.get(); |
| 7781 | Built.Finals[Cnt] = Final.get(); |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7782 | Built.DependentCounters[Cnt] = nullptr; |
| 7783 | Built.DependentInits[Cnt] = nullptr; |
| 7784 | Built.FinalsConditions[Cnt] = nullptr; |
| Alexey Bataev | 658ad4d | 2019-10-01 16:19:10 +0000 | [diff] [blame] | 7785 | if (IS.IsNonRectangularLB || IS.IsNonRectangularUB) { |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7786 | Built.DependentCounters[Cnt] = |
| 7787 | Built.Counters[NestedLoopCount - 1 - IS.LoopDependentIdx]; |
| 7788 | Built.DependentInits[Cnt] = |
| 7789 | Built.Inits[NestedLoopCount - 1 - IS.LoopDependentIdx]; |
| 7790 | Built.FinalsConditions[Cnt] = IS.FinalCondition; |
| 7791 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7792 | } |
| 7793 | } |
| 7794 | |
| 7795 | if (HasErrors) |
| 7796 | return 0; |
| 7797 | |
| 7798 | // Save results |
| 7799 | Built.IterationVarRef = IV.get(); |
| 7800 | Built.LastIteration = LastIteration.get(); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7801 | Built.NumIterations = NumIterations.get(); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7802 | Built.CalcLastIteration = SemaRef |
| 7803 | .ActOnFinishFullExpr(CalcLastIteration.get(), |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 7804 | /*DiscardedValue=*/false) |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 7805 | .get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7806 | Built.PreCond = PreCond.get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7807 | Built.PreInits = buildPreInits(C, Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7808 | Built.Cond = Cond.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7809 | Built.Init = Init.get(); |
| 7810 | Built.Inc = Inc.get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7811 | Built.LB = LB.get(); |
| 7812 | Built.UB = UB.get(); |
| 7813 | Built.IL = IL.get(); |
| 7814 | Built.ST = ST.get(); |
| 7815 | Built.EUB = EUB.get(); |
| 7816 | Built.NLB = NextLB.get(); |
| 7817 | Built.NUB = NextUB.get(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7818 | Built.PrevLB = PrevLB.get(); |
| 7819 | Built.PrevUB = PrevUB.get(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 7820 | Built.DistInc = DistInc.get(); |
| 7821 | Built.PrevEUB = PrevEUB.get(); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 7822 | Built.DistCombinedFields.LB = CombLB.get(); |
| 7823 | Built.DistCombinedFields.UB = CombUB.get(); |
| 7824 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 7825 | Built.DistCombinedFields.Init = CombInit.get(); |
| 7826 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 7827 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 7828 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 7829 | Built.DistCombinedFields.DistCond = CombDistCond.get(); |
| 7830 | Built.DistCombinedFields.ParForInDistCond = ParForInDistCond.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7831 | |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 7832 | return NestedLoopCount; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7835 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 7836 | auto CollapseClauses = |
| 7837 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 7838 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 7839 | return (*CollapseClauses.begin())->getNumForLoops(); |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 7840 | return nullptr; |
| 7841 | } |
| 7842 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7843 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 7844 | auto OrderedClauses = |
| 7845 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 7846 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 7847 | return (*OrderedClauses.begin())->getNumForLoops(); |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7848 | return nullptr; |
| 7849 | } |
| 7850 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7851 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 7852 | const ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7853 | const OMPSafelenClause *Safelen = nullptr; |
| 7854 | const OMPSimdlenClause *Simdlen = nullptr; |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7855 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7856 | for (const OMPClause *Clause : Clauses) { |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7857 | if (Clause->getClauseKind() == OMPC_safelen) |
| 7858 | Safelen = cast<OMPSafelenClause>(Clause); |
| 7859 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 7860 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 7861 | if (Safelen && Simdlen) |
| 7862 | break; |
| 7863 | } |
| 7864 | |
| 7865 | if (Simdlen && Safelen) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7866 | const Expr *SimdlenLength = Simdlen->getSimdlen(); |
| 7867 | const Expr *SafelenLength = Safelen->getSafelen(); |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7868 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 7869 | SimdlenLength->isInstantiationDependent() || |
| 7870 | SimdlenLength->containsUnexpandedParameterPack()) |
| 7871 | return false; |
| 7872 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 7873 | SafelenLength->isInstantiationDependent() || |
| 7874 | SafelenLength->containsUnexpandedParameterPack()) |
| 7875 | return false; |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 7876 | Expr::EvalResult SimdlenResult, SafelenResult; |
| 7877 | SimdlenLength->EvaluateAsInt(SimdlenResult, S.Context); |
| 7878 | SafelenLength->EvaluateAsInt(SafelenResult, S.Context); |
| 7879 | llvm::APSInt SimdlenRes = SimdlenResult.Val.getInt(); |
| 7880 | llvm::APSInt SafelenRes = SafelenResult.Val.getInt(); |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7881 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 7882 | // If both simdlen and safelen clauses are specified, the value of the |
| 7883 | // simdlen parameter must be less than or equal to the value of the safelen |
| 7884 | // parameter. |
| 7885 | if (SimdlenRes > SafelenRes) { |
| 7886 | S.Diag(SimdlenLength->getExprLoc(), |
| 7887 | diag::err_omp_wrong_simdlen_safelen_values) |
| 7888 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 7889 | return true; |
| 7890 | } |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7891 | } |
| 7892 | return false; |
| 7893 | } |
| 7894 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7895 | StmtResult |
| 7896 | Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 7897 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 7898 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7899 | if (!AStmt) |
| 7900 | return StmtError(); |
| 7901 | |
| 7902 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7903 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7904 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7905 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7906 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7907 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 7908 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 7909 | if (NestedLoopCount == 0) |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7910 | return StmtError(); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7911 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7912 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7913 | "omp simd loop exprs were not built"); |
| 7914 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7915 | if (!CurContext->isDependentContext()) { |
| 7916 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7917 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7918 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7919 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7920 | B.NumIterations, *this, CurScope, |
| 7921 | DSAStack)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7922 | return StmtError(); |
| 7923 | } |
| 7924 | } |
| 7925 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7926 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7927 | return StmtError(); |
| 7928 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7929 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7930 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 7931 | Clauses, AStmt, B); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7932 | } |
| 7933 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7934 | StmtResult |
| 7935 | Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 7936 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 7937 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7938 | if (!AStmt) |
| 7939 | return StmtError(); |
| 7940 | |
| 7941 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7942 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7943 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7944 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7945 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7946 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 7947 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 7948 | if (NestedLoopCount == 0) |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7949 | return StmtError(); |
| 7950 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 7951 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7952 | "omp for loop exprs were not built"); |
| 7953 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 7954 | if (!CurContext->isDependentContext()) { |
| 7955 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7956 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7957 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 7958 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7959 | B.NumIterations, *this, CurScope, |
| 7960 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 7961 | return StmtError(); |
| 7962 | } |
| 7963 | } |
| 7964 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7965 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7966 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 7967 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7968 | } |
| 7969 | |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7970 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 7971 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7972 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7973 | if (!AStmt) |
| 7974 | return StmtError(); |
| 7975 | |
| 7976 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7977 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7978 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7979 | // define the nested loops number. |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7980 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7981 | checkOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7982 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 7983 | VarsWithImplicitDSA, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7984 | if (NestedLoopCount == 0) |
| 7985 | return StmtError(); |
| 7986 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 7987 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7988 | "omp for simd loop exprs were not built"); |
| 7989 | |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 7990 | if (!CurContext->isDependentContext()) { |
| 7991 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7992 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7993 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 7994 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7995 | B.NumIterations, *this, CurScope, |
| 7996 | DSAStack)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 7997 | return StmtError(); |
| 7998 | } |
| 7999 | } |
| 8000 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 8001 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8002 | return StmtError(); |
| 8003 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8004 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 8005 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 8006 | Clauses, AStmt, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 8007 | } |
| 8008 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8009 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 8010 | Stmt *AStmt, |
| 8011 | SourceLocation StartLoc, |
| 8012 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8013 | if (!AStmt) |
| 8014 | return StmtError(); |
| 8015 | |
| 8016 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8017 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8018 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8019 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8020 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8021 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 8022 | if (S.begin() == S.end()) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8023 | return StmtError(); |
| 8024 | // All associated statements must be '#pragma omp section' except for |
| 8025 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 8026 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8027 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 8028 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8029 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8030 | diag::err_omp_sections_substmt_not_section); |
| 8031 | return StmtError(); |
| 8032 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8033 | cast<OMPSectionDirective>(SectionStmt) |
| 8034 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8035 | } |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8036 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8037 | Diag(AStmt->getBeginLoc(), diag::err_omp_sections_not_compound_stmt); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8038 | return StmtError(); |
| 8039 | } |
| 8040 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8041 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8042 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8043 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 8044 | DSAStack->isCancelRegion()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 8045 | } |
| 8046 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8047 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 8048 | SourceLocation StartLoc, |
| 8049 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8050 | if (!AStmt) |
| 8051 | return StmtError(); |
| 8052 | |
| 8053 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8054 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8055 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8056 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8057 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8058 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 8059 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 8060 | } |
| 8061 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 8062 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 8063 | Stmt *AStmt, |
| 8064 | SourceLocation StartLoc, |
| 8065 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8066 | if (!AStmt) |
| 8067 | return StmtError(); |
| 8068 | |
| 8069 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 8070 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8071 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 8072 | |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 8073 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 8074 | // The copyprivate clause must not be used with the nowait clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8075 | const OMPClause *Nowait = nullptr; |
| 8076 | const OMPClause *Copyprivate = nullptr; |
| 8077 | for (const OMPClause *Clause : Clauses) { |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 8078 | if (Clause->getClauseKind() == OMPC_nowait) |
| 8079 | Nowait = Clause; |
| 8080 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 8081 | Copyprivate = Clause; |
| 8082 | if (Copyprivate && Nowait) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8083 | Diag(Copyprivate->getBeginLoc(), |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 8084 | diag::err_omp_single_copyprivate_with_nowait); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8085 | Diag(Nowait->getBeginLoc(), diag::note_omp_nowait_clause_here); |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 8086 | return StmtError(); |
| 8087 | } |
| 8088 | } |
| 8089 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 8090 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 8091 | } |
| 8092 | |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 8093 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 8094 | SourceLocation StartLoc, |
| 8095 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8096 | if (!AStmt) |
| 8097 | return StmtError(); |
| 8098 | |
| 8099 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 8100 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8101 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 8102 | |
| 8103 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 8104 | } |
| 8105 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8106 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 8107 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 8108 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8109 | if (!AStmt) |
| 8110 | return StmtError(); |
| 8111 | |
| 8112 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 8113 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8114 | bool ErrorFound = false; |
| 8115 | llvm::APSInt Hint; |
| 8116 | SourceLocation HintLoc; |
| 8117 | bool DependentHint = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8118 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8119 | if (C->getClauseKind() == OMPC_hint) { |
| 8120 | if (!DirName.getName()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8121 | Diag(C->getBeginLoc(), diag::err_omp_hint_clause_no_name); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8122 | ErrorFound = true; |
| 8123 | } |
| 8124 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 8125 | if (E->isTypeDependent() || E->isValueDependent() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8126 | E->isInstantiationDependent()) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8127 | DependentHint = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8128 | } else { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8129 | Hint = E->EvaluateKnownConstInt(Context); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8130 | HintLoc = C->getBeginLoc(); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8131 | } |
| 8132 | } |
| 8133 | } |
| 8134 | if (ErrorFound) |
| 8135 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8136 | const auto Pair = DSAStack->getCriticalWithHint(DirName); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8137 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 8138 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 8139 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8140 | if (HintLoc.isValid()) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8141 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 8142 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8143 | else |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8144 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8145 | if (const auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8146 | Diag(C->getBeginLoc(), diag::note_omp_critical_hint_here) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8147 | << 1 |
| 8148 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 8149 | /*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8150 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8151 | Diag(Pair.first->getBeginLoc(), diag::note_omp_critical_no_hint) << 1; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8152 | } |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8153 | } |
| 8154 | } |
| 8155 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8156 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 8157 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8158 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 8159 | Clauses, AStmt); |
| 8160 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 8161 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 8162 | return Dir; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 8163 | } |
| 8164 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 8165 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 8166 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8167 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8168 | if (!AStmt) |
| 8169 | return StmtError(); |
| 8170 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8171 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 8172 | // 1.2.2 OpenMP Language Terminology |
| 8173 | // Structured block - An executable statement with a single entry at the |
| 8174 | // top and a single exit at the bottom. |
| 8175 | // The point of exit cannot be a branch out of the structured block. |
| 8176 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8177 | CS->getCapturedDecl()->setNothrow(); |
| 8178 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 8179 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8180 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 8181 | // define the nested loops number. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 8182 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8183 | checkOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8184 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 8185 | VarsWithImplicitDSA, B); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 8186 | if (NestedLoopCount == 0) |
| 8187 | return StmtError(); |
| 8188 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 8189 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8190 | "omp parallel for loop exprs were not built"); |
| 8191 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 8192 | if (!CurContext->isDependentContext()) { |
| 8193 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8194 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8195 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 8196 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 8197 | B.NumIterations, *this, CurScope, |
| 8198 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 8199 | return StmtError(); |
| 8200 | } |
| 8201 | } |
| 8202 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8203 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 8204 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8205 | NestedLoopCount, Clauses, AStmt, B, |
| 8206 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 8207 | } |
| 8208 | |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8209 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 8210 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8211 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8212 | if (!AStmt) |
| 8213 | return StmtError(); |
| 8214 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8215 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8216 | // 1.2.2 OpenMP Language Terminology |
| 8217 | // Structured block - An executable statement with a single entry at the |
| 8218 | // top and a single exit at the bottom. |
| 8219 | // The point of exit cannot be a branch out of the structured block. |
| 8220 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8221 | CS->getCapturedDecl()->setNothrow(); |
| 8222 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 8223 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8224 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 8225 | // define the nested loops number. |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8226 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8227 | checkOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8228 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 8229 | VarsWithImplicitDSA, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8230 | if (NestedLoopCount == 0) |
| 8231 | return StmtError(); |
| 8232 | |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 8233 | if (!CurContext->isDependentContext()) { |
| 8234 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8235 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8236 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 8237 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 8238 | B.NumIterations, *this, CurScope, |
| 8239 | DSAStack)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 8240 | return StmtError(); |
| 8241 | } |
| 8242 | } |
| 8243 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 8244 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8245 | return StmtError(); |
| 8246 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8247 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 8248 | return OMPParallelForSimdDirective::Create( |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 8249 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8250 | } |
| 8251 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8252 | StmtResult |
| 8253 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 8254 | Stmt *AStmt, SourceLocation StartLoc, |
| 8255 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8256 | if (!AStmt) |
| 8257 | return StmtError(); |
| 8258 | |
| 8259 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8260 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8261 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8262 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8263 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8264 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 8265 | if (S.begin() == S.end()) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8266 | return StmtError(); |
| 8267 | // All associated statements must be '#pragma omp section' except for |
| 8268 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 8269 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8270 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 8271 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8272 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8273 | diag::err_omp_parallel_sections_substmt_not_section); |
| 8274 | return StmtError(); |
| 8275 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8276 | cast<OMPSectionDirective>(SectionStmt) |
| 8277 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8278 | } |
| 8279 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8280 | Diag(AStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8281 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 8282 | return StmtError(); |
| 8283 | } |
| 8284 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8285 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8286 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8287 | return OMPParallelSectionsDirective::Create( |
| 8288 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8289 | } |
| 8290 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8291 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 8292 | Stmt *AStmt, SourceLocation StartLoc, |
| 8293 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8294 | if (!AStmt) |
| 8295 | return StmtError(); |
| 8296 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8297 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8298 | // 1.2.2 OpenMP Language Terminology |
| 8299 | // Structured block - An executable statement with a single entry at the |
| 8300 | // top and a single exit at the bottom. |
| 8301 | // The point of exit cannot be a branch out of the structured block. |
| 8302 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8303 | CS->getCapturedDecl()->setNothrow(); |
| 8304 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8305 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8306 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 8307 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 8308 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8309 | } |
| 8310 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 8311 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 8312 | SourceLocation EndLoc) { |
| 8313 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 8314 | } |
| 8315 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 8316 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 8317 | SourceLocation EndLoc) { |
| 8318 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 8319 | } |
| 8320 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 8321 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 8322 | SourceLocation EndLoc) { |
| 8323 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 8324 | } |
| 8325 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8326 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
| 8327 | Stmt *AStmt, |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8328 | SourceLocation StartLoc, |
| 8329 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8330 | if (!AStmt) |
| 8331 | return StmtError(); |
| 8332 | |
| 8333 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8334 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8335 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8336 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8337 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 8338 | AStmt, |
| 8339 | DSAStack->getTaskgroupReductionRef()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8340 | } |
| 8341 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8342 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 8343 | SourceLocation StartLoc, |
| 8344 | SourceLocation EndLoc) { |
| 8345 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 8346 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 8347 | } |
| 8348 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8349 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 8350 | Stmt *AStmt, |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8351 | SourceLocation StartLoc, |
| 8352 | SourceLocation EndLoc) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8353 | const OMPClause *DependFound = nullptr; |
| 8354 | const OMPClause *DependSourceClause = nullptr; |
| 8355 | const OMPClause *DependSinkClause = nullptr; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8356 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8357 | const OMPThreadsClause *TC = nullptr; |
| 8358 | const OMPSIMDClause *SC = nullptr; |
| 8359 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8360 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 8361 | DependFound = C; |
| 8362 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 8363 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8364 | Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8365 | << getOpenMPDirectiveName(OMPD_ordered) |
| 8366 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 8367 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8368 | } else { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8369 | DependSourceClause = C; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8370 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8371 | if (DependSinkClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8372 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8373 | << 0; |
| 8374 | ErrorFound = true; |
| 8375 | } |
| 8376 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 8377 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8378 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8379 | << 1; |
| 8380 | ErrorFound = true; |
| 8381 | } |
| 8382 | DependSinkClause = C; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8383 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8384 | } else if (C->getClauseKind() == OMPC_threads) { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8385 | TC = cast<OMPThreadsClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8386 | } else if (C->getClauseKind() == OMPC_simd) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8387 | SC = cast<OMPSIMDClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8388 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8389 | } |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8390 | if (!ErrorFound && !SC && |
| 8391 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8392 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 8393 | // An ordered construct with the simd clause is the only OpenMP construct |
| 8394 | // that can appear in the simd region. |
| Alexey Bataev | f8c12ed | 2019-11-11 13:44:42 -0500 | [diff] [blame] | 8395 | Diag(StartLoc, diag::err_omp_prohibited_region_simd) |
| 8396 | << (LangOpts.OpenMP >= 50 ? 1 : 0); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8397 | ErrorFound = true; |
| 8398 | } else if (DependFound && (TC || SC)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8399 | Diag(DependFound->getBeginLoc(), diag::err_omp_depend_clause_thread_simd) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8400 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 8401 | ErrorFound = true; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 8402 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8403 | Diag(DependFound->getBeginLoc(), |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8404 | diag::err_omp_ordered_directive_without_param); |
| 8405 | ErrorFound = true; |
| 8406 | } else if (TC || Clauses.empty()) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 8407 | if (const Expr *Param = DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8408 | SourceLocation ErrLoc = TC ? TC->getBeginLoc() : StartLoc; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8409 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 8410 | << (TC != nullptr); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8411 | Diag(Param->getBeginLoc(), diag::note_omp_ordered_param); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8412 | ErrorFound = true; |
| 8413 | } |
| 8414 | } |
| 8415 | if ((!AStmt && !DependFound) || ErrorFound) |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8416 | return StmtError(); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8417 | |
| 8418 | if (AStmt) { |
| 8419 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 8420 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8421 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8422 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8423 | |
| 8424 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8425 | } |
| 8426 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8427 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8428 | /// Helper class for checking expression in 'omp atomic [update]' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8429 | /// construct. |
| 8430 | class OpenMPAtomicUpdateChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8431 | /// Error results for atomic update expressions. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8432 | enum ExprAnalysisErrorCode { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8433 | /// A statement is not an expression statement. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8434 | NotAnExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8435 | /// Expression is not builtin binary or unary operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8436 | NotABinaryOrUnaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8437 | /// Unary operation is not post-/pre- increment/decrement operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8438 | NotAnUnaryIncDecExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8439 | /// An expression is not of scalar type. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8440 | NotAScalarType, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8441 | /// A binary operation is not an assignment operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8442 | NotAnAssignmentOp, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8443 | /// RHS part of the binary operation is not a binary expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8444 | NotABinaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8445 | /// RHS part is not additive/multiplicative/shift/biwise binary |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8446 | /// expression. |
| 8447 | NotABinaryOperator, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8448 | /// RHS binary operation does not have reference to the updated LHS |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8449 | /// part. |
| 8450 | NotAnUpdateExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8451 | /// No errors is found. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8452 | NoError |
| 8453 | }; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8454 | /// Reference to Sema. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8455 | Sema &SemaRef; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8456 | /// A location for note diagnostics (when error is found). |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8457 | SourceLocation NoteLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8458 | /// 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8459 | Expr *X; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8460 | /// 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8461 | Expr *E; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8462 | /// Helper expression of the form |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8463 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 8464 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 8465 | Expr *UpdateExpr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8466 | /// Is 'x' a LHS in a RHS part of full update expression. It is |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8467 | /// important for non-associative operations. |
| 8468 | bool IsXLHSInRHSPart; |
| 8469 | BinaryOperatorKind Op; |
| 8470 | SourceLocation OpLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8471 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8472 | /// if it is a prefix unary operation. |
| 8473 | bool IsPostfixUpdate; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8474 | |
| 8475 | public: |
| 8476 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8477 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8478 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8479 | /// Check specified statement that it is suitable for 'atomic update' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8480 | /// constructs and extract 'x', 'expr' and Operation from the original |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8481 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 8482 | /// without error notification. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8483 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 8484 | /// \param NoteId Diagnostic note for the main error message. |
| 8485 | /// \return true if statement is not an update expression, false otherwise. |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8486 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8487 | /// Return the 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8488 | Expr *getX() const { return X; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8489 | /// Return the 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8490 | Expr *getExpr() const { return E; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8491 | /// Return the update expression used in calculation of the updated |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8492 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 8493 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 8494 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8495 | /// Return true if 'x' is LHS in RHS part of full update expression, |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8496 | /// false otherwise. |
| 8497 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 8498 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8499 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8500 | /// if it is a prefix unary operation. |
| 8501 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 8502 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8503 | private: |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8504 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 8505 | unsigned NoteId = 0); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8506 | }; |
| 8507 | } // namespace |
| 8508 | |
| 8509 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 8510 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 8511 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 8512 | SourceLocation ErrorLoc, NoteLoc; |
| 8513 | SourceRange ErrorRange, NoteRange; |
| 8514 | // Allowed constructs are: |
| 8515 | // x = x binop expr; |
| 8516 | // x = expr binop x; |
| 8517 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 8518 | X = AtomicBinOp->getLHS(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8519 | if (const auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8520 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 8521 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 8522 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 8523 | AtomicInnerBinOp->isBitwiseOp()) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8524 | Op = AtomicInnerBinOp->getOpcode(); |
| 8525 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8526 | Expr *LHS = AtomicInnerBinOp->getLHS(); |
| 8527 | Expr *RHS = AtomicInnerBinOp->getRHS(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8528 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 8529 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 8530 | /*Canonical=*/true); |
| 8531 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 8532 | /*Canonical=*/true); |
| 8533 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 8534 | /*Canonical=*/true); |
| 8535 | if (XId == LHSId) { |
| 8536 | E = RHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8537 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8538 | } else if (XId == RHSId) { |
| 8539 | E = LHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8540 | IsXLHSInRHSPart = false; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8541 | } else { |
| 8542 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 8543 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 8544 | NoteLoc = X->getExprLoc(); |
| 8545 | NoteRange = X->getSourceRange(); |
| 8546 | ErrorFound = NotAnUpdateExpression; |
| 8547 | } |
| 8548 | } else { |
| 8549 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 8550 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 8551 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 8552 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 8553 | ErrorFound = NotABinaryOperator; |
| 8554 | } |
| 8555 | } else { |
| 8556 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 8557 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 8558 | ErrorFound = NotABinaryExpression; |
| 8559 | } |
| 8560 | } else { |
| 8561 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 8562 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 8563 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 8564 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 8565 | ErrorFound = NotAnAssignmentOp; |
| 8566 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8567 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8568 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 8569 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 8570 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8571 | } |
| 8572 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8573 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 8574 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8575 | } |
| 8576 | |
| 8577 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 8578 | unsigned NoteId) { |
| 8579 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 8580 | SourceLocation ErrorLoc, NoteLoc; |
| 8581 | SourceRange ErrorRange, NoteRange; |
| 8582 | // Allowed constructs are: |
| 8583 | // x++; |
| 8584 | // x--; |
| 8585 | // ++x; |
| 8586 | // --x; |
| 8587 | // x binop= expr; |
| 8588 | // x = x binop expr; |
| 8589 | // x = expr binop x; |
| 8590 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 8591 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 8592 | if (AtomicBody->getType()->isScalarType() || |
| 8593 | AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8594 | if (const auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8595 | AtomicBody->IgnoreParenImpCasts())) { |
| 8596 | // Check for Compound Assignment Operation |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8597 | Op = BinaryOperator::getOpForCompoundAssignment( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8598 | AtomicCompAssignOp->getOpcode()); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8599 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8600 | E = AtomicCompAssignOp->getRHS(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 8601 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8602 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8603 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 8604 | AtomicBody->IgnoreParenImpCasts())) { |
| 8605 | // Check for Binary Operation |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8606 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8607 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8608 | } else if (const auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8609 | AtomicBody->IgnoreParenImpCasts())) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8610 | // Check for Unary Operation |
| 8611 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8612 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8613 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 8614 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 8615 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8616 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 8617 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8618 | } else { |
| 8619 | ErrorFound = NotAnUnaryIncDecExpression; |
| 8620 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 8621 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 8622 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 8623 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 8624 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 8625 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8626 | ErrorFound = NotABinaryOrUnaryExpression; |
| 8627 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 8628 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 8629 | } |
| 8630 | } else { |
| 8631 | ErrorFound = NotAScalarType; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8632 | NoteLoc = ErrorLoc = AtomicBody->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8633 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 8634 | } |
| 8635 | } else { |
| 8636 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8637 | NoteLoc = ErrorLoc = S->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8638 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 8639 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8640 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8641 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 8642 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 8643 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8644 | } |
| 8645 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8646 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 8647 | if (ErrorFound == NoError && E && X) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8648 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 8649 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 8650 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 8651 | auto *OVEX = new (SemaRef.getASTContext()) |
| 8652 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 8653 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 8654 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8655 | ExprResult Update = |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8656 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 8657 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 8658 | if (Update.isInvalid()) |
| 8659 | return true; |
| 8660 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 8661 | Sema::AA_Casting); |
| 8662 | if (Update.isInvalid()) |
| 8663 | return true; |
| 8664 | UpdateExpr = Update.get(); |
| 8665 | } |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 8666 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8667 | } |
| 8668 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8669 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 8670 | Stmt *AStmt, |
| 8671 | SourceLocation StartLoc, |
| 8672 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8673 | if (!AStmt) |
| 8674 | return StmtError(); |
| 8675 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8676 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8677 | // 1.2.2 OpenMP Language Terminology |
| 8678 | // Structured block - An executable statement with a single entry at the |
| 8679 | // top and a single exit at the bottom. |
| 8680 | // The point of exit cannot be a branch out of the structured block. |
| 8681 | // longjmp() and throw() must not violate the entry/exit criteria. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8682 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 8683 | SourceLocation AtomicKindLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8684 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8685 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8686 | C->getClauseKind() == OMPC_update || |
| 8687 | C->getClauseKind() == OMPC_capture) { |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8688 | if (AtomicKind != OMPC_unknown) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8689 | Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8690 | << SourceRange(C->getBeginLoc(), C->getEndLoc()); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8691 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 8692 | << getOpenMPClauseName(AtomicKind); |
| 8693 | } else { |
| 8694 | AtomicKind = C->getClauseKind(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8695 | AtomicKindLoc = C->getBeginLoc(); |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8696 | } |
| 8697 | } |
| 8698 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8699 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8700 | Stmt *Body = CS->getCapturedStmt(); |
| Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 8701 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 8702 | Body = EWC->getSubExpr(); |
| 8703 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8704 | Expr *X = nullptr; |
| 8705 | Expr *V = nullptr; |
| 8706 | Expr *E = nullptr; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8707 | Expr *UE = nullptr; |
| 8708 | bool IsXLHSInRHSPart = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8709 | bool IsPostfixUpdate = false; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8710 | // OpenMP [2.12.6, atomic Construct] |
| 8711 | // In the next expressions: |
| 8712 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 8713 | // * During the execution of an atomic region, multiple syntactic |
| 8714 | // occurrences of x must designate the same storage location. |
| 8715 | // * Neither of v and expr (as applicable) may access the storage location |
| 8716 | // designated by x. |
| 8717 | // * Neither of x and expr (as applicable) may access the storage location |
| 8718 | // designated by v. |
| 8719 | // * expr is an expression with scalar type. |
| 8720 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 8721 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 8722 | // * The expression x binop expr must be numerically equivalent to x binop |
| 8723 | // (expr). This requirement is satisfied if the operators in expr have |
| 8724 | // precedence greater than binop, or by using parentheses around expr or |
| 8725 | // subexpressions of expr. |
| 8726 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 8727 | // binop x. This requirement is satisfied if the operators in expr have |
| 8728 | // precedence equal to or greater than binop, or by using parentheses around |
| 8729 | // expr or subexpressions of expr. |
| 8730 | // * For forms that allow multiple occurrences of x, the number of times |
| 8731 | // that x is evaluated is unspecified. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8732 | if (AtomicKind == OMPC_read) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8733 | enum { |
| 8734 | NotAnExpression, |
| 8735 | NotAnAssignmentOp, |
| 8736 | NotAScalarType, |
| 8737 | NotAnLValue, |
| 8738 | NoError |
| 8739 | } ErrorFound = NoError; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8740 | SourceLocation ErrorLoc, NoteLoc; |
| 8741 | SourceRange ErrorRange, NoteRange; |
| 8742 | // If clause is read: |
| 8743 | // v = x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8744 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 8745 | const auto *AtomicBinOp = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8746 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 8747 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 8748 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 8749 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 8750 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 8751 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 8752 | if (!X->isLValue() || !V->isLValue()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8753 | const Expr *NotLValueExpr = X->isLValue() ? V : X; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8754 | ErrorFound = NotAnLValue; |
| 8755 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 8756 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 8757 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 8758 | NoteRange = NotLValueExpr->getSourceRange(); |
| 8759 | } |
| 8760 | } else if (!X->isInstantiationDependent() || |
| 8761 | !V->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8762 | const Expr *NotScalarExpr = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8763 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 8764 | ? V |
| 8765 | : X; |
| 8766 | ErrorFound = NotAScalarType; |
| 8767 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 8768 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 8769 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 8770 | NoteRange = NotScalarExpr->getSourceRange(); |
| 8771 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 8772 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8773 | ErrorFound = NotAnAssignmentOp; |
| 8774 | ErrorLoc = AtomicBody->getExprLoc(); |
| 8775 | ErrorRange = AtomicBody->getSourceRange(); |
| 8776 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 8777 | : AtomicBody->getExprLoc(); |
| 8778 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 8779 | : AtomicBody->getSourceRange(); |
| 8780 | } |
| 8781 | } else { |
| 8782 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8783 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8784 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8785 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8786 | if (ErrorFound != NoError) { |
| 8787 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 8788 | << ErrorRange; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8789 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 8790 | << NoteRange; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8791 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8792 | } |
| 8793 | if (CurContext->isDependentContext()) |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 8794 | V = X = nullptr; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8795 | } else if (AtomicKind == OMPC_write) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8796 | enum { |
| 8797 | NotAnExpression, |
| 8798 | NotAnAssignmentOp, |
| 8799 | NotAScalarType, |
| 8800 | NotAnLValue, |
| 8801 | NoError |
| 8802 | } ErrorFound = NoError; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8803 | SourceLocation ErrorLoc, NoteLoc; |
| 8804 | SourceRange ErrorRange, NoteRange; |
| 8805 | // If clause is write: |
| 8806 | // x = expr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8807 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 8808 | const auto *AtomicBinOp = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8809 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 8810 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 8811 | X = AtomicBinOp->getLHS(); |
| 8812 | E = AtomicBinOp->getRHS(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8813 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 8814 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 8815 | if (!X->isLValue()) { |
| 8816 | ErrorFound = NotAnLValue; |
| 8817 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 8818 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 8819 | NoteLoc = X->getExprLoc(); |
| 8820 | NoteRange = X->getSourceRange(); |
| 8821 | } |
| 8822 | } else if (!X->isInstantiationDependent() || |
| 8823 | !E->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8824 | const Expr *NotScalarExpr = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8825 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 8826 | ? E |
| 8827 | : X; |
| 8828 | ErrorFound = NotAScalarType; |
| 8829 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 8830 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 8831 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 8832 | NoteRange = NotScalarExpr->getSourceRange(); |
| 8833 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 8834 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8835 | ErrorFound = NotAnAssignmentOp; |
| 8836 | ErrorLoc = AtomicBody->getExprLoc(); |
| 8837 | ErrorRange = AtomicBody->getSourceRange(); |
| 8838 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 8839 | : AtomicBody->getExprLoc(); |
| 8840 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 8841 | : AtomicBody->getSourceRange(); |
| 8842 | } |
| 8843 | } else { |
| 8844 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8845 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8846 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8847 | } |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8848 | if (ErrorFound != NoError) { |
| 8849 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 8850 | << ErrorRange; |
| 8851 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 8852 | << NoteRange; |
| 8853 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8854 | } |
| 8855 | if (CurContext->isDependentContext()) |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 8856 | E = X = nullptr; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8857 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8858 | // If clause is update: |
| 8859 | // x++; |
| 8860 | // x--; |
| 8861 | // ++x; |
| 8862 | // --x; |
| 8863 | // x binop= expr; |
| 8864 | // x = x binop expr; |
| 8865 | // x = expr binop x; |
| 8866 | OpenMPAtomicUpdateChecker Checker(*this); |
| 8867 | if (Checker.checkStatement( |
| 8868 | Body, (AtomicKind == OMPC_update) |
| 8869 | ? diag::err_omp_atomic_update_not_expression_statement |
| 8870 | : diag::err_omp_atomic_not_expression_statement, |
| 8871 | diag::note_omp_atomic_update)) |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8872 | return StmtError(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 8873 | if (!CurContext->isDependentContext()) { |
| 8874 | E = Checker.getExpr(); |
| 8875 | X = Checker.getX(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 8876 | UE = Checker.getUpdateExpr(); |
| 8877 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8878 | } |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8879 | } else if (AtomicKind == OMPC_capture) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8880 | enum { |
| 8881 | NotAnAssignmentOp, |
| 8882 | NotACompoundStatement, |
| 8883 | NotTwoSubstatements, |
| 8884 | NotASpecificExpression, |
| 8885 | NoError |
| 8886 | } ErrorFound = NoError; |
| 8887 | SourceLocation ErrorLoc, NoteLoc; |
| 8888 | SourceRange ErrorRange, NoteRange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8889 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8890 | // If clause is a capture: |
| 8891 | // v = x++; |
| 8892 | // v = x--; |
| 8893 | // v = ++x; |
| 8894 | // v = --x; |
| 8895 | // v = x binop= expr; |
| 8896 | // v = x = x binop expr; |
| 8897 | // v = x = expr binop x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8898 | const auto *AtomicBinOp = |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8899 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 8900 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 8901 | V = AtomicBinOp->getLHS(); |
| 8902 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 8903 | OpenMPAtomicUpdateChecker Checker(*this); |
| 8904 | if (Checker.checkStatement( |
| 8905 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 8906 | diag::note_omp_atomic_update)) |
| 8907 | return StmtError(); |
| 8908 | E = Checker.getExpr(); |
| 8909 | X = Checker.getX(); |
| 8910 | UE = Checker.getUpdateExpr(); |
| 8911 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 8912 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 8913 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8914 | ErrorLoc = AtomicBody->getExprLoc(); |
| 8915 | ErrorRange = AtomicBody->getSourceRange(); |
| 8916 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 8917 | : AtomicBody->getExprLoc(); |
| 8918 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 8919 | : AtomicBody->getSourceRange(); |
| 8920 | ErrorFound = NotAnAssignmentOp; |
| 8921 | } |
| 8922 | if (ErrorFound != NoError) { |
| 8923 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 8924 | << ErrorRange; |
| 8925 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 8926 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8927 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8928 | if (CurContext->isDependentContext()) |
| 8929 | UE = V = E = X = nullptr; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8930 | } else { |
| 8931 | // If clause is a capture: |
| 8932 | // { v = x; x = expr; } |
| 8933 | // { v = x; x++; } |
| 8934 | // { v = x; x--; } |
| 8935 | // { v = x; ++x; } |
| 8936 | // { v = x; --x; } |
| 8937 | // { v = x; x binop= expr; } |
| 8938 | // { v = x; x = x binop expr; } |
| 8939 | // { v = x; x = expr binop x; } |
| 8940 | // { x++; v = x; } |
| 8941 | // { x--; v = x; } |
| 8942 | // { ++x; v = x; } |
| 8943 | // { --x; v = x; } |
| 8944 | // { x binop= expr; v = x; } |
| 8945 | // { x = x binop expr; v = x; } |
| 8946 | // { x = expr binop x; v = x; } |
| 8947 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 8948 | // Check that this is { expr1; expr2; } |
| 8949 | if (CS->size() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8950 | Stmt *First = CS->body_front(); |
| 8951 | Stmt *Second = CS->body_back(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8952 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 8953 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 8954 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 8955 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 8956 | // Need to find what subexpression is 'v' and what is 'x'. |
| 8957 | OpenMPAtomicUpdateChecker Checker(*this); |
| 8958 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 8959 | BinaryOperator *BinOp = nullptr; |
| 8960 | if (IsUpdateExprFound) { |
| 8961 | BinOp = dyn_cast<BinaryOperator>(First); |
| 8962 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 8963 | } |
| 8964 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 8965 | // { v = x; x++; } |
| 8966 | // { v = x; x--; } |
| 8967 | // { v = x; ++x; } |
| 8968 | // { v = x; --x; } |
| 8969 | // { v = x; x binop= expr; } |
| 8970 | // { v = x; x = x binop expr; } |
| 8971 | // { v = x; x = expr binop x; } |
| 8972 | // Check that the first expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8973 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8974 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 8975 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 8976 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 8977 | IsUpdateExprFound = XId == PossibleXId; |
| 8978 | if (IsUpdateExprFound) { |
| 8979 | V = BinOp->getLHS(); |
| 8980 | X = Checker.getX(); |
| 8981 | E = Checker.getExpr(); |
| 8982 | UE = Checker.getUpdateExpr(); |
| 8983 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 8984 | IsPostfixUpdate = true; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 8985 | } |
| 8986 | } |
| 8987 | if (!IsUpdateExprFound) { |
| 8988 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 8989 | BinOp = nullptr; |
| 8990 | if (IsUpdateExprFound) { |
| 8991 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 8992 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 8993 | } |
| 8994 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 8995 | // { x++; v = x; } |
| 8996 | // { x--; v = x; } |
| 8997 | // { ++x; v = x; } |
| 8998 | // { --x; v = x; } |
| 8999 | // { x binop= expr; v = x; } |
| 9000 | // { x = x binop expr; v = x; } |
| 9001 | // { x = expr binop x; v = x; } |
| 9002 | // Check that the second expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9003 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9004 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 9005 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 9006 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 9007 | IsUpdateExprFound = XId == PossibleXId; |
| 9008 | if (IsUpdateExprFound) { |
| 9009 | V = BinOp->getLHS(); |
| 9010 | X = Checker.getX(); |
| 9011 | E = Checker.getExpr(); |
| 9012 | UE = Checker.getUpdateExpr(); |
| 9013 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 9014 | IsPostfixUpdate = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9015 | } |
| 9016 | } |
| 9017 | } |
| 9018 | if (!IsUpdateExprFound) { |
| 9019 | // { v = x; x = expr; } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9020 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 9021 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 9022 | if (!FirstExpr || !SecondExpr || |
| 9023 | !(FirstExpr->isInstantiationDependent() || |
| 9024 | SecondExpr->isInstantiationDependent())) { |
| 9025 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 9026 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9027 | ErrorFound = NotAnAssignmentOp; |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9028 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9029 | : First->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9030 | NoteRange = ErrorRange = FirstBinOp |
| 9031 | ? FirstBinOp->getSourceRange() |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9032 | : SourceRange(ErrorLoc, ErrorLoc); |
| 9033 | } else { |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9034 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 9035 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 9036 | ErrorFound = NotAnAssignmentOp; |
| 9037 | NoteLoc = ErrorLoc = SecondBinOp |
| 9038 | ? SecondBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9039 | : Second->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9040 | NoteRange = ErrorRange = |
| 9041 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 9042 | : SourceRange(ErrorLoc, ErrorLoc); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9043 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9044 | Expr *PossibleXRHSInFirst = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9045 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9046 | Expr *PossibleXLHSInSecond = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 9047 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 9048 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 9049 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 9050 | /*Canonical=*/true); |
| 9051 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 9052 | /*Canonical=*/true); |
| 9053 | IsUpdateExprFound = X1Id == X2Id; |
| 9054 | if (IsUpdateExprFound) { |
| 9055 | V = FirstBinOp->getLHS(); |
| 9056 | X = SecondBinOp->getLHS(); |
| 9057 | E = SecondBinOp->getRHS(); |
| 9058 | UE = nullptr; |
| 9059 | IsXLHSInRHSPart = false; |
| 9060 | IsPostfixUpdate = true; |
| 9061 | } else { |
| 9062 | ErrorFound = NotASpecificExpression; |
| 9063 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 9064 | ErrorRange = FirstBinOp->getSourceRange(); |
| 9065 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 9066 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 9067 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9068 | } |
| 9069 | } |
| 9070 | } |
| 9071 | } |
| 9072 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9073 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9074 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9075 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9076 | ErrorFound = NotTwoSubstatements; |
| 9077 | } |
| 9078 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9079 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9080 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9081 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9082 | ErrorFound = NotACompoundStatement; |
| 9083 | } |
| 9084 | if (ErrorFound != NoError) { |
| 9085 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 9086 | << ErrorRange; |
| 9087 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 9088 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9089 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9090 | if (CurContext->isDependentContext()) |
| 9091 | UE = V = E = X = nullptr; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9092 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9093 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 9094 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9095 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 9096 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 9097 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 9098 | X, V, E, UE, IsXLHSInRHSPart, |
| 9099 | IsPostfixUpdate); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 9100 | } |
| 9101 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 9102 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 9103 | Stmt *AStmt, |
| 9104 | SourceLocation StartLoc, |
| 9105 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9106 | if (!AStmt) |
| 9107 | return StmtError(); |
| 9108 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9109 | auto *CS = cast<CapturedStmt>(AStmt); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 9110 | // 1.2.2 OpenMP Language Terminology |
| 9111 | // Structured block - An executable statement with a single entry at the |
| 9112 | // top and a single exit at the bottom. |
| 9113 | // The point of exit cannot be a branch out of the structured block. |
| 9114 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9115 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 9116 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target); |
| 9117 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9118 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9119 | // 1.2.2 OpenMP Language Terminology |
| 9120 | // Structured block - An executable statement with a single entry at the |
| 9121 | // top and a single exit at the bottom. |
| 9122 | // The point of exit cannot be a branch out of the structured block. |
| 9123 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9124 | CS->getCapturedDecl()->setNothrow(); |
| 9125 | } |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 9126 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9127 | // OpenMP [2.16, Nesting of Regions] |
| 9128 | // If specified, a teams construct must be contained within a target |
| 9129 | // construct. That target construct must contain no statements or directives |
| 9130 | // outside of the teams construct. |
| 9131 | if (DSAStack->hasInnerTeamsRegion()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9132 | const Stmt *S = CS->IgnoreContainers(/*IgnoreCaptured=*/true); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9133 | bool OMPTeamsFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9134 | if (const auto *CS = dyn_cast<CompoundStmt>(S)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9135 | auto I = CS->body_begin(); |
| 9136 | while (I != CS->body_end()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9137 | const auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
| Kelvin Li | 620ba60 | 2019-02-05 16:43:00 +0000 | [diff] [blame] | 9138 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind()) || |
| 9139 | OMPTeamsFound) { |
| 9140 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9141 | OMPTeamsFound = false; |
| 9142 | break; |
| 9143 | } |
| 9144 | ++I; |
| 9145 | } |
| 9146 | assert(I != CS->body_end() && "Not found statement"); |
| 9147 | S = *I; |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 9148 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9149 | const auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 9150 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9151 | } |
| 9152 | if (!OMPTeamsFound) { |
| 9153 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 9154 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 9155 | diag::note_omp_nested_teams_construct_here); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9156 | Diag(S->getBeginLoc(), diag::note_omp_nested_statement_here) |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9157 | << isa<OMPExecutableDirective>(S); |
| 9158 | return StmtError(); |
| 9159 | } |
| 9160 | } |
| 9161 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9162 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 9163 | |
| 9164 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 9165 | } |
| 9166 | |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 9167 | StmtResult |
| 9168 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 9169 | Stmt *AStmt, SourceLocation StartLoc, |
| 9170 | SourceLocation EndLoc) { |
| 9171 | if (!AStmt) |
| 9172 | return StmtError(); |
| 9173 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9174 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 9175 | // 1.2.2 OpenMP Language Terminology |
| 9176 | // Structured block - An executable statement with a single entry at the |
| 9177 | // top and a single exit at the bottom. |
| 9178 | // The point of exit cannot be a branch out of the structured block. |
| 9179 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9180 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 9181 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel); |
| 9182 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9183 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9184 | // 1.2.2 OpenMP Language Terminology |
| 9185 | // Structured block - An executable statement with a single entry at the |
| 9186 | // top and a single exit at the bottom. |
| 9187 | // The point of exit cannot be a branch out of the structured block. |
| 9188 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9189 | CS->getCapturedDecl()->setNothrow(); |
| 9190 | } |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 9191 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9192 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 9193 | |
| 9194 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9195 | AStmt); |
| 9196 | } |
| 9197 | |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9198 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 9199 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9200 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9201 | if (!AStmt) |
| 9202 | return StmtError(); |
| 9203 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9204 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9205 | // 1.2.2 OpenMP Language Terminology |
| 9206 | // Structured block - An executable statement with a single entry at the |
| 9207 | // top and a single exit at the bottom. |
| 9208 | // The point of exit cannot be a branch out of the structured block. |
| 9209 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9210 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 9211 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 9212 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9213 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9214 | // 1.2.2 OpenMP Language Terminology |
| 9215 | // Structured block - An executable statement with a single entry at the |
| 9216 | // top and a single exit at the bottom. |
| 9217 | // The point of exit cannot be a branch out of the structured block. |
| 9218 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9219 | CS->getCapturedDecl()->setNothrow(); |
| 9220 | } |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9221 | |
| 9222 | OMPLoopDirective::HelperExprs B; |
| 9223 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9224 | // define the nested loops number. |
| 9225 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9226 | checkOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 9227 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9228 | VarsWithImplicitDSA, B); |
| 9229 | if (NestedLoopCount == 0) |
| 9230 | return StmtError(); |
| 9231 | |
| 9232 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9233 | "omp target parallel for loop exprs were not built"); |
| 9234 | |
| 9235 | if (!CurContext->isDependentContext()) { |
| 9236 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9237 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9238 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9239 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9240 | B.NumIterations, *this, CurScope, |
| 9241 | DSAStack)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9242 | return StmtError(); |
| 9243 | } |
| 9244 | } |
| 9245 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9246 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 9247 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 9248 | NestedLoopCount, Clauses, AStmt, |
| 9249 | B, DSAStack->isCancelRegion()); |
| 9250 | } |
| 9251 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9252 | /// Check for existence of a map clause in the list of clauses. |
| 9253 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, |
| 9254 | const OpenMPClauseKind K) { |
| 9255 | return llvm::any_of( |
| 9256 | Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; }); |
| 9257 | } |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9258 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9259 | template <typename... Params> |
| 9260 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, const OpenMPClauseKind K, |
| 9261 | const Params... ClauseTypes) { |
| 9262 | return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9263 | } |
| 9264 | |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 9265 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 9266 | Stmt *AStmt, |
| 9267 | SourceLocation StartLoc, |
| 9268 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9269 | if (!AStmt) |
| 9270 | return StmtError(); |
| 9271 | |
| 9272 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9273 | |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 9274 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 9275 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9276 | if (!hasClauses(Clauses, OMPC_map, OMPC_use_device_ptr)) { |
| 9277 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 9278 | << "'map' or 'use_device_ptr'" |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9279 | << getOpenMPDirectiveName(OMPD_target_data); |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 9280 | return StmtError(); |
| 9281 | } |
| 9282 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9283 | setFunctionHasBranchProtectedScope(); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 9284 | |
| 9285 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9286 | AStmt); |
| 9287 | } |
| 9288 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9289 | StmtResult |
| 9290 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 9291 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9292 | SourceLocation EndLoc, Stmt *AStmt) { |
| 9293 | if (!AStmt) |
| 9294 | return StmtError(); |
| 9295 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9296 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9297 | // 1.2.2 OpenMP Language Terminology |
| 9298 | // Structured block - An executable statement with a single entry at the |
| 9299 | // top and a single exit at the bottom. |
| 9300 | // The point of exit cannot be a branch out of the structured block. |
| 9301 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9302 | CS->getCapturedDecl()->setNothrow(); |
| 9303 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_enter_data); |
| 9304 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9305 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9306 | // 1.2.2 OpenMP Language Terminology |
| 9307 | // Structured block - An executable statement with a single entry at the |
| 9308 | // top and a single exit at the bottom. |
| 9309 | // The point of exit cannot be a branch out of the structured block. |
| 9310 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9311 | CS->getCapturedDecl()->setNothrow(); |
| 9312 | } |
| 9313 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9314 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9315 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9316 | if (!hasClauses(Clauses, OMPC_map)) { |
| 9317 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 9318 | << "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9319 | return StmtError(); |
| 9320 | } |
| 9321 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9322 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9323 | AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9324 | } |
| 9325 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9326 | StmtResult |
| 9327 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 9328 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9329 | SourceLocation EndLoc, Stmt *AStmt) { |
| 9330 | if (!AStmt) |
| 9331 | return StmtError(); |
| 9332 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9333 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9334 | // 1.2.2 OpenMP Language Terminology |
| 9335 | // Structured block - An executable statement with a single entry at the |
| 9336 | // top and a single exit at the bottom. |
| 9337 | // The point of exit cannot be a branch out of the structured block. |
| 9338 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9339 | CS->getCapturedDecl()->setNothrow(); |
| 9340 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_exit_data); |
| 9341 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9342 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9343 | // 1.2.2 OpenMP Language Terminology |
| 9344 | // Structured block - An executable statement with a single entry at the |
| 9345 | // top and a single exit at the bottom. |
| 9346 | // The point of exit cannot be a branch out of the structured block. |
| 9347 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9348 | CS->getCapturedDecl()->setNothrow(); |
| 9349 | } |
| 9350 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9351 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9352 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9353 | if (!hasClauses(Clauses, OMPC_map)) { |
| 9354 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 9355 | << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9356 | return StmtError(); |
| 9357 | } |
| 9358 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9359 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9360 | AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9361 | } |
| 9362 | |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 9363 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 9364 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9365 | SourceLocation EndLoc, |
| 9366 | Stmt *AStmt) { |
| 9367 | if (!AStmt) |
| 9368 | return StmtError(); |
| 9369 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9370 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9371 | // 1.2.2 OpenMP Language Terminology |
| 9372 | // Structured block - An executable statement with a single entry at the |
| 9373 | // top and a single exit at the bottom. |
| 9374 | // The point of exit cannot be a branch out of the structured block. |
| 9375 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9376 | CS->getCapturedDecl()->setNothrow(); |
| 9377 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_update); |
| 9378 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9379 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9380 | // 1.2.2 OpenMP Language Terminology |
| 9381 | // Structured block - An executable statement with a single entry at the |
| 9382 | // top and a single exit at the bottom. |
| 9383 | // The point of exit cannot be a branch out of the structured block. |
| 9384 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9385 | CS->getCapturedDecl()->setNothrow(); |
| 9386 | } |
| 9387 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 9388 | if (!hasClauses(Clauses, OMPC_to, OMPC_from)) { |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 9389 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 9390 | return StmtError(); |
| 9391 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 9392 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9393 | AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 9394 | } |
| 9395 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9396 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 9397 | Stmt *AStmt, SourceLocation StartLoc, |
| 9398 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9399 | if (!AStmt) |
| 9400 | return StmtError(); |
| 9401 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9402 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9403 | // 1.2.2 OpenMP Language Terminology |
| 9404 | // Structured block - An executable statement with a single entry at the |
| 9405 | // top and a single exit at the bottom. |
| 9406 | // The point of exit cannot be a branch out of the structured block. |
| 9407 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9408 | CS->getCapturedDecl()->setNothrow(); |
| 9409 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9410 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9411 | |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 9412 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 9413 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 9414 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 9415 | } |
| 9416 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 9417 | StmtResult |
| 9418 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 9419 | SourceLocation EndLoc, |
| 9420 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 9421 | if (DSAStack->isParentNowaitRegion()) { |
| 9422 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 9423 | return StmtError(); |
| 9424 | } |
| 9425 | if (DSAStack->isParentOrderedRegion()) { |
| 9426 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 9427 | return StmtError(); |
| 9428 | } |
| 9429 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 9430 | CancelRegion); |
| 9431 | } |
| 9432 | |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 9433 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 9434 | SourceLocation StartLoc, |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 9435 | SourceLocation EndLoc, |
| 9436 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 9437 | if (DSAStack->isParentNowaitRegion()) { |
| 9438 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 9439 | return StmtError(); |
| 9440 | } |
| 9441 | if (DSAStack->isParentOrderedRegion()) { |
| 9442 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 9443 | return StmtError(); |
| 9444 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 9445 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 9446 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 9447 | CancelRegion); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 9448 | } |
| 9449 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9450 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 9451 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9452 | const OMPClause *PrevClause = nullptr; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9453 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9454 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9455 | if (C->getClauseKind() == OMPC_grainsize || |
| 9456 | C->getClauseKind() == OMPC_num_tasks) { |
| 9457 | if (!PrevClause) |
| 9458 | PrevClause = C; |
| 9459 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9460 | S.Diag(C->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9461 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 9462 | << getOpenMPClauseName(C->getClauseKind()) |
| 9463 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9464 | S.Diag(PrevClause->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9465 | diag::note_omp_previous_grainsize_num_tasks) |
| 9466 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 9467 | ErrorFound = true; |
| 9468 | } |
| 9469 | } |
| 9470 | } |
| 9471 | return ErrorFound; |
| 9472 | } |
| 9473 | |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9474 | static bool checkReductionClauseWithNogroup(Sema &S, |
| 9475 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9476 | const OMPClause *ReductionClause = nullptr; |
| 9477 | const OMPClause *NogroupClause = nullptr; |
| 9478 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9479 | if (C->getClauseKind() == OMPC_reduction) { |
| 9480 | ReductionClause = C; |
| 9481 | if (NogroupClause) |
| 9482 | break; |
| 9483 | continue; |
| 9484 | } |
| 9485 | if (C->getClauseKind() == OMPC_nogroup) { |
| 9486 | NogroupClause = C; |
| 9487 | if (ReductionClause) |
| 9488 | break; |
| 9489 | continue; |
| 9490 | } |
| 9491 | } |
| 9492 | if (ReductionClause && NogroupClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9493 | S.Diag(ReductionClause->getBeginLoc(), diag::err_omp_reduction_with_nogroup) |
| 9494 | << SourceRange(NogroupClause->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9495 | NogroupClause->getEndLoc()); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9496 | return true; |
| 9497 | } |
| 9498 | return false; |
| 9499 | } |
| 9500 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 9501 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 9502 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9503 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 9504 | if (!AStmt) |
| 9505 | return StmtError(); |
| 9506 | |
| 9507 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9508 | OMPLoopDirective::HelperExprs B; |
| 9509 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9510 | // define the nested loops number. |
| 9511 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9512 | checkOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 9513 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 9514 | VarsWithImplicitDSA, B); |
| 9515 | if (NestedLoopCount == 0) |
| 9516 | return StmtError(); |
| 9517 | |
| 9518 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9519 | "omp for loop exprs were not built"); |
| 9520 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9521 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9522 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9523 | // not appear on the same taskloop directive. |
| 9524 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9525 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9526 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9527 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9528 | // clause must not be specified. |
| 9529 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9530 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9531 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9532 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 9533 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 9534 | NestedLoopCount, Clauses, AStmt, B); |
| 9535 | } |
| 9536 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 9537 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 9538 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9539 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 9540 | if (!AStmt) |
| 9541 | return StmtError(); |
| 9542 | |
| 9543 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9544 | OMPLoopDirective::HelperExprs B; |
| 9545 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9546 | // define the nested loops number. |
| 9547 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9548 | checkOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 9549 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 9550 | VarsWithImplicitDSA, B); |
| 9551 | if (NestedLoopCount == 0) |
| 9552 | return StmtError(); |
| 9553 | |
| 9554 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9555 | "omp for loop exprs were not built"); |
| 9556 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9557 | if (!CurContext->isDependentContext()) { |
| 9558 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9559 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9560 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9561 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9562 | B.NumIterations, *this, CurScope, |
| 9563 | DSAStack)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9564 | return StmtError(); |
| 9565 | } |
| 9566 | } |
| 9567 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9568 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9569 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9570 | // not appear on the same taskloop directive. |
| 9571 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9572 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9573 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9574 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9575 | // clause must not be specified. |
| 9576 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9577 | return StmtError(); |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 9578 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 9579 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9580 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9581 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 9582 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 9583 | NestedLoopCount, Clauses, AStmt, B); |
| 9584 | } |
| 9585 | |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 9586 | StmtResult Sema::ActOnOpenMPMasterTaskLoopDirective( |
| 9587 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 9588 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| 9589 | if (!AStmt) |
| 9590 | return StmtError(); |
| 9591 | |
| 9592 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9593 | OMPLoopDirective::HelperExprs B; |
| 9594 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9595 | // define the nested loops number. |
| 9596 | unsigned NestedLoopCount = |
| 9597 | checkOpenMPLoop(OMPD_master_taskloop, getCollapseNumberExpr(Clauses), |
| 9598 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 9599 | VarsWithImplicitDSA, B); |
| 9600 | if (NestedLoopCount == 0) |
| 9601 | return StmtError(); |
| 9602 | |
| 9603 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9604 | "omp for loop exprs were not built"); |
| 9605 | |
| 9606 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9607 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9608 | // not appear on the same taskloop directive. |
| 9609 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9610 | return StmtError(); |
| 9611 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9612 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9613 | // clause must not be specified. |
| 9614 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9615 | return StmtError(); |
| 9616 | |
| 9617 | setFunctionHasBranchProtectedScope(); |
| 9618 | return OMPMasterTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 9619 | NestedLoopCount, Clauses, AStmt, B); |
| 9620 | } |
| 9621 | |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 9622 | StmtResult Sema::ActOnOpenMPMasterTaskLoopSimdDirective( |
| 9623 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 9624 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| 9625 | if (!AStmt) |
| 9626 | return StmtError(); |
| 9627 | |
| 9628 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9629 | OMPLoopDirective::HelperExprs B; |
| 9630 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9631 | // define the nested loops number. |
| 9632 | unsigned NestedLoopCount = |
| 9633 | checkOpenMPLoop(OMPD_master_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 9634 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 9635 | VarsWithImplicitDSA, B); |
| 9636 | if (NestedLoopCount == 0) |
| 9637 | return StmtError(); |
| 9638 | |
| 9639 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9640 | "omp for loop exprs were not built"); |
| 9641 | |
| 9642 | if (!CurContext->isDependentContext()) { |
| 9643 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 9644 | for (OMPClause *C : Clauses) { |
| 9645 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 9646 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 9647 | B.NumIterations, *this, CurScope, |
| 9648 | DSAStack)) |
| 9649 | return StmtError(); |
| 9650 | } |
| 9651 | } |
| 9652 | |
| 9653 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9654 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9655 | // not appear on the same taskloop directive. |
| 9656 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9657 | return StmtError(); |
| 9658 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9659 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9660 | // clause must not be specified. |
| 9661 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9662 | return StmtError(); |
| 9663 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 9664 | return StmtError(); |
| 9665 | |
| 9666 | setFunctionHasBranchProtectedScope(); |
| 9667 | return OMPMasterTaskLoopSimdDirective::Create( |
| 9668 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 9669 | } |
| 9670 | |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 9671 | StmtResult Sema::ActOnOpenMPParallelMasterTaskLoopDirective( |
| 9672 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 9673 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| 9674 | if (!AStmt) |
| 9675 | return StmtError(); |
| 9676 | |
| 9677 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9678 | auto *CS = cast<CapturedStmt>(AStmt); |
| 9679 | // 1.2.2 OpenMP Language Terminology |
| 9680 | // Structured block - An executable statement with a single entry at the |
| 9681 | // top and a single exit at the bottom. |
| 9682 | // The point of exit cannot be a branch out of the structured block. |
| 9683 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9684 | CS->getCapturedDecl()->setNothrow(); |
| 9685 | for (int ThisCaptureLevel = |
| 9686 | getOpenMPCaptureLevels(OMPD_parallel_master_taskloop); |
| 9687 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9688 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9689 | // 1.2.2 OpenMP Language Terminology |
| 9690 | // Structured block - An executable statement with a single entry at the |
| 9691 | // top and a single exit at the bottom. |
| 9692 | // The point of exit cannot be a branch out of the structured block. |
| 9693 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9694 | CS->getCapturedDecl()->setNothrow(); |
| 9695 | } |
| 9696 | |
| 9697 | OMPLoopDirective::HelperExprs B; |
| 9698 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9699 | // define the nested loops number. |
| 9700 | unsigned NestedLoopCount = checkOpenMPLoop( |
| 9701 | OMPD_parallel_master_taskloop, getCollapseNumberExpr(Clauses), |
| 9702 | /*OrderedLoopCountExpr=*/nullptr, CS, *this, *DSAStack, |
| 9703 | VarsWithImplicitDSA, B); |
| 9704 | if (NestedLoopCount == 0) |
| 9705 | return StmtError(); |
| 9706 | |
| 9707 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9708 | "omp for loop exprs were not built"); |
| 9709 | |
| 9710 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9711 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9712 | // not appear on the same taskloop directive. |
| 9713 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9714 | return StmtError(); |
| 9715 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9716 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9717 | // clause must not be specified. |
| 9718 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9719 | return StmtError(); |
| 9720 | |
| 9721 | setFunctionHasBranchProtectedScope(); |
| 9722 | return OMPParallelMasterTaskLoopDirective::Create( |
| 9723 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 9724 | } |
| 9725 | |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 9726 | StmtResult Sema::ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
| 9727 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 9728 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| 9729 | if (!AStmt) |
| 9730 | return StmtError(); |
| 9731 | |
| 9732 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9733 | auto *CS = cast<CapturedStmt>(AStmt); |
| 9734 | // 1.2.2 OpenMP Language Terminology |
| 9735 | // Structured block - An executable statement with a single entry at the |
| 9736 | // top and a single exit at the bottom. |
| 9737 | // The point of exit cannot be a branch out of the structured block. |
| 9738 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9739 | CS->getCapturedDecl()->setNothrow(); |
| 9740 | for (int ThisCaptureLevel = |
| 9741 | getOpenMPCaptureLevels(OMPD_parallel_master_taskloop_simd); |
| 9742 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9743 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9744 | // 1.2.2 OpenMP Language Terminology |
| 9745 | // Structured block - An executable statement with a single entry at the |
| 9746 | // top and a single exit at the bottom. |
| 9747 | // The point of exit cannot be a branch out of the structured block. |
| 9748 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9749 | CS->getCapturedDecl()->setNothrow(); |
| 9750 | } |
| 9751 | |
| 9752 | OMPLoopDirective::HelperExprs B; |
| 9753 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 9754 | // define the nested loops number. |
| 9755 | unsigned NestedLoopCount = checkOpenMPLoop( |
| 9756 | OMPD_parallel_master_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 9757 | /*OrderedLoopCountExpr=*/nullptr, CS, *this, *DSAStack, |
| 9758 | VarsWithImplicitDSA, B); |
| 9759 | if (NestedLoopCount == 0) |
| 9760 | return StmtError(); |
| 9761 | |
| 9762 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9763 | "omp for loop exprs were not built"); |
| 9764 | |
| 9765 | if (!CurContext->isDependentContext()) { |
| 9766 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 9767 | for (OMPClause *C : Clauses) { |
| 9768 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 9769 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 9770 | B.NumIterations, *this, CurScope, |
| 9771 | DSAStack)) |
| 9772 | return StmtError(); |
| 9773 | } |
| 9774 | } |
| 9775 | |
| 9776 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9777 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 9778 | // not appear on the same taskloop directive. |
| 9779 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 9780 | return StmtError(); |
| 9781 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 9782 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 9783 | // clause must not be specified. |
| 9784 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 9785 | return StmtError(); |
| 9786 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 9787 | return StmtError(); |
| 9788 | |
| 9789 | setFunctionHasBranchProtectedScope(); |
| 9790 | return OMPParallelMasterTaskLoopSimdDirective::Create( |
| 9791 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 9792 | } |
| 9793 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 9794 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 9795 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9796 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 9797 | if (!AStmt) |
| 9798 | return StmtError(); |
| 9799 | |
| 9800 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 9801 | OMPLoopDirective::HelperExprs B; |
| 9802 | // In presence of clause 'collapse' with number of loops, it will |
| 9803 | // define the nested loops number. |
| 9804 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9805 | checkOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 9806 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 9807 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 9808 | if (NestedLoopCount == 0) |
| 9809 | return StmtError(); |
| 9810 | |
| 9811 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9812 | "omp for loop exprs were not built"); |
| 9813 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9814 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 9815 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 9816 | NestedLoopCount, Clauses, AStmt, B); |
| 9817 | } |
| 9818 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9819 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 9820 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9821 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9822 | if (!AStmt) |
| 9823 | return StmtError(); |
| 9824 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9825 | auto *CS = cast<CapturedStmt>(AStmt); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9826 | // 1.2.2 OpenMP Language Terminology |
| 9827 | // Structured block - An executable statement with a single entry at the |
| 9828 | // top and a single exit at the bottom. |
| 9829 | // The point of exit cannot be a branch out of the structured block. |
| 9830 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9831 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 9832 | for (int ThisCaptureLevel = |
| 9833 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for); |
| 9834 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9835 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9836 | // 1.2.2 OpenMP Language Terminology |
| 9837 | // Structured block - An executable statement with a single entry at the |
| 9838 | // top and a single exit at the bottom. |
| 9839 | // The point of exit cannot be a branch out of the structured block. |
| 9840 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9841 | CS->getCapturedDecl()->setNothrow(); |
| 9842 | } |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9843 | |
| 9844 | OMPLoopDirective::HelperExprs B; |
| 9845 | // In presence of clause 'collapse' with number of loops, it will |
| 9846 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9847 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9848 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 9849 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9850 | VarsWithImplicitDSA, B); |
| 9851 | if (NestedLoopCount == 0) |
| 9852 | return StmtError(); |
| 9853 | |
| 9854 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9855 | "omp for loop exprs were not built"); |
| 9856 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9857 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9858 | return OMPDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 9859 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 9860 | DSAStack->isCancelRegion()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 9861 | } |
| 9862 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9863 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 9864 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9865 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9866 | if (!AStmt) |
| 9867 | return StmtError(); |
| 9868 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9869 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9870 | // 1.2.2 OpenMP Language Terminology |
| 9871 | // Structured block - An executable statement with a single entry at the |
| 9872 | // top and a single exit at the bottom. |
| 9873 | // The point of exit cannot be a branch out of the structured block. |
| 9874 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9875 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 9876 | for (int ThisCaptureLevel = |
| 9877 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for_simd); |
| 9878 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9879 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9880 | // 1.2.2 OpenMP Language Terminology |
| 9881 | // Structured block - An executable statement with a single entry at the |
| 9882 | // top and a single exit at the bottom. |
| 9883 | // The point of exit cannot be a branch out of the structured block. |
| 9884 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9885 | CS->getCapturedDecl()->setNothrow(); |
| 9886 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9887 | |
| 9888 | OMPLoopDirective::HelperExprs B; |
| 9889 | // In presence of clause 'collapse' with number of loops, it will |
| 9890 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9891 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9892 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 9893 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9894 | VarsWithImplicitDSA, B); |
| 9895 | if (NestedLoopCount == 0) |
| 9896 | return StmtError(); |
| 9897 | |
| 9898 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9899 | "omp for loop exprs were not built"); |
| 9900 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 9901 | if (!CurContext->isDependentContext()) { |
| 9902 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9903 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 9904 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 9905 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 9906 | B.NumIterations, *this, CurScope, |
| 9907 | DSAStack)) |
| 9908 | return StmtError(); |
| 9909 | } |
| 9910 | } |
| 9911 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 9912 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 9913 | return StmtError(); |
| 9914 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9915 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 9916 | return OMPDistributeParallelForSimdDirective::Create( |
| 9917 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 9918 | } |
| 9919 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9920 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 9921 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9922 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9923 | if (!AStmt) |
| 9924 | return StmtError(); |
| 9925 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9926 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9927 | // 1.2.2 OpenMP Language Terminology |
| 9928 | // Structured block - An executable statement with a single entry at the |
| 9929 | // top and a single exit at the bottom. |
| 9930 | // The point of exit cannot be a branch out of the structured block. |
| 9931 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9932 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 9933 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_distribute_simd); |
| 9934 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9935 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9936 | // 1.2.2 OpenMP Language Terminology |
| 9937 | // Structured block - An executable statement with a single entry at the |
| 9938 | // top and a single exit at the bottom. |
| 9939 | // The point of exit cannot be a branch out of the structured block. |
| 9940 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9941 | CS->getCapturedDecl()->setNothrow(); |
| 9942 | } |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9943 | |
| 9944 | OMPLoopDirective::HelperExprs B; |
| 9945 | // In presence of clause 'collapse' with number of loops, it will |
| 9946 | // define the nested loops number. |
| 9947 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9948 | checkOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 9949 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 9950 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9951 | if (NestedLoopCount == 0) |
| 9952 | return StmtError(); |
| 9953 | |
| 9954 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 9955 | "omp for loop exprs were not built"); |
| 9956 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 9957 | if (!CurContext->isDependentContext()) { |
| 9958 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9959 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 9960 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 9961 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 9962 | B.NumIterations, *this, CurScope, |
| 9963 | DSAStack)) |
| 9964 | return StmtError(); |
| 9965 | } |
| 9966 | } |
| 9967 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 9968 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 9969 | return StmtError(); |
| 9970 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 9971 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 9972 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 9973 | NestedLoopCount, Clauses, AStmt, B); |
| 9974 | } |
| 9975 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 9976 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 9977 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9978 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 9979 | if (!AStmt) |
| 9980 | return StmtError(); |
| 9981 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9982 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 9983 | // 1.2.2 OpenMP Language Terminology |
| 9984 | // Structured block - An executable statement with a single entry at the |
| 9985 | // top and a single exit at the bottom. |
| 9986 | // The point of exit cannot be a branch out of the structured block. |
| 9987 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9988 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 9989 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 9990 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 9991 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 9992 | // 1.2.2 OpenMP Language Terminology |
| 9993 | // Structured block - An executable statement with a single entry at the |
| 9994 | // top and a single exit at the bottom. |
| 9995 | // The point of exit cannot be a branch out of the structured block. |
| 9996 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 9997 | CS->getCapturedDecl()->setNothrow(); |
| 9998 | } |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 9999 | |
| 10000 | OMPLoopDirective::HelperExprs B; |
| 10001 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 10002 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10003 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 10004 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 10005 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 10006 | VarsWithImplicitDSA, B); |
| 10007 | if (NestedLoopCount == 0) |
| 10008 | return StmtError(); |
| 10009 | |
| 10010 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10011 | "omp target parallel for simd loop exprs were not built"); |
| 10012 | |
| 10013 | if (!CurContext->isDependentContext()) { |
| 10014 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10015 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10016 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 10017 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10018 | B.NumIterations, *this, CurScope, |
| 10019 | DSAStack)) |
| 10020 | return StmtError(); |
| 10021 | } |
| 10022 | } |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 10023 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 10024 | return StmtError(); |
| 10025 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10026 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 10027 | return OMPTargetParallelForSimdDirective::Create( |
| 10028 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10029 | } |
| 10030 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10031 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 10032 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10033 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10034 | if (!AStmt) |
| 10035 | return StmtError(); |
| 10036 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10037 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10038 | // 1.2.2 OpenMP Language Terminology |
| 10039 | // Structured block - An executable statement with a single entry at the |
| 10040 | // top and a single exit at the bottom. |
| 10041 | // The point of exit cannot be a branch out of the structured block. |
| 10042 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10043 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 10044 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_simd); |
| 10045 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10046 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10047 | // 1.2.2 OpenMP Language Terminology |
| 10048 | // Structured block - An executable statement with a single entry at the |
| 10049 | // top and a single exit at the bottom. |
| 10050 | // The point of exit cannot be a branch out of the structured block. |
| 10051 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10052 | CS->getCapturedDecl()->setNothrow(); |
| 10053 | } |
| 10054 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10055 | OMPLoopDirective::HelperExprs B; |
| 10056 | // In presence of clause 'collapse' with number of loops, it will define the |
| 10057 | // nested loops number. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10058 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10059 | checkOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 10060 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10061 | VarsWithImplicitDSA, B); |
| 10062 | if (NestedLoopCount == 0) |
| 10063 | return StmtError(); |
| 10064 | |
| 10065 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10066 | "omp target simd loop exprs were not built"); |
| 10067 | |
| 10068 | if (!CurContext->isDependentContext()) { |
| 10069 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10070 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10071 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10072 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10073 | B.NumIterations, *this, CurScope, |
| 10074 | DSAStack)) |
| 10075 | return StmtError(); |
| 10076 | } |
| 10077 | } |
| 10078 | |
| 10079 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 10080 | return StmtError(); |
| 10081 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10082 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 10083 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 10084 | NestedLoopCount, Clauses, AStmt, B); |
| 10085 | } |
| 10086 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10087 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 10088 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10089 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10090 | if (!AStmt) |
| 10091 | return StmtError(); |
| 10092 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10093 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10094 | // 1.2.2 OpenMP Language Terminology |
| 10095 | // Structured block - An executable statement with a single entry at the |
| 10096 | // top and a single exit at the bottom. |
| 10097 | // The point of exit cannot be a branch out of the structured block. |
| 10098 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10099 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 10100 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_teams_distribute); |
| 10101 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10102 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10103 | // 1.2.2 OpenMP Language Terminology |
| 10104 | // Structured block - An executable statement with a single entry at the |
| 10105 | // top and a single exit at the bottom. |
| 10106 | // The point of exit cannot be a branch out of the structured block. |
| 10107 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10108 | CS->getCapturedDecl()->setNothrow(); |
| 10109 | } |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10110 | |
| 10111 | OMPLoopDirective::HelperExprs B; |
| 10112 | // In presence of clause 'collapse' with number of loops, it will |
| 10113 | // define the nested loops number. |
| 10114 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10115 | checkOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 10116 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 10117 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10118 | if (NestedLoopCount == 0) |
| 10119 | return StmtError(); |
| 10120 | |
| 10121 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10122 | "omp teams distribute loop exprs were not built"); |
| 10123 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10124 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 10125 | |
| 10126 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 10127 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10128 | return OMPTeamsDistributeDirective::Create( |
| 10129 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 10130 | } |
| 10131 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10132 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 10133 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10134 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10135 | if (!AStmt) |
| 10136 | return StmtError(); |
| 10137 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10138 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10139 | // 1.2.2 OpenMP Language Terminology |
| 10140 | // Structured block - An executable statement with a single entry at the |
| 10141 | // top and a single exit at the bottom. |
| 10142 | // The point of exit cannot be a branch out of the structured block. |
| 10143 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10144 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 10145 | for (int ThisCaptureLevel = |
| 10146 | getOpenMPCaptureLevels(OMPD_teams_distribute_simd); |
| 10147 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10148 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10149 | // 1.2.2 OpenMP Language Terminology |
| 10150 | // Structured block - An executable statement with a single entry at the |
| 10151 | // top and a single exit at the bottom. |
| 10152 | // The point of exit cannot be a branch out of the structured block. |
| 10153 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10154 | CS->getCapturedDecl()->setNothrow(); |
| 10155 | } |
| 10156 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10157 | |
| 10158 | OMPLoopDirective::HelperExprs B; |
| 10159 | // In presence of clause 'collapse' with number of loops, it will |
| 10160 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10161 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 10162 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 10163 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 10164 | VarsWithImplicitDSA, B); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10165 | |
| 10166 | if (NestedLoopCount == 0) |
| 10167 | return StmtError(); |
| 10168 | |
| 10169 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10170 | "omp teams distribute simd loop exprs were not built"); |
| 10171 | |
| 10172 | if (!CurContext->isDependentContext()) { |
| 10173 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10174 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10175 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 10176 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10177 | B.NumIterations, *this, CurScope, |
| 10178 | DSAStack)) |
| 10179 | return StmtError(); |
| 10180 | } |
| 10181 | } |
| 10182 | |
| 10183 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 10184 | return StmtError(); |
| 10185 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10186 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 10187 | |
| 10188 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 10189 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 10190 | return OMPTeamsDistributeSimdDirective::Create( |
| 10191 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10192 | } |
| 10193 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10194 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 10195 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10196 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10197 | if (!AStmt) |
| 10198 | return StmtError(); |
| 10199 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10200 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10201 | // 1.2.2 OpenMP Language Terminology |
| 10202 | // Structured block - An executable statement with a single entry at the |
| 10203 | // top and a single exit at the bottom. |
| 10204 | // The point of exit cannot be a branch out of the structured block. |
| 10205 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10206 | CS->getCapturedDecl()->setNothrow(); |
| 10207 | |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 10208 | for (int ThisCaptureLevel = |
| 10209 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for_simd); |
| 10210 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10211 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10212 | // 1.2.2 OpenMP Language Terminology |
| 10213 | // Structured block - An executable statement with a single entry at the |
| 10214 | // top and a single exit at the bottom. |
| 10215 | // The point of exit cannot be a branch out of the structured block. |
| 10216 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10217 | CS->getCapturedDecl()->setNothrow(); |
| 10218 | } |
| 10219 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10220 | OMPLoopDirective::HelperExprs B; |
| 10221 | // In presence of clause 'collapse' with number of loops, it will |
| 10222 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10223 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10224 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 10225 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10226 | VarsWithImplicitDSA, B); |
| 10227 | |
| 10228 | if (NestedLoopCount == 0) |
| 10229 | return StmtError(); |
| 10230 | |
| 10231 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10232 | "omp for loop exprs were not built"); |
| 10233 | |
| 10234 | if (!CurContext->isDependentContext()) { |
| 10235 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10236 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10237 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 10238 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10239 | B.NumIterations, *this, CurScope, |
| 10240 | DSAStack)) |
| 10241 | return StmtError(); |
| 10242 | } |
| 10243 | } |
| 10244 | |
| 10245 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 10246 | return StmtError(); |
| 10247 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10248 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 10249 | |
| 10250 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 10251 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10252 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 10253 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10254 | } |
| 10255 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10256 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 10257 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10258 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10259 | if (!AStmt) |
| 10260 | return StmtError(); |
| 10261 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10262 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10263 | // 1.2.2 OpenMP Language Terminology |
| 10264 | // Structured block - An executable statement with a single entry at the |
| 10265 | // top and a single exit at the bottom. |
| 10266 | // The point of exit cannot be a branch out of the structured block. |
| 10267 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10268 | CS->getCapturedDecl()->setNothrow(); |
| 10269 | |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10270 | for (int ThisCaptureLevel = |
| 10271 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for); |
| 10272 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10273 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10274 | // 1.2.2 OpenMP Language Terminology |
| 10275 | // Structured block - An executable statement with a single entry at the |
| 10276 | // top and a single exit at the bottom. |
| 10277 | // The point of exit cannot be a branch out of the structured block. |
| 10278 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10279 | CS->getCapturedDecl()->setNothrow(); |
| 10280 | } |
| 10281 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10282 | OMPLoopDirective::HelperExprs B; |
| 10283 | // In presence of clause 'collapse' with number of loops, it will |
| 10284 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10285 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10286 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10287 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10288 | VarsWithImplicitDSA, B); |
| 10289 | |
| 10290 | if (NestedLoopCount == 0) |
| 10291 | return StmtError(); |
| 10292 | |
| 10293 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10294 | "omp for loop exprs were not built"); |
| 10295 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10296 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 10297 | |
| 10298 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 10299 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10300 | return OMPTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 10301 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 10302 | DSAStack->isCancelRegion()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 10303 | } |
| 10304 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 10305 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 10306 | Stmt *AStmt, |
| 10307 | SourceLocation StartLoc, |
| 10308 | SourceLocation EndLoc) { |
| 10309 | if (!AStmt) |
| 10310 | return StmtError(); |
| 10311 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10312 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 10313 | // 1.2.2 OpenMP Language Terminology |
| 10314 | // Structured block - An executable statement with a single entry at the |
| 10315 | // top and a single exit at the bottom. |
| 10316 | // The point of exit cannot be a branch out of the structured block. |
| 10317 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10318 | CS->getCapturedDecl()->setNothrow(); |
| 10319 | |
| Alexey Bataev | f9fc42e | 2017-11-22 14:25:55 +0000 | [diff] [blame] | 10320 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_teams); |
| 10321 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10322 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10323 | // 1.2.2 OpenMP Language Terminology |
| 10324 | // Structured block - An executable statement with a single entry at the |
| 10325 | // top and a single exit at the bottom. |
| 10326 | // The point of exit cannot be a branch out of the structured block. |
| 10327 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10328 | CS->getCapturedDecl()->setNothrow(); |
| 10329 | } |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10330 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 10331 | |
| 10332 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 10333 | AStmt); |
| 10334 | } |
| 10335 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10336 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 10337 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10338 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10339 | if (!AStmt) |
| 10340 | return StmtError(); |
| 10341 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10342 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10343 | // 1.2.2 OpenMP Language Terminology |
| 10344 | // Structured block - An executable statement with a single entry at the |
| 10345 | // top and a single exit at the bottom. |
| 10346 | // The point of exit cannot be a branch out of the structured block. |
| 10347 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10348 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 10349 | for (int ThisCaptureLevel = |
| 10350 | getOpenMPCaptureLevels(OMPD_target_teams_distribute); |
| 10351 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10352 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10353 | // 1.2.2 OpenMP Language Terminology |
| 10354 | // Structured block - An executable statement with a single entry at the |
| 10355 | // top and a single exit at the bottom. |
| 10356 | // The point of exit cannot be a branch out of the structured block. |
| 10357 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10358 | CS->getCapturedDecl()->setNothrow(); |
| 10359 | } |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10360 | |
| 10361 | OMPLoopDirective::HelperExprs B; |
| 10362 | // In presence of clause 'collapse' with number of loops, it will |
| 10363 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10364 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 10365 | OMPD_target_teams_distribute, getCollapseNumberExpr(Clauses), |
| 10366 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10367 | VarsWithImplicitDSA, B); |
| 10368 | if (NestedLoopCount == 0) |
| 10369 | return StmtError(); |
| 10370 | |
| 10371 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10372 | "omp target teams distribute loop exprs were not built"); |
| 10373 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10374 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10375 | return OMPTargetTeamsDistributeDirective::Create( |
| 10376 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10377 | } |
| 10378 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10379 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 10380 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10381 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10382 | if (!AStmt) |
| 10383 | return StmtError(); |
| 10384 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10385 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10386 | // 1.2.2 OpenMP Language Terminology |
| 10387 | // Structured block - An executable statement with a single entry at the |
| 10388 | // top and a single exit at the bottom. |
| 10389 | // The point of exit cannot be a branch out of the structured block. |
| 10390 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10391 | CS->getCapturedDecl()->setNothrow(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 10392 | for (int ThisCaptureLevel = |
| 10393 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_parallel_for); |
| 10394 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10395 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10396 | // 1.2.2 OpenMP Language Terminology |
| 10397 | // Structured block - An executable statement with a single entry at the |
| 10398 | // top and a single exit at the bottom. |
| 10399 | // The point of exit cannot be a branch out of the structured block. |
| 10400 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10401 | CS->getCapturedDecl()->setNothrow(); |
| 10402 | } |
| 10403 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10404 | OMPLoopDirective::HelperExprs B; |
| 10405 | // In presence of clause 'collapse' with number of loops, it will |
| 10406 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10407 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 10408 | OMPD_target_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 10409 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10410 | VarsWithImplicitDSA, B); |
| 10411 | if (NestedLoopCount == 0) |
| 10412 | return StmtError(); |
| 10413 | |
| 10414 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10415 | "omp target teams distribute parallel for loop exprs were not built"); |
| 10416 | |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 10417 | if (!CurContext->isDependentContext()) { |
| 10418 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10419 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 10420 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 10421 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10422 | B.NumIterations, *this, CurScope, |
| 10423 | DSAStack)) |
| 10424 | return StmtError(); |
| 10425 | } |
| 10426 | } |
| 10427 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10428 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10429 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 10430 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 10431 | DSAStack->isCancelRegion()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10432 | } |
| 10433 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10434 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 10435 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10436 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10437 | if (!AStmt) |
| 10438 | return StmtError(); |
| 10439 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10440 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10441 | // 1.2.2 OpenMP Language Terminology |
| 10442 | // Structured block - An executable statement with a single entry at the |
| 10443 | // top and a single exit at the bottom. |
| 10444 | // The point of exit cannot be a branch out of the structured block. |
| 10445 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10446 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 10447 | for (int ThisCaptureLevel = getOpenMPCaptureLevels( |
| 10448 | OMPD_target_teams_distribute_parallel_for_simd); |
| 10449 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10450 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10451 | // 1.2.2 OpenMP Language Terminology |
| 10452 | // Structured block - An executable statement with a single entry at the |
| 10453 | // top and a single exit at the bottom. |
| 10454 | // The point of exit cannot be a branch out of the structured block. |
| 10455 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10456 | CS->getCapturedDecl()->setNothrow(); |
| 10457 | } |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10458 | |
| 10459 | OMPLoopDirective::HelperExprs B; |
| 10460 | // In presence of clause 'collapse' with number of loops, it will |
| 10461 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10462 | unsigned NestedLoopCount = |
| 10463 | checkOpenMPLoop(OMPD_target_teams_distribute_parallel_for_simd, |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 10464 | getCollapseNumberExpr(Clauses), |
| 10465 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 10466 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10467 | if (NestedLoopCount == 0) |
| 10468 | return StmtError(); |
| 10469 | |
| 10470 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10471 | "omp target teams distribute parallel for simd loop exprs were not " |
| 10472 | "built"); |
| 10473 | |
| 10474 | if (!CurContext->isDependentContext()) { |
| 10475 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10476 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10477 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 10478 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10479 | B.NumIterations, *this, CurScope, |
| 10480 | DSAStack)) |
| 10481 | return StmtError(); |
| 10482 | } |
| 10483 | } |
| 10484 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 10485 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 10486 | return StmtError(); |
| 10487 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10488 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10489 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 10490 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10491 | } |
| 10492 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10493 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 10494 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10495 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10496 | if (!AStmt) |
| 10497 | return StmtError(); |
| 10498 | |
| 10499 | auto *CS = cast<CapturedStmt>(AStmt); |
| 10500 | // 1.2.2 OpenMP Language Terminology |
| 10501 | // Structured block - An executable statement with a single entry at the |
| 10502 | // top and a single exit at the bottom. |
| 10503 | // The point of exit cannot be a branch out of the structured block. |
| 10504 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10505 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 10506 | for (int ThisCaptureLevel = |
| 10507 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_simd); |
| 10508 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 10509 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 10510 | // 1.2.2 OpenMP Language Terminology |
| 10511 | // Structured block - An executable statement with a single entry at the |
| 10512 | // top and a single exit at the bottom. |
| 10513 | // The point of exit cannot be a branch out of the structured block. |
| 10514 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 10515 | CS->getCapturedDecl()->setNothrow(); |
| 10516 | } |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10517 | |
| 10518 | OMPLoopDirective::HelperExprs B; |
| 10519 | // In presence of clause 'collapse' with number of loops, it will |
| 10520 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10521 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10522 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 10523 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10524 | VarsWithImplicitDSA, B); |
| 10525 | if (NestedLoopCount == 0) |
| 10526 | return StmtError(); |
| 10527 | |
| 10528 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 10529 | "omp target teams distribute simd loop exprs were not built"); |
| 10530 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 10531 | if (!CurContext->isDependentContext()) { |
| 10532 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10533 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 10534 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 10535 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 10536 | B.NumIterations, *this, CurScope, |
| 10537 | DSAStack)) |
| 10538 | return StmtError(); |
| 10539 | } |
| 10540 | } |
| 10541 | |
| 10542 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 10543 | return StmtError(); |
| 10544 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 10545 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10546 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 10547 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 10548 | } |
| 10549 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10550 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10551 | SourceLocation StartLoc, |
| 10552 | SourceLocation LParenLoc, |
| 10553 | SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 10554 | OMPClause *Res = nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10555 | switch (Kind) { |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 10556 | case OMPC_final: |
| 10557 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10558 | break; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 10559 | case OMPC_num_threads: |
| 10560 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10561 | break; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 10562 | case OMPC_safelen: |
| 10563 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10564 | break; |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 10565 | case OMPC_simdlen: |
| 10566 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10567 | break; |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 10568 | case OMPC_allocator: |
| 10569 | Res = ActOnOpenMPAllocatorClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10570 | break; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 10571 | case OMPC_collapse: |
| 10572 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10573 | break; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 10574 | case OMPC_ordered: |
| 10575 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 10576 | break; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10577 | case OMPC_device: |
| 10578 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10579 | break; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10580 | case OMPC_num_teams: |
| 10581 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10582 | break; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10583 | case OMPC_thread_limit: |
| 10584 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10585 | break; |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10586 | case OMPC_priority: |
| 10587 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10588 | break; |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10589 | case OMPC_grainsize: |
| 10590 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10591 | break; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10592 | case OMPC_num_tasks: |
| 10593 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10594 | break; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10595 | case OMPC_hint: |
| 10596 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 10597 | break; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 10598 | case OMPC_if: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10599 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 10600 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 10601 | case OMPC_schedule: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10602 | case OMPC_private: |
| 10603 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10604 | case OMPC_lastprivate: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10605 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10606 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10607 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10608 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 10609 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10610 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10611 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10612 | case OMPC_copyprivate: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 10613 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 10614 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 10615 | case OMPC_mergeable: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10616 | case OMPC_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 10617 | case OMPC_allocate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 10618 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 10619 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 10620 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 10621 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 10622 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 10623 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10624 | case OMPC_depend: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 10625 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 10626 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10627 | case OMPC_map: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 10628 | case OMPC_nogroup: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10629 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10630 | case OMPC_defaultmap: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10631 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 10632 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10633 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10634 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 10635 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 10636 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 10637 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 10638 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 10639 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 10640 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 10641 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 10642 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 10643 | case OMPC_match: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 10644 | llvm_unreachable("Clause is not allowed."); |
| 10645 | } |
| 10646 | return Res; |
| 10647 | } |
| 10648 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10649 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 10650 | // for the 'target' and 'parallel' respectively. This function returns |
| 10651 | // the region in which to capture expressions associated with a clause. |
| 10652 | // A return value of OMPD_unknown signifies that the expression should not |
| 10653 | // be captured. |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10654 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 10655 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, unsigned OpenMPVersion, |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10656 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10657 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10658 | switch (CKind) { |
| 10659 | case OMPC_if: |
| 10660 | switch (DKind) { |
| 10661 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 10662 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 10663 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10664 | // If this clause applies to the nested 'parallel' region, capture within |
| 10665 | // the 'target' region, otherwise do not capture. |
| 10666 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 10667 | CaptureRegion = OMPD_target; |
| 10668 | break; |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 10669 | case OMPD_target_teams_distribute_parallel_for: |
| 10670 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 10671 | // If this clause applies to the nested 'parallel' region, capture within |
| 10672 | // the 'teams' region, otherwise do not capture. |
| 10673 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 10674 | CaptureRegion = OMPD_teams; |
| 10675 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10676 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10677 | case OMPD_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10678 | CaptureRegion = OMPD_teams; |
| 10679 | break; |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 10680 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 10681 | case OMPD_target_enter_data: |
| 10682 | case OMPD_target_exit_data: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 10683 | CaptureRegion = OMPD_task; |
| 10684 | break; |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 10685 | case OMPD_parallel_master_taskloop: |
| 10686 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_taskloop) |
| 10687 | CaptureRegion = OMPD_parallel; |
| 10688 | break; |
| Alexey Bataev | 5c517a6 | 2019-12-05 11:31:45 -0500 | [diff] [blame] | 10689 | case OMPD_parallel_master_taskloop_simd: |
| 10690 | if ((OpenMPVersion <= 45 && NameModifier == OMPD_unknown) || |
| 10691 | NameModifier == OMPD_taskloop) { |
| 10692 | CaptureRegion = OMPD_parallel; |
| 10693 | break; |
| 10694 | } |
| 10695 | if (OpenMPVersion <= 45) |
| 10696 | break; |
| 10697 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd) |
| 10698 | CaptureRegion = OMPD_taskloop; |
| 10699 | break; |
| Alexey Bataev | f59614d | 2019-11-21 10:00:56 -0500 | [diff] [blame] | 10700 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 10701 | if (OpenMPVersion <= 45) |
| 10702 | break; |
| Alexey Bataev | f59614d | 2019-11-21 10:00:56 -0500 | [diff] [blame] | 10703 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd) |
| 10704 | CaptureRegion = OMPD_parallel; |
| 10705 | break; |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 10706 | case OMPD_taskloop_simd: |
| Alexey Bataev | 853961f | 2019-12-05 09:50:18 -0500 | [diff] [blame] | 10707 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 10708 | if (OpenMPVersion <= 45) |
| 10709 | break; |
| 10710 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd) |
| 10711 | CaptureRegion = OMPD_taskloop; |
| 10712 | break; |
| Alexey Bataev | 52812f2 | 2019-12-05 13:22:15 -0500 | [diff] [blame] | 10713 | case OMPD_distribute_parallel_for_simd: |
| 10714 | if (OpenMPVersion <= 45) |
| 10715 | break; |
| 10716 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd) |
| 10717 | CaptureRegion = OMPD_parallel; |
| 10718 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10719 | case OMPD_cancel: |
| 10720 | case OMPD_parallel: |
| 10721 | case OMPD_parallel_sections: |
| 10722 | case OMPD_parallel_for: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10723 | case OMPD_target: |
| 10724 | case OMPD_target_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10725 | case OMPD_target_teams: |
| 10726 | case OMPD_target_teams_distribute: |
| 10727 | case OMPD_target_teams_distribute_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10728 | case OMPD_distribute_parallel_for: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10729 | case OMPD_task: |
| 10730 | case OMPD_taskloop: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 10731 | case OMPD_master_taskloop: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10732 | case OMPD_target_data: |
| Alexey Bataev | d08c056 | 2019-11-19 12:07:54 -0500 | [diff] [blame] | 10733 | case OMPD_simd: |
| Alexey Bataev | 103f3c9e | 2019-11-20 15:59:03 -0500 | [diff] [blame] | 10734 | case OMPD_for_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10735 | // Do not capture if-clause expressions. |
| 10736 | break; |
| 10737 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 10738 | case OMPD_allocate: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10739 | case OMPD_taskyield: |
| 10740 | case OMPD_barrier: |
| 10741 | case OMPD_taskwait: |
| 10742 | case OMPD_cancellation_point: |
| 10743 | case OMPD_flush: |
| 10744 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 10745 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10746 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 10747 | case OMPD_declare_variant: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10748 | case OMPD_declare_target: |
| 10749 | case OMPD_end_declare_target: |
| 10750 | case OMPD_teams: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10751 | case OMPD_for: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10752 | case OMPD_sections: |
| 10753 | case OMPD_section: |
| 10754 | case OMPD_single: |
| 10755 | case OMPD_master: |
| 10756 | case OMPD_critical: |
| 10757 | case OMPD_taskgroup: |
| 10758 | case OMPD_distribute: |
| 10759 | case OMPD_ordered: |
| 10760 | case OMPD_atomic: |
| 10761 | case OMPD_distribute_simd: |
| 10762 | case OMPD_teams_distribute: |
| 10763 | case OMPD_teams_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 10764 | case OMPD_requires: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10765 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 10766 | case OMPD_unknown: |
| 10767 | llvm_unreachable("Unknown OpenMP directive"); |
| 10768 | } |
| 10769 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10770 | case OMPC_num_threads: |
| 10771 | switch (DKind) { |
| 10772 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 10773 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 10774 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10775 | CaptureRegion = OMPD_target; |
| 10776 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10777 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10778 | case OMPD_teams_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 10779 | case OMPD_target_teams_distribute_parallel_for: |
| 10780 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 10781 | CaptureRegion = OMPD_teams; |
| 10782 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10783 | case OMPD_parallel: |
| 10784 | case OMPD_parallel_sections: |
| 10785 | case OMPD_parallel_for: |
| 10786 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10787 | case OMPD_distribute_parallel_for: |
| 10788 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 10789 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 10790 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10791 | // Do not capture num_threads-clause expressions. |
| 10792 | break; |
| 10793 | case OMPD_target_data: |
| 10794 | case OMPD_target_enter_data: |
| 10795 | case OMPD_target_exit_data: |
| 10796 | case OMPD_target_update: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10797 | case OMPD_target: |
| 10798 | case OMPD_target_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10799 | case OMPD_target_teams: |
| 10800 | case OMPD_target_teams_distribute: |
| 10801 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10802 | case OMPD_cancel: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10803 | case OMPD_task: |
| 10804 | case OMPD_taskloop: |
| 10805 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 10806 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 10807 | case OMPD_master_taskloop_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10808 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 10809 | case OMPD_allocate: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10810 | case OMPD_taskyield: |
| 10811 | case OMPD_barrier: |
| 10812 | case OMPD_taskwait: |
| 10813 | case OMPD_cancellation_point: |
| 10814 | case OMPD_flush: |
| 10815 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 10816 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10817 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 10818 | case OMPD_declare_variant: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10819 | case OMPD_declare_target: |
| 10820 | case OMPD_end_declare_target: |
| 10821 | case OMPD_teams: |
| 10822 | case OMPD_simd: |
| 10823 | case OMPD_for: |
| 10824 | case OMPD_for_simd: |
| 10825 | case OMPD_sections: |
| 10826 | case OMPD_section: |
| 10827 | case OMPD_single: |
| 10828 | case OMPD_master: |
| 10829 | case OMPD_critical: |
| 10830 | case OMPD_taskgroup: |
| 10831 | case OMPD_distribute: |
| 10832 | case OMPD_ordered: |
| 10833 | case OMPD_atomic: |
| 10834 | case OMPD_distribute_simd: |
| 10835 | case OMPD_teams_distribute: |
| 10836 | case OMPD_teams_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 10837 | case OMPD_requires: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 10838 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 10839 | case OMPD_unknown: |
| 10840 | llvm_unreachable("Unknown OpenMP directive"); |
| 10841 | } |
| 10842 | break; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10843 | case OMPC_num_teams: |
| 10844 | switch (DKind) { |
| 10845 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10846 | case OMPD_target_teams_distribute: |
| 10847 | case OMPD_target_teams_distribute_simd: |
| 10848 | case OMPD_target_teams_distribute_parallel_for: |
| 10849 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10850 | CaptureRegion = OMPD_target; |
| 10851 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10852 | case OMPD_teams_distribute_parallel_for: |
| 10853 | case OMPD_teams_distribute_parallel_for_simd: |
| 10854 | case OMPD_teams: |
| 10855 | case OMPD_teams_distribute: |
| 10856 | case OMPD_teams_distribute_simd: |
| 10857 | // Do not capture num_teams-clause expressions. |
| 10858 | break; |
| 10859 | case OMPD_distribute_parallel_for: |
| 10860 | case OMPD_distribute_parallel_for_simd: |
| 10861 | case OMPD_task: |
| 10862 | case OMPD_taskloop: |
| 10863 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 10864 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 10865 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 10866 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 10867 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10868 | case OMPD_target_data: |
| 10869 | case OMPD_target_enter_data: |
| 10870 | case OMPD_target_exit_data: |
| 10871 | case OMPD_target_update: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10872 | case OMPD_cancel: |
| 10873 | case OMPD_parallel: |
| 10874 | case OMPD_parallel_sections: |
| 10875 | case OMPD_parallel_for: |
| 10876 | case OMPD_parallel_for_simd: |
| 10877 | case OMPD_target: |
| 10878 | case OMPD_target_simd: |
| 10879 | case OMPD_target_parallel: |
| 10880 | case OMPD_target_parallel_for: |
| 10881 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10882 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 10883 | case OMPD_allocate: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10884 | case OMPD_taskyield: |
| 10885 | case OMPD_barrier: |
| 10886 | case OMPD_taskwait: |
| 10887 | case OMPD_cancellation_point: |
| 10888 | case OMPD_flush: |
| 10889 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 10890 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10891 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 10892 | case OMPD_declare_variant: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10893 | case OMPD_declare_target: |
| 10894 | case OMPD_end_declare_target: |
| 10895 | case OMPD_simd: |
| 10896 | case OMPD_for: |
| 10897 | case OMPD_for_simd: |
| 10898 | case OMPD_sections: |
| 10899 | case OMPD_section: |
| 10900 | case OMPD_single: |
| 10901 | case OMPD_master: |
| 10902 | case OMPD_critical: |
| 10903 | case OMPD_taskgroup: |
| 10904 | case OMPD_distribute: |
| 10905 | case OMPD_ordered: |
| 10906 | case OMPD_atomic: |
| 10907 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 10908 | case OMPD_requires: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 10909 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 10910 | case OMPD_unknown: |
| 10911 | llvm_unreachable("Unknown OpenMP directive"); |
| 10912 | } |
| 10913 | break; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10914 | case OMPC_thread_limit: |
| 10915 | switch (DKind) { |
| 10916 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10917 | case OMPD_target_teams_distribute: |
| 10918 | case OMPD_target_teams_distribute_simd: |
| 10919 | case OMPD_target_teams_distribute_parallel_for: |
| 10920 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10921 | CaptureRegion = OMPD_target; |
| 10922 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10923 | case OMPD_teams_distribute_parallel_for: |
| 10924 | case OMPD_teams_distribute_parallel_for_simd: |
| 10925 | case OMPD_teams: |
| 10926 | case OMPD_teams_distribute: |
| 10927 | case OMPD_teams_distribute_simd: |
| 10928 | // Do not capture thread_limit-clause expressions. |
| 10929 | break; |
| 10930 | case OMPD_distribute_parallel_for: |
| 10931 | case OMPD_distribute_parallel_for_simd: |
| 10932 | case OMPD_task: |
| 10933 | case OMPD_taskloop: |
| 10934 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 10935 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 10936 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 10937 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 10938 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10939 | case OMPD_target_data: |
| 10940 | case OMPD_target_enter_data: |
| 10941 | case OMPD_target_exit_data: |
| 10942 | case OMPD_target_update: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10943 | case OMPD_cancel: |
| 10944 | case OMPD_parallel: |
| 10945 | case OMPD_parallel_sections: |
| 10946 | case OMPD_parallel_for: |
| 10947 | case OMPD_parallel_for_simd: |
| 10948 | case OMPD_target: |
| 10949 | case OMPD_target_simd: |
| 10950 | case OMPD_target_parallel: |
| 10951 | case OMPD_target_parallel_for: |
| 10952 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10953 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 10954 | case OMPD_allocate: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10955 | case OMPD_taskyield: |
| 10956 | case OMPD_barrier: |
| 10957 | case OMPD_taskwait: |
| 10958 | case OMPD_cancellation_point: |
| 10959 | case OMPD_flush: |
| 10960 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 10961 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10962 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 10963 | case OMPD_declare_variant: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10964 | case OMPD_declare_target: |
| 10965 | case OMPD_end_declare_target: |
| 10966 | case OMPD_simd: |
| 10967 | case OMPD_for: |
| 10968 | case OMPD_for_simd: |
| 10969 | case OMPD_sections: |
| 10970 | case OMPD_section: |
| 10971 | case OMPD_single: |
| 10972 | case OMPD_master: |
| 10973 | case OMPD_critical: |
| 10974 | case OMPD_taskgroup: |
| 10975 | case OMPD_distribute: |
| 10976 | case OMPD_ordered: |
| 10977 | case OMPD_atomic: |
| 10978 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 10979 | case OMPD_requires: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 10980 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 10981 | case OMPD_unknown: |
| 10982 | llvm_unreachable("Unknown OpenMP directive"); |
| 10983 | } |
| 10984 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 10985 | case OMPC_schedule: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 10986 | switch (DKind) { |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10987 | case OMPD_parallel_for: |
| 10988 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 10989 | case OMPD_distribute_parallel_for: |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 10990 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 10991 | case OMPD_teams_distribute_parallel_for: |
| 10992 | case OMPD_teams_distribute_parallel_for_simd: |
| 10993 | case OMPD_target_parallel_for: |
| 10994 | case OMPD_target_parallel_for_simd: |
| 10995 | case OMPD_target_teams_distribute_parallel_for: |
| 10996 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 10997 | CaptureRegion = OMPD_parallel; |
| 10998 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 10999 | case OMPD_for: |
| 11000 | case OMPD_for_simd: |
| 11001 | // Do not capture schedule-clause expressions. |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11002 | break; |
| 11003 | case OMPD_task: |
| 11004 | case OMPD_taskloop: |
| 11005 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 11006 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 11007 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 11008 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 11009 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11010 | case OMPD_target_data: |
| 11011 | case OMPD_target_enter_data: |
| 11012 | case OMPD_target_exit_data: |
| 11013 | case OMPD_target_update: |
| 11014 | case OMPD_teams: |
| 11015 | case OMPD_teams_distribute: |
| 11016 | case OMPD_teams_distribute_simd: |
| 11017 | case OMPD_target_teams_distribute: |
| 11018 | case OMPD_target_teams_distribute_simd: |
| 11019 | case OMPD_target: |
| 11020 | case OMPD_target_simd: |
| 11021 | case OMPD_target_parallel: |
| 11022 | case OMPD_cancel: |
| 11023 | case OMPD_parallel: |
| 11024 | case OMPD_parallel_sections: |
| 11025 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11026 | case OMPD_allocate: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11027 | case OMPD_taskyield: |
| 11028 | case OMPD_barrier: |
| 11029 | case OMPD_taskwait: |
| 11030 | case OMPD_cancellation_point: |
| 11031 | case OMPD_flush: |
| 11032 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 11033 | case OMPD_declare_mapper: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11034 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 11035 | case OMPD_declare_variant: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11036 | case OMPD_declare_target: |
| 11037 | case OMPD_end_declare_target: |
| 11038 | case OMPD_simd: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11039 | case OMPD_sections: |
| 11040 | case OMPD_section: |
| 11041 | case OMPD_single: |
| 11042 | case OMPD_master: |
| 11043 | case OMPD_critical: |
| 11044 | case OMPD_taskgroup: |
| 11045 | case OMPD_distribute: |
| 11046 | case OMPD_ordered: |
| 11047 | case OMPD_atomic: |
| 11048 | case OMPD_distribute_simd: |
| 11049 | case OMPD_target_teams: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11050 | case OMPD_requires: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 11051 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 11052 | case OMPD_unknown: |
| 11053 | llvm_unreachable("Unknown OpenMP directive"); |
| 11054 | } |
| 11055 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11056 | case OMPC_dist_schedule: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11057 | switch (DKind) { |
| 11058 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11059 | case OMPD_teams_distribute_parallel_for_simd: |
| 11060 | case OMPD_teams_distribute: |
| 11061 | case OMPD_teams_distribute_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11062 | case OMPD_target_teams_distribute_parallel_for: |
| 11063 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11064 | case OMPD_target_teams_distribute: |
| 11065 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 11066 | CaptureRegion = OMPD_teams; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11067 | break; |
| 11068 | case OMPD_distribute_parallel_for: |
| 11069 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11070 | case OMPD_distribute: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11071 | case OMPD_distribute_simd: |
| 11072 | // Do not capture thread_limit-clause expressions. |
| 11073 | break; |
| 11074 | case OMPD_parallel_for: |
| 11075 | case OMPD_parallel_for_simd: |
| 11076 | case OMPD_target_parallel_for_simd: |
| 11077 | case OMPD_target_parallel_for: |
| 11078 | case OMPD_task: |
| 11079 | case OMPD_taskloop: |
| 11080 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 11081 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 11082 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 11083 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 11084 | case OMPD_parallel_master_taskloop_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11085 | case OMPD_target_data: |
| 11086 | case OMPD_target_enter_data: |
| 11087 | case OMPD_target_exit_data: |
| 11088 | case OMPD_target_update: |
| 11089 | case OMPD_teams: |
| 11090 | case OMPD_target: |
| 11091 | case OMPD_target_simd: |
| 11092 | case OMPD_target_parallel: |
| 11093 | case OMPD_cancel: |
| 11094 | case OMPD_parallel: |
| 11095 | case OMPD_parallel_sections: |
| 11096 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11097 | case OMPD_allocate: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11098 | case OMPD_taskyield: |
| 11099 | case OMPD_barrier: |
| 11100 | case OMPD_taskwait: |
| 11101 | case OMPD_cancellation_point: |
| 11102 | case OMPD_flush: |
| 11103 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 11104 | case OMPD_declare_mapper: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11105 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 11106 | case OMPD_declare_variant: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11107 | case OMPD_declare_target: |
| 11108 | case OMPD_end_declare_target: |
| 11109 | case OMPD_simd: |
| 11110 | case OMPD_for: |
| 11111 | case OMPD_for_simd: |
| 11112 | case OMPD_sections: |
| 11113 | case OMPD_section: |
| 11114 | case OMPD_single: |
| 11115 | case OMPD_master: |
| 11116 | case OMPD_critical: |
| 11117 | case OMPD_taskgroup: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11118 | case OMPD_ordered: |
| 11119 | case OMPD_atomic: |
| 11120 | case OMPD_target_teams: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11121 | case OMPD_requires: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 11122 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 11123 | case OMPD_unknown: |
| 11124 | llvm_unreachable("Unknown OpenMP directive"); |
| 11125 | } |
| 11126 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11127 | case OMPC_device: |
| 11128 | switch (DKind) { |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 11129 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 11130 | case OMPD_target_enter_data: |
| 11131 | case OMPD_target_exit_data: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 11132 | case OMPD_target: |
| Alexey Bataev | f41c88f | 2018-01-16 15:05:16 +0000 | [diff] [blame] | 11133 | case OMPD_target_simd: |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 11134 | case OMPD_target_teams: |
| Alexey Bataev | 54d5c7d | 2018-01-16 16:27:49 +0000 | [diff] [blame] | 11135 | case OMPD_target_parallel: |
| Alexey Bataev | 79df756 | 2018-01-16 16:46:46 +0000 | [diff] [blame] | 11136 | case OMPD_target_teams_distribute: |
| Alexey Bataev | 8d16a43 | 2018-01-16 17:22:50 +0000 | [diff] [blame] | 11137 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 8ed89551 | 2018-01-16 17:41:04 +0000 | [diff] [blame] | 11138 | case OMPD_target_parallel_for: |
| Alexey Bataev | d60d1ba | 2018-01-16 17:55:15 +0000 | [diff] [blame] | 11139 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 11140 | case OMPD_target_teams_distribute_parallel_for: |
| Alexey Bataev | 9350fc3 | 2018-01-16 19:18:24 +0000 | [diff] [blame] | 11141 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 11142 | CaptureRegion = OMPD_task; |
| 11143 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11144 | case OMPD_target_data: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11145 | // Do not capture device-clause expressions. |
| 11146 | break; |
| 11147 | case OMPD_teams_distribute_parallel_for: |
| 11148 | case OMPD_teams_distribute_parallel_for_simd: |
| 11149 | case OMPD_teams: |
| 11150 | case OMPD_teams_distribute: |
| 11151 | case OMPD_teams_distribute_simd: |
| 11152 | case OMPD_distribute_parallel_for: |
| 11153 | case OMPD_distribute_parallel_for_simd: |
| 11154 | case OMPD_task: |
| 11155 | case OMPD_taskloop: |
| 11156 | case OMPD_taskloop_simd: |
| Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 11157 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 11158 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 11159 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 11160 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11161 | case OMPD_cancel: |
| 11162 | case OMPD_parallel: |
| 11163 | case OMPD_parallel_sections: |
| 11164 | case OMPD_parallel_for: |
| 11165 | case OMPD_parallel_for_simd: |
| 11166 | case OMPD_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11167 | case OMPD_allocate: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11168 | case OMPD_taskyield: |
| 11169 | case OMPD_barrier: |
| 11170 | case OMPD_taskwait: |
| 11171 | case OMPD_cancellation_point: |
| 11172 | case OMPD_flush: |
| 11173 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 11174 | case OMPD_declare_mapper: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11175 | case OMPD_declare_simd: |
| Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 11176 | case OMPD_declare_variant: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11177 | case OMPD_declare_target: |
| 11178 | case OMPD_end_declare_target: |
| 11179 | case OMPD_simd: |
| 11180 | case OMPD_for: |
| 11181 | case OMPD_for_simd: |
| 11182 | case OMPD_sections: |
| 11183 | case OMPD_section: |
| 11184 | case OMPD_single: |
| 11185 | case OMPD_master: |
| 11186 | case OMPD_critical: |
| 11187 | case OMPD_taskgroup: |
| 11188 | case OMPD_distribute: |
| 11189 | case OMPD_ordered: |
| 11190 | case OMPD_atomic: |
| 11191 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11192 | case OMPD_requires: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11193 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 11194 | case OMPD_unknown: |
| 11195 | llvm_unreachable("Unknown OpenMP directive"); |
| 11196 | } |
| 11197 | break; |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11198 | case OMPC_grainsize: |
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 11199 | case OMPC_num_tasks: |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11200 | case OMPC_final: |
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 11201 | case OMPC_priority: |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11202 | switch (DKind) { |
| 11203 | case OMPD_task: |
| 11204 | case OMPD_taskloop: |
| 11205 | case OMPD_taskloop_simd: |
| 11206 | case OMPD_master_taskloop: |
| Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 11207 | case OMPD_master_taskloop_simd: |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11208 | break; |
| 11209 | case OMPD_parallel_master_taskloop: |
| Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 11210 | case OMPD_parallel_master_taskloop_simd: |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11211 | CaptureRegion = OMPD_parallel; |
| 11212 | break; |
| 11213 | case OMPD_target_update: |
| 11214 | case OMPD_target_enter_data: |
| 11215 | case OMPD_target_exit_data: |
| 11216 | case OMPD_target: |
| 11217 | case OMPD_target_simd: |
| 11218 | case OMPD_target_teams: |
| 11219 | case OMPD_target_parallel: |
| 11220 | case OMPD_target_teams_distribute: |
| 11221 | case OMPD_target_teams_distribute_simd: |
| 11222 | case OMPD_target_parallel_for: |
| 11223 | case OMPD_target_parallel_for_simd: |
| 11224 | case OMPD_target_teams_distribute_parallel_for: |
| 11225 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 11226 | case OMPD_target_data: |
| 11227 | case OMPD_teams_distribute_parallel_for: |
| 11228 | case OMPD_teams_distribute_parallel_for_simd: |
| 11229 | case OMPD_teams: |
| 11230 | case OMPD_teams_distribute: |
| 11231 | case OMPD_teams_distribute_simd: |
| 11232 | case OMPD_distribute_parallel_for: |
| 11233 | case OMPD_distribute_parallel_for_simd: |
| 11234 | case OMPD_cancel: |
| 11235 | case OMPD_parallel: |
| 11236 | case OMPD_parallel_sections: |
| 11237 | case OMPD_parallel_for: |
| 11238 | case OMPD_parallel_for_simd: |
| 11239 | case OMPD_threadprivate: |
| 11240 | case OMPD_allocate: |
| 11241 | case OMPD_taskyield: |
| 11242 | case OMPD_barrier: |
| 11243 | case OMPD_taskwait: |
| 11244 | case OMPD_cancellation_point: |
| 11245 | case OMPD_flush: |
| 11246 | case OMPD_declare_reduction: |
| 11247 | case OMPD_declare_mapper: |
| 11248 | case OMPD_declare_simd: |
| 11249 | case OMPD_declare_variant: |
| 11250 | case OMPD_declare_target: |
| 11251 | case OMPD_end_declare_target: |
| 11252 | case OMPD_simd: |
| 11253 | case OMPD_for: |
| 11254 | case OMPD_for_simd: |
| 11255 | case OMPD_sections: |
| 11256 | case OMPD_section: |
| 11257 | case OMPD_single: |
| 11258 | case OMPD_master: |
| 11259 | case OMPD_critical: |
| 11260 | case OMPD_taskgroup: |
| 11261 | case OMPD_distribute: |
| 11262 | case OMPD_ordered: |
| 11263 | case OMPD_atomic: |
| 11264 | case OMPD_distribute_simd: |
| 11265 | case OMPD_requires: |
| 11266 | llvm_unreachable("Unexpected OpenMP directive with grainsize-clause"); |
| 11267 | case OMPD_unknown: |
| 11268 | llvm_unreachable("Unknown OpenMP directive"); |
| 11269 | } |
| 11270 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11271 | case OMPC_firstprivate: |
| 11272 | case OMPC_lastprivate: |
| 11273 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11274 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11275 | case OMPC_in_reduction: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11276 | case OMPC_linear: |
| 11277 | case OMPC_default: |
| 11278 | case OMPC_proc_bind: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11279 | case OMPC_safelen: |
| 11280 | case OMPC_simdlen: |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11281 | case OMPC_allocator: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11282 | case OMPC_collapse: |
| 11283 | case OMPC_private: |
| 11284 | case OMPC_shared: |
| 11285 | case OMPC_aligned: |
| 11286 | case OMPC_copyin: |
| 11287 | case OMPC_copyprivate: |
| 11288 | case OMPC_ordered: |
| 11289 | case OMPC_nowait: |
| 11290 | case OMPC_untied: |
| 11291 | case OMPC_mergeable: |
| 11292 | case OMPC_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11293 | case OMPC_allocate: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11294 | case OMPC_flush: |
| 11295 | case OMPC_read: |
| 11296 | case OMPC_write: |
| 11297 | case OMPC_update: |
| 11298 | case OMPC_capture: |
| 11299 | case OMPC_seq_cst: |
| 11300 | case OMPC_depend: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11301 | case OMPC_threads: |
| 11302 | case OMPC_simd: |
| 11303 | case OMPC_map: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11304 | case OMPC_nogroup: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11305 | case OMPC_hint: |
| 11306 | case OMPC_defaultmap: |
| 11307 | case OMPC_unknown: |
| 11308 | case OMPC_uniform: |
| 11309 | case OMPC_to: |
| 11310 | case OMPC_from: |
| 11311 | case OMPC_use_device_ptr: |
| 11312 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11313 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 11314 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 11315 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 11316 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 11317 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 11318 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 11319 | case OMPC_match: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11320 | llvm_unreachable("Unexpected OpenMP clause."); |
| 11321 | } |
| 11322 | return CaptureRegion; |
| 11323 | } |
| 11324 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11325 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 11326 | Expr *Condition, SourceLocation StartLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11327 | SourceLocation LParenLoc, |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11328 | SourceLocation NameModifierLoc, |
| 11329 | SourceLocation ColonLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11330 | SourceLocation EndLoc) { |
| 11331 | Expr *ValExpr = Condition; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11332 | Stmt *HelperValStmt = nullptr; |
| 11333 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11334 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 11335 | !Condition->isInstantiationDependent() && |
| 11336 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 11337 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11338 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11339 | return nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11340 | |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 11341 | ValExpr = Val.get(); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11342 | |
| 11343 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 11344 | CaptureRegion = getOpenMPCaptureRegionForClause( |
| 11345 | DKind, OMPC_if, LangOpts.OpenMP, NameModifier); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11346 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 11347 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11348 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11349 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11350 | HelperValStmt = buildPreInits(Context, Captures); |
| 11351 | } |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11352 | } |
| 11353 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 11354 | return new (Context) |
| 11355 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 11356 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11357 | } |
| 11358 | |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11359 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 11360 | SourceLocation StartLoc, |
| 11361 | SourceLocation LParenLoc, |
| 11362 | SourceLocation EndLoc) { |
| 11363 | Expr *ValExpr = Condition; |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11364 | Stmt *HelperValStmt = nullptr; |
| 11365 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11366 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 11367 | !Condition->isInstantiationDependent() && |
| 11368 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 11369 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11370 | if (Val.isInvalid()) |
| 11371 | return nullptr; |
| 11372 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 11373 | ValExpr = MakeFullExpr(Val.get()).get(); |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11374 | |
| 11375 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 11376 | CaptureRegion = |
| 11377 | getOpenMPCaptureRegionForClause(DKind, OMPC_final, LangOpts.OpenMP); |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11378 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| 11379 | ValExpr = MakeFullExpr(ValExpr).get(); |
| 11380 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| 11381 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11382 | HelperValStmt = buildPreInits(Context, Captures); |
| 11383 | } |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11384 | } |
| 11385 | |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11386 | return new (Context) OMPFinalClause(ValExpr, HelperValStmt, CaptureRegion, |
| 11387 | StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11388 | } |
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 11389 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 11390 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 11391 | Expr *Op) { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11392 | if (!Op) |
| 11393 | return ExprError(); |
| 11394 | |
| 11395 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 11396 | public: |
| 11397 | IntConvertDiagnoser() |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11398 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 11399 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 11400 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11401 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 11402 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11403 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 11404 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11405 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 11406 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11407 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 11408 | QualType T, |
| 11409 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11410 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 11411 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11412 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 11413 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11414 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11415 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11416 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11417 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 11418 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11419 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 11420 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11421 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 11422 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11423 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11424 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11425 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11426 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 11427 | QualType) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11428 | llvm_unreachable("conversion functions are permitted"); |
| 11429 | } |
| 11430 | } ConvertDiagnoser; |
| 11431 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 11432 | } |
| 11433 | |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11434 | static bool |
| 11435 | isNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, OpenMPClauseKind CKind, |
| 11436 | bool StrictlyPositive, bool BuildCapture = false, |
| 11437 | OpenMPDirectiveKind DKind = OMPD_unknown, |
| 11438 | OpenMPDirectiveKind *CaptureRegion = nullptr, |
| 11439 | Stmt **HelperValStmt = nullptr) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11440 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 11441 | !ValExpr->isInstantiationDependent()) { |
| 11442 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 11443 | ExprResult Value = |
| 11444 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 11445 | if (Value.isInvalid()) |
| 11446 | return false; |
| 11447 | |
| 11448 | ValExpr = Value.get(); |
| 11449 | // The expression must evaluate to a non-negative integer value. |
| 11450 | llvm::APSInt Result; |
| 11451 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11452 | Result.isSigned() && |
| 11453 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 11454 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11455 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11456 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 11457 | << ValExpr->getSourceRange(); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11458 | return false; |
| 11459 | } |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11460 | if (!BuildCapture) |
| 11461 | return true; |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 11462 | *CaptureRegion = |
| 11463 | getOpenMPCaptureRegionForClause(DKind, CKind, SemaRef.LangOpts.OpenMP); |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 11464 | if (*CaptureRegion != OMPD_unknown && |
| 11465 | !SemaRef.CurContext->isDependentContext()) { |
| 11466 | ValExpr = SemaRef.MakeFullExpr(ValExpr).get(); |
| 11467 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| 11468 | ValExpr = tryBuildCapture(SemaRef, ValExpr, Captures).get(); |
| 11469 | *HelperValStmt = buildPreInits(SemaRef.Context, Captures); |
| 11470 | } |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11471 | } |
| 11472 | return true; |
| 11473 | } |
| 11474 | |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11475 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 11476 | SourceLocation StartLoc, |
| 11477 | SourceLocation LParenLoc, |
| 11478 | SourceLocation EndLoc) { |
| 11479 | Expr *ValExpr = NumThreads; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 11480 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11481 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11482 | // OpenMP [2.5, Restrictions] |
| 11483 | // The num_threads expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11484 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11485 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11486 | return nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11487 | |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 11488 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11489 | OpenMPDirectiveKind CaptureRegion = |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 11490 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads, LangOpts.OpenMP); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11491 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 11492 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11493 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 11494 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11495 | HelperValStmt = buildPreInits(Context, Captures); |
| 11496 | } |
| 11497 | |
| 11498 | return new (Context) OMPNumThreadsClause( |
| 11499 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11500 | } |
| 11501 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11502 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11503 | OpenMPClauseKind CKind, |
| 11504 | bool StrictlyPositive) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11505 | if (!E) |
| 11506 | return ExprError(); |
| 11507 | if (E->isValueDependent() || E->isTypeDependent() || |
| 11508 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11509 | return E; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11510 | llvm::APSInt Result; |
| 11511 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 11512 | if (ICE.isInvalid()) |
| 11513 | return ExprError(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11514 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 11515 | (!StrictlyPositive && !Result.isNonNegative())) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11516 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11517 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 11518 | << E->getSourceRange(); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11519 | return ExprError(); |
| 11520 | } |
| Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 11521 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 11522 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 11523 | << E->getSourceRange(); |
| 11524 | return ExprError(); |
| 11525 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11526 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 11527 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 11528 | else if (CKind == OMPC_ordered) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11529 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11530 | return ICE; |
| 11531 | } |
| 11532 | |
| 11533 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 11534 | SourceLocation LParenLoc, |
| 11535 | SourceLocation EndLoc) { |
| 11536 | // OpenMP [2.8.1, simd construct, Description] |
| 11537 | // The parameter of the safelen clause must be a constant |
| 11538 | // positive integer expression. |
| 11539 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 11540 | if (Safelen.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11541 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11542 | return new (Context) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11543 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11544 | } |
| 11545 | |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 11546 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 11547 | SourceLocation LParenLoc, |
| 11548 | SourceLocation EndLoc) { |
| 11549 | // OpenMP [2.8.1, simd construct, Description] |
| 11550 | // The parameter of the simdlen clause must be a constant |
| 11551 | // positive integer expression. |
| 11552 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 11553 | if (Simdlen.isInvalid()) |
| 11554 | return nullptr; |
| 11555 | return new (Context) |
| 11556 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 11557 | } |
| 11558 | |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11559 | /// Tries to find omp_allocator_handle_t type. |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 11560 | static bool findOMPAllocatorHandleT(Sema &S, SourceLocation Loc, |
| 11561 | DSAStackTy *Stack) { |
| 11562 | QualType OMPAllocatorHandleT = Stack->getOMPAllocatorHandleT(); |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11563 | if (!OMPAllocatorHandleT.isNull()) |
| 11564 | return true; |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 11565 | // Build the predefined allocator expressions. |
| 11566 | bool ErrorFound = false; |
| 11567 | for (int I = OMPAllocateDeclAttr::OMPDefaultMemAlloc; |
| 11568 | I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) { |
| 11569 | auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I); |
| 11570 | StringRef Allocator = |
| 11571 | OMPAllocateDeclAttr::ConvertAllocatorTypeTyToStr(AllocatorKind); |
| 11572 | DeclarationName AllocatorName = &S.getASTContext().Idents.get(Allocator); |
| 11573 | auto *VD = dyn_cast_or_null<ValueDecl>( |
| 11574 | S.LookupSingleName(S.TUScope, AllocatorName, Loc, Sema::LookupAnyName)); |
| 11575 | if (!VD) { |
| 11576 | ErrorFound = true; |
| 11577 | break; |
| 11578 | } |
| 11579 | QualType AllocatorType = |
| 11580 | VD->getType().getNonLValueExprType(S.getASTContext()); |
| 11581 | ExprResult Res = S.BuildDeclRefExpr(VD, AllocatorType, VK_LValue, Loc); |
| 11582 | if (!Res.isUsable()) { |
| 11583 | ErrorFound = true; |
| 11584 | break; |
| 11585 | } |
| 11586 | if (OMPAllocatorHandleT.isNull()) |
| 11587 | OMPAllocatorHandleT = AllocatorType; |
| 11588 | if (!S.getASTContext().hasSameType(OMPAllocatorHandleT, AllocatorType)) { |
| 11589 | ErrorFound = true; |
| 11590 | break; |
| 11591 | } |
| 11592 | Stack->setAllocator(AllocatorKind, Res.get()); |
| 11593 | } |
| 11594 | if (ErrorFound) { |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11595 | S.Diag(Loc, diag::err_implied_omp_allocator_handle_t_not_found); |
| 11596 | return false; |
| 11597 | } |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 11598 | OMPAllocatorHandleT.addConst(); |
| 11599 | Stack->setOMPAllocatorHandleT(OMPAllocatorHandleT); |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11600 | return true; |
| 11601 | } |
| 11602 | |
| 11603 | OMPClause *Sema::ActOnOpenMPAllocatorClause(Expr *A, SourceLocation StartLoc, |
| 11604 | SourceLocation LParenLoc, |
| 11605 | SourceLocation EndLoc) { |
| 11606 | // OpenMP [2.11.3, allocate Directive, Description] |
| 11607 | // allocator is an expression of omp_allocator_handle_t type. |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 11608 | if (!findOMPAllocatorHandleT(*this, A->getExprLoc(), DSAStack)) |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11609 | return nullptr; |
| 11610 | |
| 11611 | ExprResult Allocator = DefaultLvalueConversion(A); |
| 11612 | if (Allocator.isInvalid()) |
| 11613 | return nullptr; |
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 11614 | Allocator = PerformImplicitConversion(Allocator.get(), |
| 11615 | DSAStack->getOMPAllocatorHandleT(), |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11616 | Sema::AA_Initializing, |
| 11617 | /*AllowExplicit=*/true); |
| 11618 | if (Allocator.isInvalid()) |
| 11619 | return nullptr; |
| 11620 | return new (Context) |
| 11621 | OMPAllocatorClause(Allocator.get(), StartLoc, LParenLoc, EndLoc); |
| 11622 | } |
| 11623 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 11624 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 11625 | SourceLocation StartLoc, |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11626 | SourceLocation LParenLoc, |
| 11627 | SourceLocation EndLoc) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 11628 | // OpenMP [2.7.1, loop construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11629 | // OpenMP [2.8.1, simd construct, Description] |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 11630 | // OpenMP [2.9.6, distribute construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11631 | // The parameter of the collapse clause must be a constant |
| 11632 | // positive integer expression. |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 11633 | ExprResult NumForLoopsResult = |
| 11634 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 11635 | if (NumForLoopsResult.isInvalid()) |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11636 | return nullptr; |
| 11637 | return new (Context) |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 11638 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11639 | } |
| 11640 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 11641 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 11642 | SourceLocation EndLoc, |
| 11643 | SourceLocation LParenLoc, |
| 11644 | Expr *NumForLoops) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 11645 | // OpenMP [2.7.1, loop construct, Description] |
| 11646 | // OpenMP [2.8.1, simd construct, Description] |
| 11647 | // OpenMP [2.9.6, distribute construct, Description] |
| 11648 | // The parameter of the ordered clause must be a constant |
| 11649 | // positive integer expression if any. |
| 11650 | if (NumForLoops && LParenLoc.isValid()) { |
| 11651 | ExprResult NumForLoopsResult = |
| 11652 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 11653 | if (NumForLoopsResult.isInvalid()) |
| 11654 | return nullptr; |
| 11655 | NumForLoops = NumForLoopsResult.get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11656 | } else { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 11657 | NumForLoops = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11658 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11659 | auto *Clause = OMPOrderedClause::Create( |
| 11660 | Context, NumForLoops, NumForLoops ? DSAStack->getAssociatedLoops() : 0, |
| 11661 | StartLoc, LParenLoc, EndLoc); |
| 11662 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops, Clause); |
| 11663 | return Clause; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 11664 | } |
| 11665 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11666 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 11667 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 11668 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11669 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11670 | switch (Kind) { |
| 11671 | case OMPC_default: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11672 | Res = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11673 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 11674 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11675 | break; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11676 | case OMPC_proc_bind: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11677 | Res = ActOnOpenMPProcBindClause( |
| 11678 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 11679 | LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11680 | break; |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 11681 | case OMPC_atomic_default_mem_order: |
| 11682 | Res = ActOnOpenMPAtomicDefaultMemOrderClause( |
| 11683 | static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Argument), |
| 11684 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
| 11685 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11686 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11687 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 11688 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 11689 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 11690 | case OMPC_simdlen: |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11691 | case OMPC_allocator: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 11692 | case OMPC_collapse: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11693 | case OMPC_schedule: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11694 | case OMPC_private: |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 11695 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 11696 | case OMPC_lastprivate: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11697 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11698 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11699 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11700 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11701 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11702 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11703 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11704 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 11705 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 11706 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 11707 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 11708 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11709 | case OMPC_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11710 | case OMPC_allocate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 11711 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 11712 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 11713 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 11714 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 11715 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 11716 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11717 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 11718 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 11719 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 11720 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11721 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11722 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11723 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11724 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11725 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 11726 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11727 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11728 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11729 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11730 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11731 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 11732 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11733 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11734 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11735 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11736 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11737 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 11738 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 11739 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 11740 | case OMPC_dynamic_allocators: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 11741 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 11742 | case OMPC_match: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11743 | llvm_unreachable("Clause is not allowed."); |
| 11744 | } |
| 11745 | return Res; |
| 11746 | } |
| 11747 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11748 | static std::string |
| 11749 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 11750 | ArrayRef<unsigned> Exclude = llvm::None) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11751 | SmallString<256> Buffer; |
| 11752 | llvm::raw_svector_ostream Out(Buffer); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11753 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 11754 | unsigned Skipped = Exclude.size(); |
| 11755 | auto S = Exclude.begin(), E = Exclude.end(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11756 | for (unsigned I = First; I < Last; ++I) { |
| 11757 | if (std::find(S, E, I) != E) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11758 | --Skipped; |
| 11759 | continue; |
| 11760 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11761 | Out << "'" << getOpenMPSimpleClauseTypeName(K, I) << "'"; |
| 11762 | if (I == Bound - Skipped) |
| 11763 | Out << " or "; |
| 11764 | else if (I != Bound + 1 - Skipped) |
| 11765 | Out << ", "; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11766 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11767 | return Out.str(); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11768 | } |
| 11769 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11770 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 11771 | SourceLocation KindKwLoc, |
| 11772 | SourceLocation StartLoc, |
| 11773 | SourceLocation LParenLoc, |
| 11774 | SourceLocation EndLoc) { |
| 11775 | if (Kind == OMPC_DEFAULT_unknown) { |
| Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 11776 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 11777 | "OMPC_DEFAULT_unknown not greater than 0"); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11778 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11779 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 11780 | /*Last=*/OMPC_DEFAULT_unknown) |
| 11781 | << getOpenMPClauseName(OMPC_default); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11782 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11783 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11784 | switch (Kind) { |
| 11785 | case OMPC_DEFAULT_none: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11786 | DSAStack->setDefaultDSANone(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11787 | break; |
| 11788 | case OMPC_DEFAULT_shared: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11789 | DSAStack->setDefaultDSAShared(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11790 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11791 | case OMPC_DEFAULT_unknown: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 11792 | llvm_unreachable("Clause kind is not allowed."); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 11793 | break; |
| 11794 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11795 | return new (Context) |
| 11796 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 11797 | } |
| 11798 | |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11799 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 11800 | SourceLocation KindKwLoc, |
| 11801 | SourceLocation StartLoc, |
| 11802 | SourceLocation LParenLoc, |
| 11803 | SourceLocation EndLoc) { |
| 11804 | if (Kind == OMPC_PROC_BIND_unknown) { |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11805 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11806 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 11807 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 11808 | << getOpenMPClauseName(OMPC_proc_bind); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11809 | return nullptr; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11810 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11811 | return new (Context) |
| 11812 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 11813 | } |
| 11814 | |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 11815 | OMPClause *Sema::ActOnOpenMPAtomicDefaultMemOrderClause( |
| 11816 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindKwLoc, |
| 11817 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 11818 | if (Kind == OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown) { |
| 11819 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| 11820 | << getListOfPossibleValues( |
| 11821 | OMPC_atomic_default_mem_order, /*First=*/0, |
| 11822 | /*Last=*/OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown) |
| 11823 | << getOpenMPClauseName(OMPC_atomic_default_mem_order); |
| 11824 | return nullptr; |
| 11825 | } |
| 11826 | return new (Context) OMPAtomicDefaultMemOrderClause(Kind, KindKwLoc, StartLoc, |
| 11827 | LParenLoc, EndLoc); |
| 11828 | } |
| 11829 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11830 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11831 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11832 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11833 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11834 | SourceLocation EndLoc) { |
| 11835 | OMPClause *Res = nullptr; |
| 11836 | switch (Kind) { |
| 11837 | case OMPC_schedule: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11838 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 11839 | assert(Argument.size() == NumberOfElements && |
| 11840 | ArgumentLoc.size() == NumberOfElements); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11841 | Res = ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11842 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 11843 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 11844 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 11845 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 11846 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11847 | break; |
| 11848 | case OMPC_if: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11849 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 11850 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 11851 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 11852 | DelimLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11853 | break; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11854 | case OMPC_dist_schedule: |
| 11855 | Res = ActOnOpenMPDistScheduleClause( |
| 11856 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 11857 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 11858 | break; |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11859 | case OMPC_defaultmap: |
| 11860 | enum { Modifier, DefaultmapKind }; |
| 11861 | Res = ActOnOpenMPDefaultmapClause( |
| 11862 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 11863 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11864 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 11865 | EndLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11866 | break; |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 11867 | case OMPC_final: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11868 | case OMPC_num_threads: |
| 11869 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 11870 | case OMPC_simdlen: |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11871 | case OMPC_allocator: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11872 | case OMPC_collapse: |
| 11873 | case OMPC_default: |
| 11874 | case OMPC_proc_bind: |
| 11875 | case OMPC_private: |
| 11876 | case OMPC_firstprivate: |
| 11877 | case OMPC_lastprivate: |
| 11878 | case OMPC_shared: |
| 11879 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11880 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11881 | case OMPC_in_reduction: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11882 | case OMPC_linear: |
| 11883 | case OMPC_aligned: |
| 11884 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11885 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 11886 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 11887 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 11888 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 11889 | case OMPC_mergeable: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11890 | case OMPC_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 11891 | case OMPC_allocate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 11892 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 11893 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 11894 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 11895 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 11896 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 11897 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11898 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 11899 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 11900 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 11901 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11902 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11903 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11904 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11905 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11906 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 11907 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11908 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11909 | case OMPC_hint: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11910 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 11911 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11912 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11913 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11914 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11915 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11916 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 11917 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 11918 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 11919 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 11920 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 11921 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 11922 | case OMPC_match: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11923 | llvm_unreachable("Clause is not allowed."); |
| 11924 | } |
| 11925 | return Res; |
| 11926 | } |
| 11927 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11928 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 11929 | OpenMPScheduleClauseModifier M2, |
| 11930 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 11931 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 11932 | SmallVector<unsigned, 2> Excluded; |
| 11933 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 11934 | Excluded.push_back(M2); |
| 11935 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 11936 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 11937 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 11938 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 11939 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 11940 | << getListOfPossibleValues(OMPC_schedule, |
| 11941 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 11942 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 11943 | Excluded) |
| 11944 | << getOpenMPClauseName(OMPC_schedule); |
| 11945 | return true; |
| 11946 | } |
| 11947 | return false; |
| 11948 | } |
| 11949 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11950 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11951 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11952 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11953 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 11954 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 11955 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 11956 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 11957 | return nullptr; |
| 11958 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 11959 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 11960 | // but not both. |
| 11961 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 11962 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 11963 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 11964 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 11965 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 11966 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 11967 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 11968 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 11969 | return nullptr; |
| 11970 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11971 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 11972 | std::string Values; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11973 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 11974 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 11975 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 11976 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 11977 | Exclude); |
| 11978 | } else { |
| 11979 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 11980 | /*Last=*/OMPC_SCHEDULE_unknown); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11981 | } |
| 11982 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11983 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 11984 | return nullptr; |
| 11985 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11986 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 11987 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 11988 | // schedule(guided). |
| 11989 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 11990 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 11991 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 11992 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 11993 | diag::err_omp_schedule_nonmonotonic_static); |
| 11994 | return nullptr; |
| 11995 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11996 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11997 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 11998 | if (ChunkSize) { |
| 11999 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 12000 | !ChunkSize->isInstantiationDependent() && |
| 12001 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12002 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 12003 | ExprResult Val = |
| 12004 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 12005 | if (Val.isInvalid()) |
| 12006 | return nullptr; |
| 12007 | |
| 12008 | ValExpr = Val.get(); |
| 12009 | |
| 12010 | // OpenMP [2.7.1, Restrictions] |
| 12011 | // chunk_size must be a loop invariant integer expression with a positive |
| 12012 | // value. |
| 12013 | llvm::APSInt Result; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 12014 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 12015 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 12016 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12017 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 12018 | return nullptr; |
| 12019 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 12020 | } else if (getOpenMPCaptureRegionForClause( |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 12021 | DSAStack->getCurrentDirective(), OMPC_schedule, |
| 12022 | LangOpts.OpenMP) != OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 12023 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 12024 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12025 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 12026 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 12027 | HelperValStmt = buildPreInits(Context, Captures); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 12028 | } |
| 12029 | } |
| 12030 | } |
| 12031 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 12032 | return new (Context) |
| 12033 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 12034 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 12035 | } |
| 12036 | |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12037 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 12038 | SourceLocation StartLoc, |
| 12039 | SourceLocation EndLoc) { |
| 12040 | OMPClause *Res = nullptr; |
| 12041 | switch (Kind) { |
| 12042 | case OMPC_ordered: |
| 12043 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 12044 | break; |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 12045 | case OMPC_nowait: |
| 12046 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 12047 | break; |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 12048 | case OMPC_untied: |
| 12049 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 12050 | break; |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 12051 | case OMPC_mergeable: |
| 12052 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 12053 | break; |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 12054 | case OMPC_read: |
| 12055 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 12056 | break; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 12057 | case OMPC_write: |
| 12058 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 12059 | break; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 12060 | case OMPC_update: |
| 12061 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 12062 | break; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 12063 | case OMPC_capture: |
| 12064 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 12065 | break; |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 12066 | case OMPC_seq_cst: |
| 12067 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 12068 | break; |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 12069 | case OMPC_threads: |
| 12070 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 12071 | break; |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 12072 | case OMPC_simd: |
| 12073 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 12074 | break; |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 12075 | case OMPC_nogroup: |
| 12076 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 12077 | break; |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 12078 | case OMPC_unified_address: |
| 12079 | Res = ActOnOpenMPUnifiedAddressClause(StartLoc, EndLoc); |
| 12080 | break; |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 12081 | case OMPC_unified_shared_memory: |
| 12082 | Res = ActOnOpenMPUnifiedSharedMemoryClause(StartLoc, EndLoc); |
| 12083 | break; |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 12084 | case OMPC_reverse_offload: |
| 12085 | Res = ActOnOpenMPReverseOffloadClause(StartLoc, EndLoc); |
| 12086 | break; |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 12087 | case OMPC_dynamic_allocators: |
| 12088 | Res = ActOnOpenMPDynamicAllocatorsClause(StartLoc, EndLoc); |
| 12089 | break; |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12090 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 12091 | case OMPC_final: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12092 | case OMPC_num_threads: |
| 12093 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 12094 | case OMPC_simdlen: |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 12095 | case OMPC_allocator: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12096 | case OMPC_collapse: |
| 12097 | case OMPC_schedule: |
| 12098 | case OMPC_private: |
| 12099 | case OMPC_firstprivate: |
| 12100 | case OMPC_lastprivate: |
| 12101 | case OMPC_shared: |
| 12102 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 12103 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 12104 | case OMPC_in_reduction: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12105 | case OMPC_linear: |
| 12106 | case OMPC_aligned: |
| 12107 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12108 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12109 | case OMPC_default: |
| 12110 | case OMPC_proc_bind: |
| 12111 | case OMPC_threadprivate: |
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 12112 | case OMPC_allocate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 12113 | case OMPC_flush: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12114 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 12115 | case OMPC_device: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12116 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12117 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12118 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12119 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 12120 | case OMPC_grainsize: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 12121 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 12122 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 12123 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 12124 | case OMPC_defaultmap: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12125 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 12126 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12127 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12128 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12129 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12130 | case OMPC_is_device_ptr: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 12131 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 12132 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 12133 | case OMPC_match: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12134 | llvm_unreachable("Clause is not allowed."); |
| 12135 | } |
| 12136 | return Res; |
| 12137 | } |
| 12138 | |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 12139 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 12140 | SourceLocation EndLoc) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 12141 | DSAStack->setNowaitRegion(); |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 12142 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 12143 | } |
| 12144 | |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 12145 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 12146 | SourceLocation EndLoc) { |
| 12147 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 12148 | } |
| 12149 | |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 12150 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 12151 | SourceLocation EndLoc) { |
| 12152 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 12153 | } |
| 12154 | |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 12155 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 12156 | SourceLocation EndLoc) { |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 12157 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 12158 | } |
| 12159 | |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 12160 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 12161 | SourceLocation EndLoc) { |
| 12162 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 12163 | } |
| 12164 | |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 12165 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 12166 | SourceLocation EndLoc) { |
| 12167 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 12168 | } |
| 12169 | |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 12170 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 12171 | SourceLocation EndLoc) { |
| 12172 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 12173 | } |
| 12174 | |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 12175 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 12176 | SourceLocation EndLoc) { |
| 12177 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 12178 | } |
| 12179 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 12180 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 12181 | SourceLocation EndLoc) { |
| 12182 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 12183 | } |
| 12184 | |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 12185 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 12186 | SourceLocation EndLoc) { |
| 12187 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 12188 | } |
| 12189 | |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 12190 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 12191 | SourceLocation EndLoc) { |
| 12192 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 12193 | } |
| 12194 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 12195 | OMPClause *Sema::ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
| 12196 | SourceLocation EndLoc) { |
| 12197 | return new (Context) OMPUnifiedAddressClause(StartLoc, EndLoc); |
| 12198 | } |
| 12199 | |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 12200 | OMPClause *Sema::ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
| 12201 | SourceLocation EndLoc) { |
| 12202 | return new (Context) OMPUnifiedSharedMemoryClause(StartLoc, EndLoc); |
| 12203 | } |
| 12204 | |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 12205 | OMPClause *Sema::ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
| 12206 | SourceLocation EndLoc) { |
| 12207 | return new (Context) OMPReverseOffloadClause(StartLoc, EndLoc); |
| 12208 | } |
| 12209 | |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 12210 | OMPClause *Sema::ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
| 12211 | SourceLocation EndLoc) { |
| 12212 | return new (Context) OMPDynamicAllocatorsClause(StartLoc, EndLoc); |
| 12213 | } |
| 12214 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 12215 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 12216 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12217 | const OMPVarListLocTy &Locs, SourceLocation ColonLoc, |
| 12218 | CXXScopeSpec &ReductionOrMapperIdScopeSpec, |
| 12219 | DeclarationNameInfo &ReductionOrMapperId, OpenMPDependClauseKind DepKind, |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 12220 | OpenMPLinearClauseKind LinKind, |
| 12221 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12222 | ArrayRef<SourceLocation> MapTypeModifiersLoc, OpenMPMapClauseKind MapType, |
| 12223 | bool IsMapTypeImplicit, SourceLocation DepLinMapLoc) { |
| 12224 | SourceLocation StartLoc = Locs.StartLoc; |
| 12225 | SourceLocation LParenLoc = Locs.LParenLoc; |
| 12226 | SourceLocation EndLoc = Locs.EndLoc; |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 12227 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12228 | switch (Kind) { |
| 12229 | case OMPC_private: |
| 12230 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12231 | break; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12232 | case OMPC_firstprivate: |
| 12233 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12234 | break; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12235 | case OMPC_lastprivate: |
| 12236 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12237 | break; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12238 | case OMPC_shared: |
| 12239 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12240 | break; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 12241 | case OMPC_reduction: |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 12242 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12243 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 12244 | ReductionOrMapperId); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 12245 | break; |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 12246 | case OMPC_task_reduction: |
| 12247 | Res = ActOnOpenMPTaskReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12248 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 12249 | ReductionOrMapperId); |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 12250 | break; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 12251 | case OMPC_in_reduction: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12252 | Res = ActOnOpenMPInReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 12253 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 12254 | ReductionOrMapperId); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 12255 | break; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 12256 | case OMPC_linear: |
| 12257 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12258 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 12259 | break; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 12260 | case OMPC_aligned: |
| 12261 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 12262 | ColonLoc, EndLoc); |
| 12263 | break; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12264 | case OMPC_copyin: |
| 12265 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12266 | break; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12267 | case OMPC_copyprivate: |
| 12268 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12269 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 12270 | case OMPC_flush: |
| 12271 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 12272 | break; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12273 | case OMPC_depend: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12274 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12275 | StartLoc, LParenLoc, EndLoc); |
| 12276 | break; |
| 12277 | case OMPC_map: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12278 | Res = ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, |
| 12279 | ReductionOrMapperIdScopeSpec, |
| 12280 | ReductionOrMapperId, MapType, IsMapTypeImplicit, |
| 12281 | DepLinMapLoc, ColonLoc, VarList, Locs); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12282 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12283 | case OMPC_to: |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 12284 | Res = ActOnOpenMPToClause(VarList, ReductionOrMapperIdScopeSpec, |
| 12285 | ReductionOrMapperId, Locs); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12286 | break; |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12287 | case OMPC_from: |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 12288 | Res = ActOnOpenMPFromClause(VarList, ReductionOrMapperIdScopeSpec, |
| 12289 | ReductionOrMapperId, Locs); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12290 | break; |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12291 | case OMPC_use_device_ptr: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12292 | Res = ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12293 | break; |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12294 | case OMPC_is_device_ptr: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12295 | Res = ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12296 | break; |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 12297 | case OMPC_allocate: |
| 12298 | Res = ActOnOpenMPAllocateClause(TailExpr, VarList, StartLoc, LParenLoc, |
| 12299 | ColonLoc, EndLoc); |
| 12300 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 12301 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 12302 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 12303 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 12304 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 12305 | case OMPC_simdlen: |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 12306 | case OMPC_allocator: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 12307 | case OMPC_collapse: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12308 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 12309 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 12310 | case OMPC_schedule: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 12311 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 12312 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 12313 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 12314 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12315 | case OMPC_threadprivate: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 12316 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 12317 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 12318 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 12319 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 12320 | case OMPC_seq_cst: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 12321 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 12322 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 12323 | case OMPC_simd: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12324 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12325 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12326 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 12327 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 12328 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 12329 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 12330 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 12331 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 12332 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12333 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 12334 | case OMPC_uniform: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 12335 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 12336 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 12337 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 12338 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 12339 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 12340 | case OMPC_device_type: |
| Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 12341 | case OMPC_match: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12342 | llvm_unreachable("Clause is not allowed."); |
| 12343 | } |
| 12344 | return Res; |
| 12345 | } |
| 12346 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 12347 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 12348 | ExprObjectKind OK, SourceLocation Loc) { |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 12349 | ExprResult Res = BuildDeclRefExpr( |
| 12350 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 12351 | if (!Res.isUsable()) |
| 12352 | return ExprError(); |
| 12353 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 12354 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 12355 | if (!Res.isUsable()) |
| 12356 | return ExprError(); |
| 12357 | } |
| 12358 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 12359 | Res = DefaultLvalueConversion(Res.get()); |
| 12360 | if (!Res.isUsable()) |
| 12361 | return ExprError(); |
| 12362 | } |
| 12363 | return Res; |
| 12364 | } |
| 12365 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12366 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 12367 | SourceLocation StartLoc, |
| 12368 | SourceLocation LParenLoc, |
| 12369 | SourceLocation EndLoc) { |
| 12370 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12371 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12372 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12373 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12374 | SourceLocation ELoc; |
| 12375 | SourceRange ERange; |
| 12376 | Expr *SimpleRefExpr = RefExpr; |
| 12377 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12378 | if (Res.second) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12379 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12380 | Vars.push_back(RefExpr); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12381 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12382 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12383 | ValueDecl *D = Res.first; |
| 12384 | if (!D) |
| 12385 | continue; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12386 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12387 | QualType Type = D->getType(); |
| 12388 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12389 | |
| 12390 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 12391 | // A variable that appears in a private clause must not have an incomplete |
| 12392 | // type or a reference type. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12393 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12394 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 12395 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12396 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 12397 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 12398 | // A variable that is privatized must not have a const-qualified type |
| 12399 | // unless it is of class type with a mutable member. This restriction does |
| 12400 | // not apply to the firstprivate clause. |
| 12401 | // |
| 12402 | // OpenMP 3.1 [2.9.3.3, private clause, Restrictions] |
| 12403 | // A variable that appears in a private clause must not have a |
| 12404 | // const-qualified type unless it is of class type with a mutable member. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 12405 | if (rejectConstNotMutableType(*this, D, Type, OMPC_private, ELoc)) |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 12406 | continue; |
| 12407 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12408 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 12409 | // in a Construct] |
| 12410 | // Variables with the predetermined data-sharing attributes may not be |
| 12411 | // listed in data-sharing attributes clauses, except for the cases |
| 12412 | // listed below. For these exceptions only, listing a predetermined |
| 12413 | // variable in a data-sharing attribute clause is allowed and overrides |
| 12414 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12415 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12416 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12417 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 12418 | << getOpenMPClauseName(OMPC_private); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12419 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12420 | continue; |
| 12421 | } |
| 12422 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12423 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12424 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 12425 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 12426 | isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12427 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 12428 | << getOpenMPClauseName(OMPC_private) << Type |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 12429 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12430 | bool IsDecl = |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12431 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12432 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12433 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12434 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12435 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12436 | continue; |
| 12437 | } |
| 12438 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12439 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 12440 | // A list item cannot appear in both a map clause and a data-sharing |
| 12441 | // attribute clause on the same construct |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 12442 | // |
| 12443 | // OpenMP 5.0 [2.19.7.1, Restrictions, p.7] |
| 12444 | // A list item cannot appear in both a map clause and a data-sharing |
| 12445 | // attribute clause on the same construct unless the construct is a |
| 12446 | // combined construct. |
| 12447 | if ((LangOpts.OpenMP <= 45 && isOpenMPTargetExecutionDirective(CurrDir)) || |
| 12448 | CurrDir == OMPD_target) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12449 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12450 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12451 | VD, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12452 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 12453 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 12454 | ConflictKind = WhereFoundClauseKind; |
| 12455 | return true; |
| 12456 | })) { |
| 12457 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12458 | << getOpenMPClauseName(OMPC_private) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12459 | << getOpenMPClauseName(ConflictKind) |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 12460 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12461 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12462 | continue; |
| 12463 | } |
| 12464 | } |
| 12465 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12466 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 12467 | // A variable of class type (or array thereof) that appears in a private |
| 12468 | // clause requires an accessible, unambiguous default constructor for the |
| 12469 | // class type. |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12470 | // Generate helper private variable and initialize it with the default |
| 12471 | // value. The address of the original variable is replaced by the address of |
| 12472 | // the new private variable in CodeGen. This new variable is not added to |
| 12473 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 12474 | // proper diagnostics. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12475 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12476 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 12477 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 12478 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 12479 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 12480 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12481 | if (VDPrivate->isInvalidDecl()) |
| 12482 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12483 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12484 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12485 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 12486 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12487 | if (!VD && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 12488 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 12489 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12490 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 12491 | ? RefExpr->IgnoreParens() |
| 12492 | : Ref); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12493 | PrivateCopies.push_back(VDPrivateRefExpr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12494 | } |
| 12495 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12496 | if (Vars.empty()) |
| 12497 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12498 | |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 12499 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 12500 | PrivateCopies); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 12501 | } |
| 12502 | |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12503 | namespace { |
| 12504 | class DiagsUninitializedSeveretyRAII { |
| 12505 | private: |
| 12506 | DiagnosticsEngine &Diags; |
| 12507 | SourceLocation SavedLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12508 | bool IsIgnored = false; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12509 | |
| 12510 | public: |
| 12511 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 12512 | bool IsIgnored) |
| 12513 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 12514 | if (!IsIgnored) { |
| 12515 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 12516 | /*Map*/ diag::Severity::Ignored, Loc); |
| 12517 | } |
| 12518 | } |
| 12519 | ~DiagsUninitializedSeveretyRAII() { |
| 12520 | if (!IsIgnored) |
| 12521 | Diags.popMappings(SavedLoc); |
| 12522 | } |
| 12523 | }; |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 12524 | } |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12525 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12526 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 12527 | SourceLocation StartLoc, |
| 12528 | SourceLocation LParenLoc, |
| 12529 | SourceLocation EndLoc) { |
| 12530 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12531 | SmallVector<Expr *, 8> PrivateCopies; |
| 12532 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 12533 | SmallVector<Decl *, 4> ExprCaptures; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12534 | bool IsImplicitClause = |
| 12535 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12536 | SourceLocation ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12537 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12538 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12539 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12540 | SourceLocation ELoc; |
| 12541 | SourceRange ERange; |
| 12542 | Expr *SimpleRefExpr = RefExpr; |
| 12543 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12544 | if (Res.second) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12545 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12546 | Vars.push_back(RefExpr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12547 | PrivateCopies.push_back(nullptr); |
| 12548 | Inits.push_back(nullptr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12549 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12550 | ValueDecl *D = Res.first; |
| 12551 | if (!D) |
| 12552 | continue; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12553 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12554 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12555 | QualType Type = D->getType(); |
| 12556 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12557 | |
| 12558 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 12559 | // A variable that appears in a private clause must not have an incomplete |
| 12560 | // type or a reference type. |
| 12561 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12562 | diag::err_omp_firstprivate_incomplete_type)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12563 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 12564 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12565 | |
| 12566 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 12567 | // A variable of class type (or array thereof) that appears in a private |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 12568 | // clause requires an accessible, unambiguous copy constructor for the |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12569 | // class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12570 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12571 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12572 | // If an implicit firstprivate variable found it was checked already. |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12573 | DSAStackTy::DSAVarData TopDVar; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12574 | if (!IsImplicitClause) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12575 | DSAStackTy::DSAVarData DVar = |
| 12576 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12577 | TopDVar = DVar; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12578 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12579 | bool IsConstant = ElemType.isConstant(Context); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12580 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 12581 | // A list item that specifies a given variable may not appear in more |
| 12582 | // than one clause on the same directive, except that a variable may be |
| 12583 | // specified in both firstprivate and lastprivate clauses. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12584 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 12585 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 12586 | // both. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12587 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 12588 | (isOpenMPDistributeDirective(CurrDir) || |
| 12589 | DVar.CKind != OMPC_lastprivate) && |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12590 | DVar.RefExpr) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12591 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12592 | << getOpenMPClauseName(DVar.CKind) |
| 12593 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12594 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12595 | continue; |
| 12596 | } |
| 12597 | |
| 12598 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 12599 | // in a Construct] |
| 12600 | // Variables with the predetermined data-sharing attributes may not be |
| 12601 | // listed in data-sharing attributes clauses, except for the cases |
| 12602 | // listed below. For these exceptions only, listing a predetermined |
| 12603 | // variable in a data-sharing attribute clause is allowed and overrides |
| 12604 | // the variable's predetermined data-sharing attributes. |
| 12605 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 12606 | // in a Construct, C/C++, p.2] |
| 12607 | // Variables with const-qualified type having no mutable member may be |
| 12608 | // listed in a firstprivate clause, even if they are static data members. |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12609 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12610 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 12611 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12612 | << getOpenMPClauseName(DVar.CKind) |
| 12613 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12614 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12615 | continue; |
| 12616 | } |
| 12617 | |
| 12618 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 12619 | // A list item that is private within a parallel region must not appear |
| 12620 | // in a firstprivate clause on a worksharing construct if any of the |
| 12621 | // worksharing regions arising from the worksharing construct ever bind |
| 12622 | // to any of the parallel regions arising from the parallel construct. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12623 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 12624 | // A list item that is private within a teams region must not appear in a |
| 12625 | // firstprivate clause on a distribute construct if any of the distribute |
| 12626 | // regions arising from the distribute construct ever bind to any of the |
| 12627 | // teams regions arising from the teams construct. |
| 12628 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 12629 | // A list item that appears in a reduction clause of a teams construct |
| 12630 | // must not appear in a firstprivate clause on a distribute construct if |
| 12631 | // any of the distribute regions arising from the distribute construct |
| 12632 | // ever bind to any of the teams regions arising from the teams construct. |
| 12633 | if ((isOpenMPWorksharingDirective(CurrDir) || |
| 12634 | isOpenMPDistributeDirective(CurrDir)) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 12635 | !isOpenMPParallelDirective(CurrDir) && |
| 12636 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12637 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12638 | if (DVar.CKind != OMPC_shared && |
| 12639 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12640 | isOpenMPTeamsDirective(DVar.DKind) || |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12641 | DVar.DKind == OMPD_unknown)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12642 | Diag(ELoc, diag::err_omp_required_access) |
| 12643 | << getOpenMPClauseName(OMPC_firstprivate) |
| 12644 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12645 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12646 | continue; |
| 12647 | } |
| 12648 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12649 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 12650 | // A list item that appears in a reduction clause of a parallel construct |
| 12651 | // must not appear in a firstprivate clause on a worksharing or task |
| 12652 | // construct if any of the worksharing or task regions arising from the |
| 12653 | // worksharing or task construct ever bind to any of the parallel regions |
| 12654 | // arising from the parallel construct. |
| 12655 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 12656 | // A list item that appears in a reduction clause in worksharing |
| 12657 | // construct must not appear in a firstprivate clause in a task construct |
| 12658 | // encountered during execution of any of the worksharing regions arising |
| 12659 | // from the worksharing construct. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 12660 | if (isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 12661 | DVar = DSAStack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12662 | D, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 12663 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 12664 | return isOpenMPParallelDirective(K) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12665 | isOpenMPWorksharingDirective(K) || |
| 12666 | isOpenMPTeamsDirective(K); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 12667 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12668 | /*FromParent=*/true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12669 | if (DVar.CKind == OMPC_reduction && |
| 12670 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12671 | isOpenMPWorksharingDirective(DVar.DKind) || |
| 12672 | isOpenMPTeamsDirective(DVar.DKind))) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12673 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 12674 | << getOpenMPDirectiveName(DVar.DKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12675 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 12676 | continue; |
| 12677 | } |
| 12678 | } |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 12679 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12680 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 12681 | // A list item cannot appear in both a map clause and a data-sharing |
| 12682 | // attribute clause on the same construct |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 12683 | // |
| 12684 | // OpenMP 5.0 [2.19.7.1, Restrictions, p.7] |
| 12685 | // A list item cannot appear in both a map clause and a data-sharing |
| 12686 | // attribute clause on the same construct unless the construct is a |
| 12687 | // combined construct. |
| 12688 | if ((LangOpts.OpenMP <= 45 && |
| 12689 | isOpenMPTargetExecutionDirective(CurrDir)) || |
| 12690 | CurrDir == OMPD_target) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12691 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12692 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12693 | VD, /*CurrentRegionOnly=*/true, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12694 | [&ConflictKind]( |
| 12695 | OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 12696 | OpenMPClauseKind WhereFoundClauseKind) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12697 | ConflictKind = WhereFoundClauseKind; |
| 12698 | return true; |
| 12699 | })) { |
| 12700 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12701 | << getOpenMPClauseName(OMPC_firstprivate) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12702 | << getOpenMPClauseName(ConflictKind) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12703 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12704 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12705 | continue; |
| 12706 | } |
| 12707 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12708 | } |
| 12709 | |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12710 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 12711 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 12712 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12713 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 12714 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 12715 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 12716 | bool IsDecl = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12717 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12718 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12719 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12720 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12721 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12722 | continue; |
| 12723 | } |
| 12724 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12725 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12726 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 12727 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 12728 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 12729 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12730 | // Generate helper private variable and initialize it with the value of the |
| 12731 | // original variable. The address of the original variable is replaced by |
| 12732 | // the address of the new private variable in the CodeGen. This new variable |
| 12733 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 12734 | // original variable for proper diagnostics and variable capturing. |
| 12735 | Expr *VDInitRefExpr = nullptr; |
| 12736 | // For arrays generate initializer for single element and replace it by the |
| 12737 | // original array element in CodeGen. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12738 | if (Type->isArrayType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12739 | VarDecl *VDInit = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12740 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12741 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12742 | Expr *Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12743 | ElemType = ElemType.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12744 | VarDecl *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
| 12745 | ".firstprivate.temp"); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 12746 | InitializedEntity Entity = |
| 12747 | InitializedEntity::InitializeVariable(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12748 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 12749 | |
| 12750 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 12751 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 12752 | if (Result.isInvalid()) |
| 12753 | VDPrivate->setInvalidDecl(); |
| 12754 | else |
| 12755 | VDPrivate->setInit(Result.getAs<Expr>()); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 12756 | // Remove temp variable declaration. |
| 12757 | Context.Deallocate(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12758 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12759 | VarDecl *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 12760 | ".firstprivate.temp"); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12761 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 12762 | RefExpr->getExprLoc()); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 12763 | AddInitializerToDecl(VDPrivate, |
| 12764 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 12765 | /*DirectInit=*/false); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12766 | } |
| 12767 | if (VDPrivate->isInvalidDecl()) { |
| 12768 | if (IsImplicitClause) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12769 | Diag(RefExpr->getExprLoc(), |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12770 | diag::note_omp_task_predetermined_firstprivate_here); |
| 12771 | } |
| 12772 | continue; |
| 12773 | } |
| 12774 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12775 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12776 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 12777 | RefExpr->getExprLoc()); |
| 12778 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12779 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12780 | if (TopDVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12781 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12782 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 12783 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12784 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12785 | ExprCaptures.push_back(Ref->getDecl()); |
| 12786 | } |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 12787 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 12788 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12789 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 12790 | ? RefExpr->IgnoreParens() |
| 12791 | : Ref); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 12792 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 12793 | Inits.push_back(VDInitRefExpr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12794 | } |
| 12795 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12796 | if (Vars.empty()) |
| 12797 | return nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12798 | |
| 12799 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 12800 | Vars, PrivateCopies, Inits, |
| 12801 | buildPreInits(Context, ExprCaptures)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 12802 | } |
| 12803 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12804 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 12805 | SourceLocation StartLoc, |
| 12806 | SourceLocation LParenLoc, |
| 12807 | SourceLocation EndLoc) { |
| 12808 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12809 | SmallVector<Expr *, 8> SrcExprs; |
| 12810 | SmallVector<Expr *, 8> DstExprs; |
| 12811 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12812 | SmallVector<Decl *, 4> ExprCaptures; |
| 12813 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12814 | for (Expr *RefExpr : VarList) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12815 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12816 | SourceLocation ELoc; |
| 12817 | SourceRange ERange; |
| 12818 | Expr *SimpleRefExpr = RefExpr; |
| 12819 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12820 | if (Res.second) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12821 | // It will be analyzed later. |
| 12822 | Vars.push_back(RefExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12823 | SrcExprs.push_back(nullptr); |
| 12824 | DstExprs.push_back(nullptr); |
| 12825 | AssignmentOps.push_back(nullptr); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12826 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12827 | ValueDecl *D = Res.first; |
| 12828 | if (!D) |
| 12829 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12830 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12831 | QualType Type = D->getType(); |
| 12832 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12833 | |
| 12834 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 12835 | // A variable that appears in a lastprivate clause must not have an |
| 12836 | // incomplete type or a reference type. |
| 12837 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12838 | diag::err_omp_lastprivate_incomplete_type)) |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12839 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 12840 | Type = Type.getNonReferenceType(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12841 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 12842 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 12843 | // A variable that is privatized must not have a const-qualified type |
| 12844 | // unless it is of class type with a mutable member. This restriction does |
| 12845 | // not apply to the firstprivate clause. |
| 12846 | // |
| 12847 | // OpenMP 3.1 [2.9.3.5, lastprivate clause, Restrictions] |
| 12848 | // A variable that appears in a lastprivate clause must not have a |
| 12849 | // const-qualified type unless it is of class type with a mutable member. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 12850 | if (rejectConstNotMutableType(*this, D, Type, OMPC_lastprivate, ELoc)) |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 12851 | continue; |
| 12852 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12853 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12854 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 12855 | // in a Construct] |
| 12856 | // Variables with the predetermined data-sharing attributes may not be |
| 12857 | // listed in data-sharing attributes clauses, except for the cases |
| 12858 | // listed below. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 12859 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 12860 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 12861 | // both. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12862 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12863 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 12864 | (isOpenMPDistributeDirective(CurrDir) || |
| 12865 | DVar.CKind != OMPC_firstprivate) && |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12866 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 12867 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 12868 | << getOpenMPClauseName(DVar.CKind) |
| 12869 | << getOpenMPClauseName(OMPC_lastprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12870 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12871 | continue; |
| 12872 | } |
| 12873 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12874 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 12875 | // A list item that is private within a parallel region, or that appears in |
| 12876 | // the reduction clause of a parallel construct, must not appear in a |
| 12877 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 12878 | // worksharing regions ever binds to any of the corresponding parallel |
| 12879 | // regions. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 12880 | DSAStackTy::DSAVarData TopDVar = DVar; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 12881 | if (isOpenMPWorksharingDirective(CurrDir) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 12882 | !isOpenMPParallelDirective(CurrDir) && |
| 12883 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12884 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12885 | if (DVar.CKind != OMPC_shared) { |
| 12886 | Diag(ELoc, diag::err_omp_required_access) |
| 12887 | << getOpenMPClauseName(OMPC_lastprivate) |
| 12888 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12889 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12890 | continue; |
| 12891 | } |
| 12892 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12893 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12894 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 12895 | // A variable of class type (or array thereof) that appears in a |
| 12896 | // lastprivate clause requires an accessible, unambiguous default |
| 12897 | // constructor for the class type, unless the list item is also specified |
| 12898 | // in a firstprivate clause. |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12899 | // A variable of class type (or array thereof) that appears in a |
| 12900 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 12901 | // operator for the class type. |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12902 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12903 | VarDecl *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
| 12904 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 12905 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 12906 | DeclRefExpr *PseudoSrcExpr = |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12907 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12908 | VarDecl *DstVD = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12909 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12910 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12911 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12912 | // For arrays generate assignment operation for single element and replace |
| 12913 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12914 | ExprResult AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
| 12915 | PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12916 | if (AssignmentOp.isInvalid()) |
| 12917 | continue; |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 12918 | AssignmentOp = |
| 12919 | ActOnFinishFullExpr(AssignmentOp.get(), ELoc, /*DiscardedValue*/ false); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12920 | if (AssignmentOp.isInvalid()) |
| 12921 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12922 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 12923 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12924 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12925 | if (TopDVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12926 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12927 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 12928 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12929 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12930 | ExprCaptures.push_back(Ref->getDecl()); |
| 12931 | } |
| 12932 | if (TopDVar.CKind == OMPC_firstprivate || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12933 | (!isOpenMPCapturedDecl(D) && |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 12934 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12935 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 12936 | if (!RefRes.isUsable()) |
| 12937 | continue; |
| 12938 | ExprResult PostUpdateRes = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12939 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 12940 | RefRes.get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12941 | if (!PostUpdateRes.isUsable()) |
| 12942 | continue; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 12943 | ExprPostUpdates.push_back( |
| 12944 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12945 | } |
| 12946 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 12947 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 12948 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 12949 | ? RefExpr->IgnoreParens() |
| 12950 | : Ref); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 12951 | SrcExprs.push_back(PseudoSrcExpr); |
| 12952 | DstExprs.push_back(PseudoDstExpr); |
| 12953 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12954 | } |
| 12955 | |
| 12956 | if (Vars.empty()) |
| 12957 | return nullptr; |
| 12958 | |
| 12959 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 12960 | Vars, SrcExprs, DstExprs, AssignmentOps, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 12961 | buildPreInits(Context, ExprCaptures), |
| 12962 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 12963 | } |
| 12964 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12965 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 12966 | SourceLocation StartLoc, |
| 12967 | SourceLocation LParenLoc, |
| 12968 | SourceLocation EndLoc) { |
| 12969 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12970 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 12971 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 12972 | SourceLocation ELoc; |
| 12973 | SourceRange ERange; |
| 12974 | Expr *SimpleRefExpr = RefExpr; |
| 12975 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 12976 | if (Res.second) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12977 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12978 | Vars.push_back(RefExpr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12979 | } |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 12980 | ValueDecl *D = Res.first; |
| 12981 | if (!D) |
| 12982 | continue; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12983 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 12984 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12985 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 12986 | // in a Construct] |
| 12987 | // Variables with the predetermined data-sharing attributes may not be |
| 12988 | // listed in data-sharing attributes clauses, except for the cases |
| 12989 | // listed below. For these exceptions only, listing a predetermined |
| 12990 | // variable in a data-sharing attribute clause is allowed and overrides |
| 12991 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12992 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12993 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 12994 | DVar.RefExpr) { |
| 12995 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 12996 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12997 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 12998 | continue; |
| 12999 | } |
| 13000 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 13001 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13002 | if (!VD && isOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 13003 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 13004 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 13005 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 13006 | ? RefExpr->IgnoreParens() |
| 13007 | : Ref); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 13008 | } |
| 13009 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 13010 | if (Vars.empty()) |
| 13011 | return nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 13012 | |
| 13013 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 13014 | } |
| 13015 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13016 | namespace { |
| 13017 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 13018 | DSAStackTy *Stack; |
| 13019 | |
| 13020 | public: |
| 13021 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13022 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 13023 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13024 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 13025 | return false; |
| 13026 | if (DVar.CKind != OMPC_unknown) |
| 13027 | return true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 13028 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13029 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) { return true; }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 13030 | /*FromParent=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13031 | return DVarPrivate.CKind != OMPC_unknown; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13032 | } |
| 13033 | return false; |
| 13034 | } |
| 13035 | bool VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13036 | for (Stmt *Child : S->children()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13037 | if (Child && Visit(Child)) |
| 13038 | return true; |
| 13039 | } |
| 13040 | return false; |
| 13041 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 13042 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13043 | }; |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 13044 | } // namespace |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13045 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13046 | namespace { |
| 13047 | // Transform MemberExpression for specified FieldDecl of current class to |
| 13048 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 13049 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 13050 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13051 | ValueDecl *Field = nullptr; |
| 13052 | DeclRefExpr *CapturedExpr = nullptr; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13053 | |
| 13054 | public: |
| 13055 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 13056 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 13057 | |
| 13058 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 13059 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 13060 | E->getMemberDecl() == Field) { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 13061 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13062 | return CapturedExpr; |
| 13063 | } |
| 13064 | return BaseTransform::TransformMemberExpr(E); |
| 13065 | } |
| 13066 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 13067 | }; |
| 13068 | } // namespace |
| 13069 | |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 13070 | template <typename T, typename U> |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13071 | static T filterLookupForUDReductionAndMapper( |
| 13072 | SmallVectorImpl<U> &Lookups, const llvm::function_ref<T(ValueDecl *)> Gen) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13073 | for (U &Set : Lookups) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13074 | for (auto *D : Set) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13075 | if (T Res = Gen(cast<ValueDecl>(D))) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13076 | return Res; |
| 13077 | } |
| 13078 | } |
| 13079 | return T(); |
| 13080 | } |
| 13081 | |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13082 | static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D) { |
| 13083 | assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case"); |
| 13084 | |
| 13085 | for (auto RD : D->redecls()) { |
| 13086 | // Don't bother with extra checks if we already know this one isn't visible. |
| 13087 | if (RD == D) |
| 13088 | continue; |
| 13089 | |
| 13090 | auto ND = cast<NamedDecl>(RD); |
| 13091 | if (LookupResult::isVisible(SemaRef, ND)) |
| 13092 | return ND; |
| 13093 | } |
| 13094 | |
| 13095 | return nullptr; |
| 13096 | } |
| 13097 | |
| 13098 | static void |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13099 | argumentDependentLookup(Sema &SemaRef, const DeclarationNameInfo &Id, |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13100 | SourceLocation Loc, QualType Ty, |
| 13101 | SmallVectorImpl<UnresolvedSet<8>> &Lookups) { |
| 13102 | // Find all of the associated namespaces and classes based on the |
| 13103 | // arguments we have. |
| 13104 | Sema::AssociatedNamespaceSet AssociatedNamespaces; |
| 13105 | Sema::AssociatedClassSet AssociatedClasses; |
| 13106 | OpaqueValueExpr OVE(Loc, Ty, VK_LValue); |
| 13107 | SemaRef.FindAssociatedClassesAndNamespaces(Loc, &OVE, AssociatedNamespaces, |
| 13108 | AssociatedClasses); |
| 13109 | |
| 13110 | // C++ [basic.lookup.argdep]p3: |
| 13111 | // Let X be the lookup set produced by unqualified lookup (3.4.1) |
| 13112 | // and let Y be the lookup set produced by argument dependent |
| 13113 | // lookup (defined as follows). If X contains [...] then Y is |
| 13114 | // empty. Otherwise Y is the set of declarations found in the |
| 13115 | // namespaces associated with the argument types as described |
| 13116 | // below. The set of declarations found by the lookup of the name |
| 13117 | // is the union of X and Y. |
| 13118 | // |
| 13119 | // Here, we compute Y and add its members to the overloaded |
| 13120 | // candidate set. |
| 13121 | for (auto *NS : AssociatedNamespaces) { |
| 13122 | // When considering an associated namespace, the lookup is the |
| 13123 | // same as the lookup performed when the associated namespace is |
| 13124 | // used as a qualifier (3.4.3.2) except that: |
| 13125 | // |
| 13126 | // -- Any using-directives in the associated namespace are |
| 13127 | // ignored. |
| 13128 | // |
| 13129 | // -- Any namespace-scope friend functions declared in |
| 13130 | // associated classes are visible within their respective |
| 13131 | // namespaces even if they are not visible during an ordinary |
| 13132 | // lookup (11.4). |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13133 | DeclContext::lookup_result R = NS->lookup(Id.getName()); |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13134 | for (auto *D : R) { |
| 13135 | auto *Underlying = D; |
| 13136 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 13137 | Underlying = USD->getTargetDecl(); |
| 13138 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13139 | if (!isa<OMPDeclareReductionDecl>(Underlying) && |
| 13140 | !isa<OMPDeclareMapperDecl>(Underlying)) |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13141 | continue; |
| 13142 | |
| 13143 | if (!SemaRef.isVisible(D)) { |
| 13144 | D = findAcceptableDecl(SemaRef, D); |
| 13145 | if (!D) |
| 13146 | continue; |
| 13147 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 13148 | Underlying = USD->getTargetDecl(); |
| 13149 | } |
| 13150 | Lookups.emplace_back(); |
| 13151 | Lookups.back().addDecl(Underlying); |
| 13152 | } |
| 13153 | } |
| 13154 | } |
| 13155 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13156 | static ExprResult |
| 13157 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 13158 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 13159 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 13160 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 13161 | if (ReductionIdScopeSpec.isInvalid()) |
| 13162 | return ExprError(); |
| 13163 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 13164 | if (S) { |
| 13165 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 13166 | Lookup.suppressDiagnostics(); |
| 13167 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13168 | NamedDecl *D = Lookup.getRepresentativeDecl(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13169 | do { |
| 13170 | S = S->getParent(); |
| 13171 | } while (S && !S->isDeclScope(D)); |
| 13172 | if (S) |
| 13173 | S = S->getParent(); |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13174 | Lookups.emplace_back(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13175 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 13176 | Lookup.clear(); |
| 13177 | } |
| 13178 | } else if (auto *ULE = |
| 13179 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 13180 | Lookups.push_back(UnresolvedSet<8>()); |
| 13181 | Decl *PrevD = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13182 | for (NamedDecl *D : ULE->decls()) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13183 | if (D == PrevD) |
| 13184 | Lookups.push_back(UnresolvedSet<8>()); |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 13185 | else if (auto *DRD = dyn_cast<OMPDeclareReductionDecl>(D)) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13186 | Lookups.back().addDecl(DRD); |
| 13187 | PrevD = D; |
| 13188 | } |
| 13189 | } |
| Alexey Bataev | fdc2035 | 2017-08-25 15:43:55 +0000 | [diff] [blame] | 13190 | if (SemaRef.CurContext->isDependentContext() || Ty->isDependentType() || |
| 13191 | Ty->isInstantiationDependentType() || |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13192 | Ty->containsUnexpandedParameterPack() || |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13193 | filterLookupForUDReductionAndMapper<bool>(Lookups, [](ValueDecl *D) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13194 | return !D->isInvalidDecl() && |
| 13195 | (D->getType()->isDependentType() || |
| 13196 | D->getType()->isInstantiationDependentType() || |
| 13197 | D->getType()->containsUnexpandedParameterPack()); |
| 13198 | })) { |
| 13199 | UnresolvedSet<8> ResSet; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13200 | for (const UnresolvedSet<8> &Set : Lookups) { |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13201 | if (Set.empty()) |
| 13202 | continue; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13203 | ResSet.append(Set.begin(), Set.end()); |
| 13204 | // The last item marks the end of all declarations at the specified scope. |
| 13205 | ResSet.addDecl(Set[Set.size() - 1]); |
| 13206 | } |
| 13207 | return UnresolvedLookupExpr::Create( |
| 13208 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 13209 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 13210 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 13211 | } |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 13212 | // Lookup inside the classes. |
| 13213 | // C++ [over.match.oper]p3: |
| 13214 | // For a unary operator @ with an operand of a type whose |
| 13215 | // cv-unqualified version is T1, and for a binary operator @ with |
| 13216 | // a left operand of a type whose cv-unqualified version is T1 and |
| 13217 | // a right operand of a type whose cv-unqualified version is T2, |
| 13218 | // three sets of candidate functions, designated member |
| 13219 | // candidates, non-member candidates and built-in candidates, are |
| 13220 | // constructed as follows: |
| 13221 | // -- If T1 is a complete class type or a class currently being |
| 13222 | // defined, the set of member candidates is the result of the |
| 13223 | // qualified lookup of T1::operator@ (13.3.1.1.1); otherwise, |
| 13224 | // the set of member candidates is empty. |
| 13225 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 13226 | Lookup.suppressDiagnostics(); |
| 13227 | if (const auto *TyRec = Ty->getAs<RecordType>()) { |
| 13228 | // Complete the type if it can be completed. |
| 13229 | // If the type is neither complete nor being defined, bail out now. |
| 13230 | if (SemaRef.isCompleteType(Loc, Ty) || TyRec->isBeingDefined() || |
| 13231 | TyRec->getDecl()->getDefinition()) { |
| 13232 | Lookup.clear(); |
| 13233 | SemaRef.LookupQualifiedName(Lookup, TyRec->getDecl()); |
| 13234 | if (Lookup.empty()) { |
| 13235 | Lookups.emplace_back(); |
| 13236 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 13237 | } |
| 13238 | } |
| 13239 | } |
| 13240 | // Perform ADL. |
| Alexey Bataev | 0923266 | 2019-04-04 17:28:22 +0000 | [diff] [blame] | 13241 | if (SemaRef.getLangOpts().CPlusPlus) |
| Alexey Bataev | 74a04e8 | 2019-03-13 19:31:34 +0000 | [diff] [blame] | 13242 | argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups); |
| Alexey Bataev | 0923266 | 2019-04-04 17:28:22 +0000 | [diff] [blame] | 13243 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 13244 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 13245 | if (!D->isInvalidDecl() && |
| 13246 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 13247 | return D; |
| 13248 | return nullptr; |
| 13249 | })) |
| 13250 | return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), |
| 13251 | VK_LValue, Loc); |
| 13252 | if (SemaRef.getLangOpts().CPlusPlus) { |
| Alexey Bataev | 74a04e8 | 2019-03-13 19:31:34 +0000 | [diff] [blame] | 13253 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 13254 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 13255 | if (!D->isInvalidDecl() && |
| 13256 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 13257 | !Ty.isMoreQualifiedThan(D->getType())) |
| 13258 | return D; |
| 13259 | return nullptr; |
| 13260 | })) { |
| 13261 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 13262 | /*DetectVirtual=*/false); |
| 13263 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 13264 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 13265 | VD->getType().getUnqualifiedType()))) { |
| 13266 | if (SemaRef.CheckBaseClassAccess( |
| 13267 | Loc, VD->getType(), Ty, Paths.front(), |
| 13268 | /*DiagID=*/0) != Sema::AR_inaccessible) { |
| 13269 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 13270 | return SemaRef.BuildDeclRefExpr( |
| 13271 | VD, VD->getType().getNonReferenceType(), VK_LValue, Loc); |
| 13272 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13273 | } |
| 13274 | } |
| 13275 | } |
| 13276 | } |
| 13277 | if (ReductionIdScopeSpec.isSet()) { |
| 13278 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 13279 | return ExprError(); |
| 13280 | } |
| 13281 | return ExprEmpty(); |
| 13282 | } |
| 13283 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13284 | namespace { |
| 13285 | /// Data for the reduction-based clauses. |
| 13286 | struct ReductionData { |
| 13287 | /// List of original reduction items. |
| 13288 | SmallVector<Expr *, 8> Vars; |
| 13289 | /// List of private copies of the reduction items. |
| 13290 | SmallVector<Expr *, 8> Privates; |
| 13291 | /// LHS expressions for the reduction_op expressions. |
| 13292 | SmallVector<Expr *, 8> LHSs; |
| 13293 | /// RHS expressions for the reduction_op expressions. |
| 13294 | SmallVector<Expr *, 8> RHSs; |
| 13295 | /// Reduction operation expression. |
| 13296 | SmallVector<Expr *, 8> ReductionOps; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13297 | /// Taskgroup descriptors for the corresponding reduction items in |
| 13298 | /// in_reduction clauses. |
| 13299 | SmallVector<Expr *, 8> TaskgroupDescriptors; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13300 | /// List of captures for clause. |
| 13301 | SmallVector<Decl *, 4> ExprCaptures; |
| 13302 | /// List of postupdate expressions. |
| 13303 | SmallVector<Expr *, 4> ExprPostUpdates; |
| 13304 | ReductionData() = delete; |
| 13305 | /// Reserves required memory for the reduction data. |
| 13306 | ReductionData(unsigned Size) { |
| 13307 | Vars.reserve(Size); |
| 13308 | Privates.reserve(Size); |
| 13309 | LHSs.reserve(Size); |
| 13310 | RHSs.reserve(Size); |
| 13311 | ReductionOps.reserve(Size); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13312 | TaskgroupDescriptors.reserve(Size); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13313 | ExprCaptures.reserve(Size); |
| 13314 | ExprPostUpdates.reserve(Size); |
| 13315 | } |
| 13316 | /// Stores reduction item and reduction operation only (required for dependent |
| 13317 | /// reduction item). |
| 13318 | void push(Expr *Item, Expr *ReductionOp) { |
| 13319 | Vars.emplace_back(Item); |
| 13320 | Privates.emplace_back(nullptr); |
| 13321 | LHSs.emplace_back(nullptr); |
| 13322 | RHSs.emplace_back(nullptr); |
| 13323 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13324 | TaskgroupDescriptors.emplace_back(nullptr); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13325 | } |
| 13326 | /// Stores reduction data. |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13327 | void push(Expr *Item, Expr *Private, Expr *LHS, Expr *RHS, Expr *ReductionOp, |
| 13328 | Expr *TaskgroupDescriptor) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13329 | Vars.emplace_back(Item); |
| 13330 | Privates.emplace_back(Private); |
| 13331 | LHSs.emplace_back(LHS); |
| 13332 | RHSs.emplace_back(RHS); |
| 13333 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13334 | TaskgroupDescriptors.emplace_back(TaskgroupDescriptor); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13335 | } |
| 13336 | }; |
| 13337 | } // namespace |
| 13338 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13339 | static bool checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13340 | ASTContext &Context, const OMPArraySectionExpr *OASE, bool &SingleElement, |
| 13341 | SmallVectorImpl<llvm::APSInt> &ArraySizes) { |
| 13342 | const Expr *Length = OASE->getLength(); |
| 13343 | if (Length == nullptr) { |
| 13344 | // For array sections of the form [1:] or [:], we would need to analyze |
| 13345 | // the lower bound... |
| 13346 | if (OASE->getColonLoc().isValid()) |
| 13347 | return false; |
| 13348 | |
| 13349 | // This is an array subscript which has implicit length 1! |
| 13350 | SingleElement = true; |
| 13351 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 13352 | } else { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 13353 | Expr::EvalResult Result; |
| 13354 | if (!Length->EvaluateAsInt(Result, Context)) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13355 | return false; |
| 13356 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 13357 | llvm::APSInt ConstantLengthValue = Result.Val.getInt(); |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13358 | SingleElement = (ConstantLengthValue.getSExtValue() == 1); |
| 13359 | ArraySizes.push_back(ConstantLengthValue); |
| 13360 | } |
| 13361 | |
| 13362 | // Get the base of this array section and walk up from there. |
| 13363 | const Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 13364 | |
| 13365 | // We require length = 1 for all array sections except the right-most to |
| 13366 | // guarantee that the memory region is contiguous and has no holes in it. |
| 13367 | while (const auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) { |
| 13368 | Length = TempOASE->getLength(); |
| 13369 | if (Length == nullptr) { |
| 13370 | // For array sections of the form [1:] or [:], we would need to analyze |
| 13371 | // the lower bound... |
| 13372 | if (OASE->getColonLoc().isValid()) |
| 13373 | return false; |
| 13374 | |
| 13375 | // This is an array subscript which has implicit length 1! |
| 13376 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 13377 | } else { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 13378 | Expr::EvalResult Result; |
| 13379 | if (!Length->EvaluateAsInt(Result, Context)) |
| 13380 | return false; |
| 13381 | |
| 13382 | llvm::APSInt ConstantLengthValue = Result.Val.getInt(); |
| 13383 | if (ConstantLengthValue.getSExtValue() != 1) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13384 | return false; |
| 13385 | |
| 13386 | ArraySizes.push_back(ConstantLengthValue); |
| 13387 | } |
| 13388 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 13389 | } |
| 13390 | |
| 13391 | // If we have a single element, we don't need to add the implicit lengths. |
| 13392 | if (!SingleElement) { |
| 13393 | while (const auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) { |
| 13394 | // Has implicit length 1! |
| 13395 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 13396 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 13397 | } |
| 13398 | } |
| 13399 | |
| 13400 | // This array section can be privatized as a single value or as a constant |
| 13401 | // sized array. |
| 13402 | return true; |
| 13403 | } |
| 13404 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13405 | static bool actOnOMPReductionKindClause( |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 13406 | Sema &S, DSAStackTy *Stack, OpenMPClauseKind ClauseKind, |
| 13407 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 13408 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 13409 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13410 | ArrayRef<Expr *> UnresolvedReductions, ReductionData &RD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13411 | DeclarationName DN = ReductionId.getName(); |
| 13412 | OverloadedOperatorKind OOK = DN.getCXXOverloadedOperator(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13413 | BinaryOperatorKind BOK = BO_Comma; |
| 13414 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13415 | ASTContext &Context = S.Context; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13416 | // OpenMP [2.14.3.6, reduction clause] |
| 13417 | // C |
| 13418 | // reduction-identifier is either an identifier or one of the following |
| 13419 | // operators: +, -, *, &, |, ^, && and || |
| 13420 | // C++ |
| 13421 | // reduction-identifier is either an id-expression or one of the following |
| 13422 | // operators: +, -, *, &, |, ^, && and || |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13423 | switch (OOK) { |
| 13424 | case OO_Plus: |
| 13425 | case OO_Minus: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13426 | BOK = BO_Add; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13427 | break; |
| 13428 | case OO_Star: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13429 | BOK = BO_Mul; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13430 | break; |
| 13431 | case OO_Amp: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13432 | BOK = BO_And; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13433 | break; |
| 13434 | case OO_Pipe: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13435 | BOK = BO_Or; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13436 | break; |
| 13437 | case OO_Caret: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13438 | BOK = BO_Xor; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13439 | break; |
| 13440 | case OO_AmpAmp: |
| 13441 | BOK = BO_LAnd; |
| 13442 | break; |
| 13443 | case OO_PipePipe: |
| 13444 | BOK = BO_LOr; |
| 13445 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13446 | case OO_New: |
| 13447 | case OO_Delete: |
| 13448 | case OO_Array_New: |
| 13449 | case OO_Array_Delete: |
| 13450 | case OO_Slash: |
| 13451 | case OO_Percent: |
| 13452 | case OO_Tilde: |
| 13453 | case OO_Exclaim: |
| 13454 | case OO_Equal: |
| 13455 | case OO_Less: |
| 13456 | case OO_Greater: |
| 13457 | case OO_LessEqual: |
| 13458 | case OO_GreaterEqual: |
| 13459 | case OO_PlusEqual: |
| 13460 | case OO_MinusEqual: |
| 13461 | case OO_StarEqual: |
| 13462 | case OO_SlashEqual: |
| 13463 | case OO_PercentEqual: |
| 13464 | case OO_CaretEqual: |
| 13465 | case OO_AmpEqual: |
| 13466 | case OO_PipeEqual: |
| 13467 | case OO_LessLess: |
| 13468 | case OO_GreaterGreater: |
| 13469 | case OO_LessLessEqual: |
| 13470 | case OO_GreaterGreaterEqual: |
| 13471 | case OO_EqualEqual: |
| 13472 | case OO_ExclaimEqual: |
| Richard Smith | d30b23d | 2017-12-01 02:13:10 +0000 | [diff] [blame] | 13473 | case OO_Spaceship: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13474 | case OO_PlusPlus: |
| 13475 | case OO_MinusMinus: |
| 13476 | case OO_Comma: |
| 13477 | case OO_ArrowStar: |
| 13478 | case OO_Arrow: |
| 13479 | case OO_Call: |
| 13480 | case OO_Subscript: |
| 13481 | case OO_Conditional: |
| Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 13482 | case OO_Coawait: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13483 | case NUM_OVERLOADED_OPERATORS: |
| 13484 | llvm_unreachable("Unexpected reduction identifier"); |
| 13485 | case OO_None: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13486 | if (IdentifierInfo *II = DN.getAsIdentifierInfo()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13487 | if (II->isStr("max")) |
| 13488 | BOK = BO_GT; |
| 13489 | else if (II->isStr("min")) |
| 13490 | BOK = BO_LT; |
| 13491 | } |
| 13492 | break; |
| 13493 | } |
| 13494 | SourceRange ReductionIdRange; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13495 | if (ReductionIdScopeSpec.isValid()) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13496 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 13497 | else |
| 13498 | ReductionIdRange.setBegin(ReductionId.getBeginLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13499 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13500 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13501 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 13502 | bool FirstIter = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13503 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13504 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13505 | // OpenMP [2.1, C/C++] |
| 13506 | // A list item is a variable or array section, subject to the restrictions |
| 13507 | // specified in Section 2.4 on page 42 and in each of the sections |
| 13508 | // describing clauses and directives for which a list appears. |
| 13509 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 13510 | // A variable that is part of another variable (as an array or |
| 13511 | // structure element) cannot appear in a private clause. |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13512 | if (!FirstIter && IR != ER) |
| 13513 | ++IR; |
| 13514 | FirstIter = false; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13515 | SourceLocation ELoc; |
| 13516 | SourceRange ERange; |
| 13517 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13518 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13519 | /*AllowArraySection=*/true); |
| 13520 | if (Res.second) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13521 | // Try to find 'declare reduction' corresponding construct before using |
| 13522 | // builtin/overloaded operators. |
| 13523 | QualType Type = Context.DependentTy; |
| 13524 | CXXCastPath BasePath; |
| 13525 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13526 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13527 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13528 | Expr *ReductionOp = nullptr; |
| 13529 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13530 | (DeclareReductionRef.isUnset() || |
| 13531 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13532 | ReductionOp = DeclareReductionRef.get(); |
| 13533 | // It will be analyzed later. |
| 13534 | RD.push(RefExpr, ReductionOp); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13535 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13536 | ValueDecl *D = Res.first; |
| 13537 | if (!D) |
| 13538 | continue; |
| 13539 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13540 | Expr *TaskgroupDescriptor = nullptr; |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 13541 | QualType Type; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13542 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 13543 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13544 | if (ASE) { |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 13545 | Type = ASE->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13546 | } else if (OASE) { |
| 13547 | QualType BaseType = |
| 13548 | OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 13549 | if (const auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 13550 | Type = ATy->getElementType(); |
| 13551 | else |
| 13552 | Type = BaseType->getPointeeType(); |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 13553 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13554 | } else { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13555 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13556 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13557 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 13558 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13559 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 13560 | // A variable that appears in a private clause must not have an incomplete |
| 13561 | // type or a reference type. |
| Joel E. Denny | 3cabf73 | 2018-06-28 19:54:49 +0000 | [diff] [blame] | 13562 | if (S.RequireCompleteType(ELoc, D->getType(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13563 | diag::err_omp_reduction_incomplete_type)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13564 | continue; |
| 13565 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13566 | // A list item that appears in a reduction clause must not be |
| 13567 | // const-qualified. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 13568 | if (rejectConstNotMutableType(S, D, Type, ClauseKind, ELoc, |
| 13569 | /*AcceptIfMutable*/ false, ASE || OASE)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13570 | continue; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 13571 | |
| 13572 | OpenMPDirectiveKind CurrDir = Stack->getCurrentDirective(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13573 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 13574 | // If a list-item is a reference type then it must bind to the same object |
| 13575 | // for all threads of the team. |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 13576 | if (!ASE && !OASE) { |
| 13577 | if (VD) { |
| 13578 | VarDecl *VDDef = VD->getDefinition(); |
| 13579 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
| 13580 | DSARefChecker Check(Stack); |
| 13581 | if (Check.Visit(VDDef->getInit())) { |
| 13582 | S.Diag(ELoc, diag::err_omp_reduction_ref_type_arg) |
| 13583 | << getOpenMPClauseName(ClauseKind) << ERange; |
| 13584 | S.Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 13585 | continue; |
| 13586 | } |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 13587 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13588 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13589 | |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 13590 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 13591 | // in a Construct] |
| 13592 | // Variables with the predetermined data-sharing attributes may not be |
| 13593 | // listed in data-sharing attributes clauses, except for the cases |
| 13594 | // listed below. For these exceptions only, listing a predetermined |
| 13595 | // variable in a data-sharing attribute clause is allowed and overrides |
| 13596 | // the variable's predetermined data-sharing attributes. |
| 13597 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 13598 | // Any number of reduction clauses can be specified on the directive, |
| 13599 | // but a list item can appear only once in the reduction clauses for that |
| 13600 | // directive. |
| 13601 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false); |
| 13602 | if (DVar.CKind == OMPC_reduction) { |
| 13603 | S.Diag(ELoc, diag::err_omp_once_referenced) |
| 13604 | << getOpenMPClauseName(ClauseKind); |
| 13605 | if (DVar.RefExpr) |
| 13606 | S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 13607 | continue; |
| 13608 | } |
| 13609 | if (DVar.CKind != OMPC_unknown) { |
| 13610 | S.Diag(ELoc, diag::err_omp_wrong_dsa) |
| 13611 | << getOpenMPClauseName(DVar.CKind) |
| 13612 | << getOpenMPClauseName(OMPC_reduction); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13613 | reportOriginalDsa(S, Stack, D, DVar); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13614 | continue; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 13615 | } |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 13616 | |
| 13617 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 13618 | // A list item that appears in a reduction clause of a worksharing |
| 13619 | // construct must be shared in the parallel regions to which any of the |
| 13620 | // worksharing regions arising from the worksharing construct bind. |
| 13621 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 13622 | !isOpenMPParallelDirective(CurrDir) && |
| 13623 | !isOpenMPTeamsDirective(CurrDir)) { |
| 13624 | DVar = Stack->getImplicitDSA(D, true); |
| 13625 | if (DVar.CKind != OMPC_shared) { |
| 13626 | S.Diag(ELoc, diag::err_omp_required_access) |
| 13627 | << getOpenMPClauseName(OMPC_reduction) |
| 13628 | << getOpenMPClauseName(OMPC_shared); |
| 13629 | reportOriginalDsa(S, Stack, D, DVar); |
| 13630 | continue; |
| 13631 | } |
| 13632 | } |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 13633 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13634 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13635 | // Try to find 'declare reduction' corresponding construct before using |
| 13636 | // builtin/overloaded operators. |
| 13637 | CXXCastPath BasePath; |
| 13638 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13639 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13640 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 13641 | if (DeclareReductionRef.isInvalid()) |
| 13642 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13643 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13644 | (DeclareReductionRef.isUnset() || |
| 13645 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13646 | RD.push(RefExpr, DeclareReductionRef.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13647 | continue; |
| 13648 | } |
| 13649 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 13650 | // Not allowed reduction identifier is found. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13651 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13652 | diag::err_omp_unknown_reduction_identifier) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13653 | << Type << ReductionIdRange; |
| 13654 | continue; |
| 13655 | } |
| 13656 | |
| 13657 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 13658 | // The type of a list item that appears in a reduction clause must be valid |
| 13659 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 13660 | // of the list item must be an allowed arithmetic data type: char, int, |
| 13661 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 13662 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 13663 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 13664 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 13665 | if (DeclareReductionRef.isUnset()) { |
| 13666 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 13667 | !(Type->isScalarType() || |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13668 | (S.getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 13669 | S.Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 13670 | << getOpenMPClauseName(ClauseKind) << S.getLangOpts().CPlusPlus; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13671 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13672 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 13673 | VarDecl::DeclarationOnly; |
| 13674 | S.Diag(D->getLocation(), |
| 13675 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13676 | << D; |
| 13677 | } |
| 13678 | continue; |
| 13679 | } |
| 13680 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13681 | !S.getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 13682 | S.Diag(ELoc, diag::err_omp_clause_floating_type_arg) |
| 13683 | << getOpenMPClauseName(ClauseKind); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13684 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13685 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 13686 | VarDecl::DeclarationOnly; |
| 13687 | S.Diag(D->getLocation(), |
| 13688 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13689 | << D; |
| 13690 | } |
| 13691 | continue; |
| 13692 | } |
| 13693 | } |
| 13694 | |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13695 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13696 | VarDecl *LHSVD = buildVarDecl(S, ELoc, Type, ".reduction.lhs", |
| 13697 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 13698 | VarDecl *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(), |
| 13699 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 13700 | QualType PrivateTy = Type; |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13701 | |
| 13702 | // Try if we can determine constant lengths for all array sections and avoid |
| 13703 | // the VLA. |
| 13704 | bool ConstantLengthOASE = false; |
| 13705 | if (OASE) { |
| 13706 | bool SingleElement; |
| 13707 | llvm::SmallVector<llvm::APSInt, 4> ArraySizes; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13708 | ConstantLengthOASE = checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13709 | Context, OASE, SingleElement, ArraySizes); |
| 13710 | |
| 13711 | // If we don't have a single element, we must emit a constant array type. |
| 13712 | if (ConstantLengthOASE && !SingleElement) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13713 | for (llvm::APSInt &Size : ArraySizes) |
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 13714 | PrivateTy = Context.getConstantArrayType(PrivateTy, Size, nullptr, |
| 13715 | ArrayType::Normal, |
| 13716 | /*IndexTypeQuals=*/0); |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 13717 | } |
| 13718 | } |
| 13719 | |
| 13720 | if ((OASE && !ConstantLengthOASE) || |
| Jonas Hahnfeld | 96087f3 | 2017-11-02 13:30:42 +0000 | [diff] [blame] | 13721 | (!OASE && !ASE && |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13722 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| Alexey Bataev | 8526031 | 2019-07-11 20:35:31 +0000 | [diff] [blame] | 13723 | if (!Context.getTargetInfo().isVLASupported()) { |
| 13724 | if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective())) { |
| 13725 | S.Diag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; |
| 13726 | S.Diag(ELoc, diag::note_vla_unsupported); |
| 13727 | } else { |
| 13728 | S.targetDiag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; |
| 13729 | S.targetDiag(ELoc, diag::note_vla_unsupported); |
| 13730 | } |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 13731 | continue; |
| 13732 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13733 | // For arrays/array sections only: |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13734 | // Create pseudo array type for private copy. The size for this array will |
| 13735 | // be generated during codegen. |
| 13736 | // For array subscripts or single variables Private Ty is the same as Type |
| 13737 | // (type of the variable or single array element). |
| 13738 | PrivateTy = Context.getVariableArrayType( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13739 | Type, |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 13740 | new (Context) OpaqueValueExpr(ELoc, Context.getSizeType(), VK_RValue), |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13741 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13742 | } else if (!ASE && !OASE && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13743 | Context.getAsArrayType(D->getType().getNonReferenceType())) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13744 | PrivateTy = D->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13745 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13746 | // Private copy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13747 | VarDecl *PrivateVD = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 13748 | buildVarDecl(S, ELoc, PrivateTy, D->getName(), |
| 13749 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 13750 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13751 | // Add initializer for private variable. |
| 13752 | Expr *Init = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13753 | DeclRefExpr *LHSDRE = buildDeclRefExpr(S, LHSVD, Type, ELoc); |
| 13754 | DeclRefExpr *RHSDRE = buildDeclRefExpr(S, RHSVD, Type, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13755 | if (DeclareReductionRef.isUsable()) { |
| 13756 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 13757 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 13758 | if (DRD->getInitializer()) { |
| 13759 | Init = DRDRef; |
| 13760 | RHSVD->setInit(DRDRef); |
| 13761 | RHSVD->setInitStyle(VarDecl::CallInit); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13762 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13763 | } else { |
| 13764 | switch (BOK) { |
| 13765 | case BO_Add: |
| 13766 | case BO_Xor: |
| 13767 | case BO_Or: |
| 13768 | case BO_LOr: |
| 13769 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 13770 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13771 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13772 | break; |
| 13773 | case BO_Mul: |
| 13774 | case BO_LAnd: |
| 13775 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 13776 | // '*' and '&&' reduction ops - initializer is '1'. |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13777 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13778 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13779 | break; |
| 13780 | case BO_And: { |
| 13781 | // '&' reduction op - initializer is '~0'. |
| 13782 | QualType OrigType = Type; |
| 13783 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 13784 | Type = ComplexTy->getElementType(); |
| 13785 | if (Type->isRealFloatingType()) { |
| 13786 | llvm::APFloat InitValue = |
| 13787 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 13788 | /*isIEEE=*/true); |
| 13789 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 13790 | Type, ELoc); |
| 13791 | } else if (Type->isScalarType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13792 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13793 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 13794 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 13795 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 13796 | } |
| 13797 | if (Init && OrigType->isAnyComplexType()) { |
| 13798 | // Init = 0xFFFF + 0xFFFFi; |
| 13799 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13800 | Init = S.CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13801 | } |
| 13802 | Type = OrigType; |
| 13803 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13804 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13805 | case BO_LT: |
| 13806 | case BO_GT: { |
| 13807 | // 'min' reduction op - initializer is 'Largest representable number in |
| 13808 | // the reduction list item type'. |
| 13809 | // 'max' reduction op - initializer is 'Least representable number in |
| 13810 | // the reduction list item type'. |
| 13811 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 13812 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13813 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13814 | QualType IntTy = |
| 13815 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 13816 | llvm::APInt InitValue = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13817 | (BOK != BO_LT) ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 13818 | : llvm::APInt::getMinValue(Size) |
| 13819 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 13820 | : llvm::APInt::getMaxValue(Size); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13821 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 13822 | if (Type->isPointerType()) { |
| 13823 | // Cast to pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13824 | ExprResult CastExpr = S.BuildCStyleCastExpr( |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 13825 | ELoc, Context.getTrivialTypeSourceInfo(Type, ELoc), ELoc, Init); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13826 | if (CastExpr.isInvalid()) |
| 13827 | continue; |
| 13828 | Init = CastExpr.get(); |
| 13829 | } |
| 13830 | } else if (Type->isRealFloatingType()) { |
| 13831 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 13832 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 13833 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 13834 | Type, ELoc); |
| 13835 | } |
| 13836 | break; |
| 13837 | } |
| 13838 | case BO_PtrMemD: |
| 13839 | case BO_PtrMemI: |
| 13840 | case BO_MulAssign: |
| 13841 | case BO_Div: |
| 13842 | case BO_Rem: |
| 13843 | case BO_Sub: |
| 13844 | case BO_Shl: |
| 13845 | case BO_Shr: |
| 13846 | case BO_LE: |
| 13847 | case BO_GE: |
| 13848 | case BO_EQ: |
| 13849 | case BO_NE: |
| Richard Smith | c70f1d6 | 2017-12-14 15:16:18 +0000 | [diff] [blame] | 13850 | case BO_Cmp: |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13851 | case BO_AndAssign: |
| 13852 | case BO_XorAssign: |
| 13853 | case BO_OrAssign: |
| 13854 | case BO_Assign: |
| 13855 | case BO_AddAssign: |
| 13856 | case BO_SubAssign: |
| 13857 | case BO_DivAssign: |
| 13858 | case BO_RemAssign: |
| 13859 | case BO_ShlAssign: |
| 13860 | case BO_ShrAssign: |
| 13861 | case BO_Comma: |
| 13862 | llvm_unreachable("Unexpected reduction operation"); |
| 13863 | } |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13864 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13865 | if (Init && DeclareReductionRef.isUnset()) |
| 13866 | S.AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
| 13867 | else if (!Init) |
| 13868 | S.ActOnUninitializedDecl(RHSVD); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13869 | if (RHSVD->isInvalidDecl()) |
| 13870 | continue; |
| Alexey Bataev | 0923266 | 2019-04-04 17:28:22 +0000 | [diff] [blame] | 13871 | if (!RHSVD->hasInit() && |
| 13872 | (DeclareReductionRef.isUnset() || !S.LangOpts.CPlusPlus)) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13873 | S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible) |
| 13874 | << Type << ReductionIdRange; |
| 13875 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 13876 | VarDecl::DeclarationOnly; |
| 13877 | S.Diag(D->getLocation(), |
| 13878 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13879 | << D; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13880 | continue; |
| 13881 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 13882 | // Store initializer for single element in private copy. Will be used during |
| 13883 | // codegen. |
| 13884 | PrivateVD->setInit(RHSVD->getInit()); |
| 13885 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13886 | DeclRefExpr *PrivateDRE = buildDeclRefExpr(S, PrivateVD, PrivateTy, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13887 | ExprResult ReductionOp; |
| 13888 | if (DeclareReductionRef.isUsable()) { |
| 13889 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 13890 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13891 | ExprResult LHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 13892 | ExprResult RHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13893 | if (!BasePath.empty()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13894 | LHS = S.DefaultLvalueConversion(LHS.get()); |
| 13895 | RHS = S.DefaultLvalueConversion(RHS.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13896 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 13897 | CK_UncheckedDerivedToBase, LHS.get(), |
| 13898 | &BasePath, LHS.get()->getValueKind()); |
| 13899 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 13900 | CK_UncheckedDerivedToBase, RHS.get(), |
| 13901 | &BasePath, RHS.get()->getValueKind()); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 13902 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13903 | FunctionProtoType::ExtProtoInfo EPI; |
| 13904 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 13905 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 13906 | auto *OVE = new (Context) OpaqueValueExpr( |
| 13907 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13908 | S.DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13909 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 13910 | ReductionOp = |
| 13911 | CallExpr::Create(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13912 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13913 | ReductionOp = S.BuildBinOp( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13914 | Stack->getCurScope(), ReductionId.getBeginLoc(), BOK, LHSDRE, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13915 | if (ReductionOp.isUsable()) { |
| 13916 | if (BOK != BO_LT && BOK != BO_GT) { |
| 13917 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13918 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13919 | BO_Assign, LHSDRE, ReductionOp.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13920 | } else { |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 13921 | auto *ConditionalOp = new (Context) |
| 13922 | ConditionalOperator(ReductionOp.get(), ELoc, LHSDRE, ELoc, RHSDRE, |
| 13923 | Type, VK_LValue, OK_Ordinary); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13924 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13925 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13926 | BO_Assign, LHSDRE, ConditionalOp); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13927 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 13928 | if (ReductionOp.isUsable()) |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 13929 | ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get(), |
| 13930 | /*DiscardedValue*/ false); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13931 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 13932 | if (!ReductionOp.isUsable()) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13933 | continue; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13934 | } |
| 13935 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13936 | // OpenMP [2.15.4.6, Restrictions, p.2] |
| 13937 | // A list item that appears in an in_reduction clause of a task construct |
| 13938 | // must appear in a task_reduction clause of a construct associated with a |
| 13939 | // taskgroup region that includes the participating task in its taskgroup |
| 13940 | // set. The construct associated with the innermost region that meets this |
| 13941 | // condition must specify the same reduction-identifier as the in_reduction |
| 13942 | // clause. |
| 13943 | if (ClauseKind == OMPC_in_reduction) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13944 | SourceRange ParentSR; |
| 13945 | BinaryOperatorKind ParentBOK; |
| 13946 | const Expr *ParentReductionOp; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13947 | Expr *ParentBOKTD, *ParentReductionOpTD; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 13948 | DSAStackTy::DSAVarData ParentBOKDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13949 | Stack->getTopMostTaskgroupReductionData(D, ParentSR, ParentBOK, |
| 13950 | ParentBOKTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 13951 | DSAStackTy::DSAVarData ParentReductionOpDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13952 | Stack->getTopMostTaskgroupReductionData( |
| 13953 | D, ParentSR, ParentReductionOp, ParentReductionOpTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 13954 | bool IsParentBOK = ParentBOKDSA.DKind != OMPD_unknown; |
| 13955 | bool IsParentReductionOp = ParentReductionOpDSA.DKind != OMPD_unknown; |
| 13956 | if (!IsParentBOK && !IsParentReductionOp) { |
| 13957 | S.Diag(ELoc, diag::err_omp_in_reduction_not_task_reduction); |
| 13958 | continue; |
| 13959 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13960 | if ((DeclareReductionRef.isUnset() && IsParentReductionOp) || |
| 13961 | (DeclareReductionRef.isUsable() && IsParentBOK) || BOK != ParentBOK || |
| 13962 | IsParentReductionOp) { |
| 13963 | bool EmitError = true; |
| 13964 | if (IsParentReductionOp && DeclareReductionRef.isUsable()) { |
| 13965 | llvm::FoldingSetNodeID RedId, ParentRedId; |
| 13966 | ParentReductionOp->Profile(ParentRedId, Context, /*Canonical=*/true); |
| 13967 | DeclareReductionRef.get()->Profile(RedId, Context, |
| 13968 | /*Canonical=*/true); |
| 13969 | EmitError = RedId != ParentRedId; |
| 13970 | } |
| 13971 | if (EmitError) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13972 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13973 | diag::err_omp_reduction_identifier_mismatch) |
| 13974 | << ReductionIdRange << RefExpr->getSourceRange(); |
| 13975 | S.Diag(ParentSR.getBegin(), |
| 13976 | diag::note_omp_previous_reduction_identifier) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 13977 | << ParentSR |
| 13978 | << (IsParentBOK ? ParentBOKDSA.RefExpr |
| 13979 | : ParentReductionOpDSA.RefExpr) |
| 13980 | ->getSourceRange(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13981 | continue; |
| 13982 | } |
| 13983 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 13984 | TaskgroupDescriptor = IsParentBOK ? ParentBOKTD : ParentReductionOpTD; |
| 13985 | assert(TaskgroupDescriptor && "Taskgroup descriptor must be defined."); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 13986 | } |
| 13987 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13988 | DeclRefExpr *Ref = nullptr; |
| 13989 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13990 | if (!VD && !S.CurContext->isDependentContext()) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13991 | if (ASE || OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13992 | TransformExprToCaptures RebuildToCapture(S, D); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 13993 | VarsExpr = |
| 13994 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 13995 | Ref = RebuildToCapture.getCapturedExpr(); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 13996 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 13997 | VarsExpr = Ref = buildCapture(S, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 13998 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13999 | if (!S.isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14000 | RD.ExprCaptures.emplace_back(Ref->getDecl()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 14001 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14002 | ExprResult RefRes = S.DefaultLvalueConversion(Ref); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 14003 | if (!RefRes.isUsable()) |
| 14004 | continue; |
| 14005 | ExprResult PostUpdateRes = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14006 | S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 14007 | RefRes.get()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 14008 | if (!PostUpdateRes.isUsable()) |
| 14009 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14010 | if (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
| 14011 | Stack->getCurrentDirective() == OMPD_taskgroup) { |
| 14012 | S.Diag(RefExpr->getExprLoc(), |
| 14013 | diag::err_omp_reduction_non_addressable_expression) |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 14014 | << RefExpr->getSourceRange(); |
| 14015 | continue; |
| 14016 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14017 | RD.ExprPostUpdates.emplace_back( |
| 14018 | S.IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 14019 | } |
| 14020 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 14021 | } |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 14022 | // All reduction items are still marked as reduction (to do not increase |
| 14023 | // code base size). |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14024 | Stack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 14025 | if (CurrDir == OMPD_taskgroup) { |
| 14026 | if (DeclareReductionRef.isUsable()) |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 14027 | Stack->addTaskgroupReductionData(D, ReductionIdRange, |
| 14028 | DeclareReductionRef.get()); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 14029 | else |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 14030 | Stack->addTaskgroupReductionData(D, ReductionIdRange, BOK); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 14031 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 14032 | RD.push(VarsExpr, PrivateDRE, LHSDRE, RHSDRE, ReductionOp.get(), |
| 14033 | TaskgroupDescriptor); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 14034 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14035 | return RD.Vars.empty(); |
| 14036 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 14037 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14038 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 14039 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 14040 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 14041 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 14042 | ArrayRef<Expr *> UnresolvedReductions) { |
| 14043 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14044 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_reduction, VarList, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 14045 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 14046 | ReductionIdScopeSpec, ReductionId, |
| 14047 | UnresolvedReductions, RD)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 14048 | return nullptr; |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 14049 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 14050 | return OMPReductionClause::Create( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 14051 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 14052 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 14053 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 14054 | buildPreInits(Context, RD.ExprCaptures), |
| 14055 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 14056 | } |
| 14057 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 14058 | OMPClause *Sema::ActOnOpenMPTaskReductionClause( |
| 14059 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 14060 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 14061 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 14062 | ArrayRef<Expr *> UnresolvedReductions) { |
| 14063 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14064 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_task_reduction, VarList, |
| 14065 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 14066 | ReductionIdScopeSpec, ReductionId, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 14067 | UnresolvedReductions, RD)) |
| 14068 | return nullptr; |
| 14069 | |
| 14070 | return OMPTaskReductionClause::Create( |
| 14071 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 14072 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 14073 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 14074 | buildPreInits(Context, RD.ExprCaptures), |
| 14075 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 14076 | } |
| 14077 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 14078 | OMPClause *Sema::ActOnOpenMPInReductionClause( |
| 14079 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 14080 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 14081 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 14082 | ArrayRef<Expr *> UnresolvedReductions) { |
| 14083 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14084 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_in_reduction, VarList, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 14085 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 14086 | ReductionIdScopeSpec, ReductionId, |
| 14087 | UnresolvedReductions, RD)) |
| 14088 | return nullptr; |
| 14089 | |
| 14090 | return OMPInReductionClause::Create( |
| 14091 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 14092 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 14093 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, RD.TaskgroupDescriptors, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 14094 | buildPreInits(Context, RD.ExprCaptures), |
| 14095 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 14096 | } |
| 14097 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14098 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 14099 | SourceLocation LinLoc) { |
| 14100 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 14101 | LinKind == OMPC_LINEAR_unknown) { |
| 14102 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 14103 | return true; |
| 14104 | } |
| 14105 | return false; |
| 14106 | } |
| 14107 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14108 | bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14109 | OpenMPLinearClauseKind LinKind, |
| 14110 | QualType Type) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14111 | const auto *VD = dyn_cast_or_null<VarDecl>(D); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14112 | // A variable must not have an incomplete type or a reference type. |
| 14113 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 14114 | return true; |
| 14115 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 14116 | !Type->isReferenceType()) { |
| 14117 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 14118 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 14119 | return true; |
| 14120 | } |
| 14121 | Type = Type.getNonReferenceType(); |
| 14122 | |
| Joel E. Denny | bae586f | 2019-01-04 22:12:13 +0000 | [diff] [blame] | 14123 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 14124 | // A variable that is privatized must not have a const-qualified type |
| 14125 | // unless it is of class type with a mutable member. This restriction does |
| 14126 | // not apply to the firstprivate clause. |
| 14127 | if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc)) |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14128 | return true; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14129 | |
| 14130 | // A list item must be of integral or pointer type. |
| 14131 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 14132 | const auto *Ty = Type.getTypePtrOrNull(); |
| 14133 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 14134 | !Ty->isPointerType())) { |
| 14135 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 14136 | if (D) { |
| 14137 | bool IsDecl = |
| 14138 | !VD || |
| 14139 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 14140 | Diag(D->getLocation(), |
| 14141 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 14142 | << D; |
| 14143 | } |
| 14144 | return true; |
| 14145 | } |
| 14146 | return false; |
| 14147 | } |
| 14148 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 14149 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 14150 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 14151 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 14152 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14153 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14154 | SmallVector<Expr *, 8> Privates; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14155 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 14156 | SmallVector<Decl *, 4> ExprCaptures; |
| 14157 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14158 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 14159 | LinKind = OMPC_LINEAR_val; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14160 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14161 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14162 | SourceLocation ELoc; |
| 14163 | SourceRange ERange; |
| 14164 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 14165 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14166 | if (Res.second) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14167 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14168 | Vars.push_back(RefExpr); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14169 | Privates.push_back(nullptr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14170 | Inits.push_back(nullptr); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14171 | } |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14172 | ValueDecl *D = Res.first; |
| 14173 | if (!D) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14174 | continue; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14175 | |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14176 | QualType Type = D->getType(); |
| 14177 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14178 | |
| 14179 | // OpenMP [2.14.3.7, linear clause] |
| 14180 | // A list-item cannot appear in more than one linear clause. |
| 14181 | // A list-item that appears in a linear clause cannot appear in any |
| 14182 | // other data-sharing attribute clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14183 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14184 | if (DVar.RefExpr) { |
| 14185 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 14186 | << getOpenMPClauseName(OMPC_linear); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14187 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14188 | continue; |
| 14189 | } |
| 14190 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14191 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14192 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 14193 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14194 | |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14195 | // Build private copy of original var. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14196 | VarDecl *Private = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 14197 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 14198 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 14199 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14200 | DeclRefExpr *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14201 | // Build var to save initial value. |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14202 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 14203 | Expr *InitExpr; |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14204 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 14205 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 14206 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14207 | if (!isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 14208 | ExprCaptures.push_back(Ref->getDecl()); |
| 14209 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 14210 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 14211 | if (!RefRes.isUsable()) |
| 14212 | continue; |
| 14213 | ExprResult PostUpdateRes = |
| 14214 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 14215 | SimpleRefExpr, RefRes.get()); |
| 14216 | if (!PostUpdateRes.isUsable()) |
| 14217 | continue; |
| 14218 | ExprPostUpdates.push_back( |
| 14219 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 14220 | } |
| 14221 | } |
| 14222 | } |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 14223 | if (LinKind == OMPC_LINEAR_uval) |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14224 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 14225 | else |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14226 | InitExpr = VD ? SimpleRefExpr : Ref; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 14227 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 14228 | /*DirectInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14229 | DeclRefExpr *InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 14230 | |
| 14231 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 14232 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 14233 | ? RefExpr->IgnoreParens() |
| 14234 | : Ref); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14235 | Privates.push_back(PrivateRef); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14236 | Inits.push_back(InitRef); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14237 | } |
| 14238 | |
| 14239 | if (Vars.empty()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 14240 | return nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14241 | |
| 14242 | Expr *StepExpr = Step; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14243 | Expr *CalcStepExpr = nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14244 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 14245 | !Step->isInstantiationDependent() && |
| 14246 | !Step->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14247 | SourceLocation StepLoc = Step->getBeginLoc(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 14248 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14249 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 14250 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 14251 | StepExpr = Val.get(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14252 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14253 | // Build var to save the step value. |
| 14254 | VarDecl *SaveVar = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 14255 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14256 | ExprResult SaveRef = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 14257 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14258 | ExprResult CalcStep = |
| 14259 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 14260 | CalcStep = ActOnFinishFullExpr(CalcStep.get(), /*DiscardedValue*/ false); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14261 | |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14262 | // Warn about zero linear step (it would be probably better specified as |
| 14263 | // making corresponding variables 'const'). |
| 14264 | llvm::APSInt Result; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14265 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 14266 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14267 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 14268 | << (Vars.size() > 1); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14269 | if (!IsConstant && CalcStep.isUsable()) { |
| 14270 | // Calculate the step beforehand instead of doing this on each iteration. |
| 14271 | // (This is not used if the number of iterations may be kfold-ed). |
| 14272 | CalcStepExpr = CalcStep.get(); |
| 14273 | } |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14274 | } |
| 14275 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 14276 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 14277 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 14278 | StepExpr, CalcStepExpr, |
| 14279 | buildPreInits(Context, ExprCaptures), |
| 14280 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14281 | } |
| 14282 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14283 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 14284 | Expr *NumIterations, Sema &SemaRef, |
| 14285 | Scope *S, DSAStackTy *Stack) { |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14286 | // Walk the vars and build update/final expressions for the CodeGen. |
| 14287 | SmallVector<Expr *, 8> Updates; |
| 14288 | SmallVector<Expr *, 8> Finals; |
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 14289 | SmallVector<Expr *, 8> UsedExprs; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14290 | Expr *Step = Clause.getStep(); |
| 14291 | Expr *CalcStep = Clause.getCalcStep(); |
| 14292 | // OpenMP [2.14.3.7, linear clause] |
| 14293 | // If linear-step is not specified it is assumed to be 1. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14294 | if (!Step) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14295 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14296 | else if (CalcStep) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14297 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 14298 | bool HasErrors = false; |
| 14299 | auto CurInit = Clause.inits().begin(); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14300 | auto CurPrivate = Clause.privates().begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14301 | OpenMPLinearClauseKind LinKind = Clause.getModifier(); |
| 14302 | for (Expr *RefExpr : Clause.varlists()) { |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14303 | SourceLocation ELoc; |
| 14304 | SourceRange ERange; |
| 14305 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 14306 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14307 | ValueDecl *D = Res.first; |
| 14308 | if (Res.second || !D) { |
| 14309 | Updates.push_back(nullptr); |
| 14310 | Finals.push_back(nullptr); |
| 14311 | HasErrors = true; |
| 14312 | continue; |
| 14313 | } |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14314 | auto &&Info = Stack->isLoopControlVariable(D); |
| Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 14315 | // OpenMP [2.15.11, distribute simd Construct] |
| 14316 | // A list item may not appear in a linear clause, unless it is the loop |
| 14317 | // iteration variable. |
| 14318 | if (isOpenMPDistributeDirective(Stack->getCurrentDirective()) && |
| 14319 | isOpenMPSimdDirective(Stack->getCurrentDirective()) && !Info.first) { |
| 14320 | SemaRef.Diag(ELoc, |
| 14321 | diag::err_omp_linear_distribute_var_non_loop_iteration); |
| 14322 | Updates.push_back(nullptr); |
| 14323 | Finals.push_back(nullptr); |
| 14324 | HasErrors = true; |
| 14325 | continue; |
| 14326 | } |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14327 | Expr *InitExpr = *CurInit; |
| 14328 | |
| 14329 | // Build privatized reference to the current linear var. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14330 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 14331 | Expr *CapturedRef; |
| 14332 | if (LinKind == OMPC_LINEAR_uval) |
| 14333 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 14334 | else |
| 14335 | CapturedRef = |
| 14336 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 14337 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 14338 | /*RefersToCapture=*/true); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14339 | |
| 14340 | // Build update: Var = InitExpr + IV * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14341 | ExprResult Update; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14342 | if (!Info.first) |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 14343 | Update = buildCounterUpdate( |
| 14344 | SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, InitExpr, IV, Step, |
| 14345 | /*Subtract=*/false, /*IsNonRectangularLB=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14346 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14347 | Update = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14348 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getBeginLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 14349 | /*DiscardedValue*/ false); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14350 | |
| 14351 | // Build final: Var = InitExpr + NumIterations * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14352 | ExprResult Final; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14353 | if (!Info.first) |
| 14354 | Final = |
| 14355 | buildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| Alexey Bataev | f8be476 | 2019-08-14 19:30:06 +0000 | [diff] [blame] | 14356 | InitExpr, NumIterations, Step, /*Subtract=*/false, |
| 14357 | /*IsNonRectangularLB=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14358 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14359 | Final = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14360 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getBeginLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 14361 | /*DiscardedValue*/ false); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 14362 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14363 | if (!Update.isUsable() || !Final.isUsable()) { |
| 14364 | Updates.push_back(nullptr); |
| 14365 | Finals.push_back(nullptr); |
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 14366 | UsedExprs.push_back(nullptr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14367 | HasErrors = true; |
| 14368 | } else { |
| 14369 | Updates.push_back(Update.get()); |
| 14370 | Finals.push_back(Final.get()); |
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 14371 | if (!Info.first) |
| 14372 | UsedExprs.push_back(SimpleRefExpr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14373 | } |
| Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 14374 | ++CurInit; |
| 14375 | ++CurPrivate; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14376 | } |
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 14377 | if (Expr *S = Clause.getStep()) |
| 14378 | UsedExprs.push_back(S); |
| 14379 | // Fill the remaining part with the nullptr. |
| 14380 | UsedExprs.append(Clause.varlist_size() + 1 - UsedExprs.size(), nullptr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14381 | Clause.setUpdates(Updates); |
| 14382 | Clause.setFinals(Finals); |
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 14383 | Clause.setUsedExprs(UsedExprs); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 14384 | return HasErrors; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 14385 | } |
| 14386 | |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14387 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 14388 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 14389 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14390 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14391 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14392 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 14393 | SourceLocation ELoc; |
| 14394 | SourceRange ERange; |
| 14395 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 14396 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14397 | if (Res.second) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14398 | // It will be analyzed later. |
| 14399 | Vars.push_back(RefExpr); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14400 | } |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14401 | ValueDecl *D = Res.first; |
| 14402 | if (!D) |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14403 | continue; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14404 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14405 | QualType QType = D->getType(); |
| 14406 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14407 | |
| 14408 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 14409 | // The type of list items appearing in the aligned clause must be |
| 14410 | // array, pointer, reference to array, or reference to pointer. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 14411 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14412 | const Type *Ty = QType.getTypePtrOrNull(); |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14413 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14414 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14415 | << QType << getLangOpts().CPlusPlus << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14416 | bool IsDecl = |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14417 | !VD || |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14418 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14419 | Diag(D->getLocation(), |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14420 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14421 | << D; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14422 | continue; |
| 14423 | } |
| 14424 | |
| 14425 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 14426 | // A list-item cannot appear in more than one aligned clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14427 | if (const Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 14428 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14429 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 14430 | << getOpenMPClauseName(OMPC_aligned); |
| 14431 | continue; |
| 14432 | } |
| 14433 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14434 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14435 | if (!VD && isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 14436 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 14437 | Vars.push_back(DefaultFunctionArrayConversion( |
| 14438 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 14439 | .get()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 14440 | } |
| 14441 | |
| 14442 | // OpenMP [2.8.1, simd construct, Description] |
| 14443 | // The parameter of the aligned clause, alignment, must be a constant |
| 14444 | // positive integer expression. |
| 14445 | // If no optional parameter is specified, implementation-defined default |
| 14446 | // alignments for SIMD instructions on the target platforms are assumed. |
| 14447 | if (Alignment != nullptr) { |
| 14448 | ExprResult AlignResult = |
| 14449 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 14450 | if (AlignResult.isInvalid()) |
| 14451 | return nullptr; |
| 14452 | Alignment = AlignResult.get(); |
| 14453 | } |
| 14454 | if (Vars.empty()) |
| 14455 | return nullptr; |
| 14456 | |
| 14457 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 14458 | EndLoc, Vars, Alignment); |
| 14459 | } |
| 14460 | |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14461 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 14462 | SourceLocation StartLoc, |
| 14463 | SourceLocation LParenLoc, |
| 14464 | SourceLocation EndLoc) { |
| 14465 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14466 | SmallVector<Expr *, 8> SrcExprs; |
| 14467 | SmallVector<Expr *, 8> DstExprs; |
| 14468 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14469 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14470 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 14471 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14472 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14473 | Vars.push_back(RefExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14474 | SrcExprs.push_back(nullptr); |
| 14475 | DstExprs.push_back(nullptr); |
| 14476 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14477 | continue; |
| 14478 | } |
| 14479 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14480 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14481 | // OpenMP [2.1, C/C++] |
| 14482 | // A list item is a variable name. |
| 14483 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 14484 | // A list item that appears in a copyin clause must be threadprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14485 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14486 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 14487 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 14488 | << 0 << RefExpr->getSourceRange(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14489 | continue; |
| 14490 | } |
| 14491 | |
| 14492 | Decl *D = DE->getDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14493 | auto *VD = cast<VarDecl>(D); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14494 | |
| 14495 | QualType Type = VD->getType(); |
| 14496 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 14497 | // It will be analyzed later. |
| 14498 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14499 | SrcExprs.push_back(nullptr); |
| 14500 | DstExprs.push_back(nullptr); |
| 14501 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14502 | continue; |
| 14503 | } |
| 14504 | |
| 14505 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 14506 | // A list item that appears in a copyin clause must be threadprivate. |
| 14507 | if (!DSAStack->isThreadPrivate(VD)) { |
| 14508 | Diag(ELoc, diag::err_omp_required_access) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14509 | << getOpenMPClauseName(OMPC_copyin) |
| 14510 | << getOpenMPDirectiveName(OMPD_threadprivate); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14511 | continue; |
| 14512 | } |
| 14513 | |
| 14514 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 14515 | // A variable of class type (or array thereof) that appears in a |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 14516 | // copyin clause requires an accessible, unambiguous copy assignment |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14517 | // operator for the class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14518 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| 14519 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14520 | buildVarDecl(*this, DE->getBeginLoc(), ElemType.getUnqualifiedType(), |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 14521 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14522 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr( |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 14523 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14524 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14525 | buildVarDecl(*this, DE->getBeginLoc(), ElemType, ".copyin.dst", |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 14526 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14527 | DeclRefExpr *PseudoDstExpr = |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 14528 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14529 | // For arrays generate assignment operation for single element and replace |
| 14530 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14531 | ExprResult AssignmentOp = |
| 14532 | BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, PseudoDstExpr, |
| 14533 | PseudoSrcExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14534 | if (AssignmentOp.isInvalid()) |
| 14535 | continue; |
| 14536 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 14537 | /*DiscardedValue*/ false); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14538 | if (AssignmentOp.isInvalid()) |
| 14539 | continue; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14540 | |
| 14541 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 14542 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14543 | SrcExprs.push_back(PseudoSrcExpr); |
| 14544 | DstExprs.push_back(PseudoDstExpr); |
| 14545 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14546 | } |
| 14547 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 14548 | if (Vars.empty()) |
| 14549 | return nullptr; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14550 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 14551 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 14552 | SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 14553 | } |
| 14554 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14555 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 14556 | SourceLocation StartLoc, |
| 14557 | SourceLocation LParenLoc, |
| 14558 | SourceLocation EndLoc) { |
| 14559 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14560 | SmallVector<Expr *, 8> SrcExprs; |
| 14561 | SmallVector<Expr *, 8> DstExprs; |
| 14562 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14563 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14564 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 14565 | SourceLocation ELoc; |
| 14566 | SourceRange ERange; |
| 14567 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 14568 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14569 | if (Res.second) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14570 | // It will be analyzed later. |
| 14571 | Vars.push_back(RefExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14572 | SrcExprs.push_back(nullptr); |
| 14573 | DstExprs.push_back(nullptr); |
| 14574 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14575 | } |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14576 | ValueDecl *D = Res.first; |
| 14577 | if (!D) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14578 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14579 | |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14580 | QualType Type = D->getType(); |
| 14581 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14582 | |
| 14583 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 14584 | // A list item that appears in a copyprivate clause may not appear in a |
| 14585 | // private or firstprivate clause on the single construct. |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14586 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14587 | DSAStackTy::DSAVarData DVar = |
| 14588 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14589 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 14590 | DVar.RefExpr) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14591 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 14592 | << getOpenMPClauseName(DVar.CKind) |
| 14593 | << getOpenMPClauseName(OMPC_copyprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14594 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14595 | continue; |
| 14596 | } |
| 14597 | |
| 14598 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 14599 | // All list items that appear in a copyprivate clause must be either |
| 14600 | // threadprivate or private in the enclosing context. |
| 14601 | if (DVar.CKind == OMPC_unknown) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14602 | DVar = DSAStack->getImplicitDSA(D, false); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14603 | if (DVar.CKind == OMPC_shared) { |
| 14604 | Diag(ELoc, diag::err_omp_required_access) |
| 14605 | << getOpenMPClauseName(OMPC_copyprivate) |
| 14606 | << "threadprivate or private in the enclosing context"; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14607 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14608 | continue; |
| 14609 | } |
| 14610 | } |
| 14611 | } |
| 14612 | |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14613 | // Variably modified types are not supported. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 14614 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14615 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 14616 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 14617 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14618 | bool IsDecl = |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14619 | !VD || |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14620 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14621 | Diag(D->getLocation(), |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14622 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14623 | << D; |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 14624 | continue; |
| 14625 | } |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 14626 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14627 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 14628 | // A variable of class type (or array thereof) that appears in a |
| 14629 | // copyin clause requires an accessible, unambiguous copy assignment |
| 14630 | // operator for the class type. |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 14631 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 14632 | .getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14633 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14634 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.src", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14635 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14636 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
| 14637 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14638 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.dst", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14639 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14640 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 14641 | ExprResult AssignmentOp = BuildBinOp( |
| 14642 | DSAStack->getCurScope(), ELoc, BO_Assign, PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14643 | if (AssignmentOp.isInvalid()) |
| 14644 | continue; |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 14645 | AssignmentOp = |
| 14646 | ActOnFinishFullExpr(AssignmentOp.get(), ELoc, /*DiscardedValue*/ false); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14647 | if (AssignmentOp.isInvalid()) |
| 14648 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14649 | |
| 14650 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 14651 | // implicitly private. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14652 | assert(VD || isOpenMPCapturedDecl(D)); |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 14653 | Vars.push_back( |
| 14654 | VD ? RefExpr->IgnoreParens() |
| 14655 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14656 | SrcExprs.push_back(PseudoSrcExpr); |
| 14657 | DstExprs.push_back(PseudoDstExpr); |
| 14658 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14659 | } |
| 14660 | |
| 14661 | if (Vars.empty()) |
| 14662 | return nullptr; |
| 14663 | |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 14664 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 14665 | Vars, SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 14666 | } |
| 14667 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 14668 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 14669 | SourceLocation StartLoc, |
| 14670 | SourceLocation LParenLoc, |
| 14671 | SourceLocation EndLoc) { |
| 14672 | if (VarList.empty()) |
| 14673 | return nullptr; |
| 14674 | |
| 14675 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 14676 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 14677 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14678 | OMPClause * |
| 14679 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 14680 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 14681 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 14682 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 14683 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14684 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 14685 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 14686 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 14687 | return nullptr; |
| 14688 | } |
| 14689 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14690 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 14691 | DepKind == OMPC_DEPEND_sink)) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 14692 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14693 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 14694 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 14695 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 14696 | << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14697 | return nullptr; |
| 14698 | } |
| 14699 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 14700 | DSAStackTy::OperatorOffsetTy OpsOffs; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14701 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 14702 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 14703 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) { |
| 14704 | if (const Expr *OrderedCountExpr = |
| 14705 | DSAStack->getParentOrderedRegionParam().first) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14706 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 14707 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14708 | } |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14709 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14710 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14711 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 14712 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 14713 | // It will be analyzed later. |
| 14714 | Vars.push_back(RefExpr); |
| 14715 | continue; |
| 14716 | } |
| 14717 | |
| 14718 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14719 | Expr *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14720 | if (DepKind == OMPC_DEPEND_sink) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 14721 | if (DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14722 | DepCounter >= TotalDepCount) { |
| 14723 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 14724 | continue; |
| 14725 | } |
| 14726 | ++DepCounter; |
| 14727 | // OpenMP [2.13.9, Summary] |
| 14728 | // depend(dependence-type : vec), where dependence-type is: |
| 14729 | // 'sink' and where vec is the iteration vector, which has the form: |
| 14730 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 14731 | // where n is the value specified by the ordered clause in the loop |
| 14732 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 14733 | // loop associated with the loop directive, and di is a constant |
| 14734 | // non-negative integer. |
| 14735 | if (CurContext->isDependentContext()) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14736 | // It will be analyzed later. |
| 14737 | Vars.push_back(RefExpr); |
| 14738 | continue; |
| 14739 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14740 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 14741 | OverloadedOperatorKind OOK = OO_None; |
| 14742 | SourceLocation OOLoc; |
| 14743 | Expr *LHS = SimpleExpr; |
| 14744 | Expr *RHS = nullptr; |
| 14745 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 14746 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 14747 | OOLoc = BO->getOperatorLoc(); |
| 14748 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 14749 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 14750 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 14751 | OOK = OCE->getOperator(); |
| 14752 | OOLoc = OCE->getOperatorLoc(); |
| 14753 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 14754 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 14755 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 14756 | OOK = MCE->getMethodDecl() |
| 14757 | ->getNameInfo() |
| 14758 | .getName() |
| 14759 | .getCXXOverloadedOperator(); |
| 14760 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 14761 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 14762 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14763 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14764 | SourceLocation ELoc; |
| 14765 | SourceRange ERange; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 14766 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14767 | if (Res.second) { |
| 14768 | // It will be analyzed later. |
| 14769 | Vars.push_back(RefExpr); |
| 14770 | } |
| 14771 | ValueDecl *D = Res.first; |
| 14772 | if (!D) |
| 14773 | continue; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14774 | |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14775 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 14776 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 14777 | continue; |
| 14778 | } |
| 14779 | if (RHS) { |
| 14780 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 14781 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 14782 | if (RHSRes.isInvalid()) |
| 14783 | continue; |
| 14784 | } |
| 14785 | if (!CurContext->isDependentContext() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 14786 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14787 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14788 | const ValueDecl *VD = |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14789 | DSAStack->getParentLoopControlVariable(DepCounter.getZExtValue()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14790 | if (VD) |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14791 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 14792 | << 1 << VD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14793 | else |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14794 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) << 0; |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14795 | continue; |
| 14796 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14797 | OpsOffs.emplace_back(RHS, OOK); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14798 | } else { |
| 14799 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 14800 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 14801 | (ASE && |
| 14802 | !ASE->getBase()->getType().getNonReferenceType()->isPointerType() && |
| 14803 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
| 14804 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 14805 | << RefExpr->getSourceRange(); |
| 14806 | continue; |
| 14807 | } |
| Richard Smith | 2e3ed4a | 2019-08-16 19:53:22 +0000 | [diff] [blame] | 14808 | |
| 14809 | ExprResult Res; |
| 14810 | { |
| 14811 | Sema::TentativeAnalysisScope Trap(*this); |
| 14812 | Res = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, |
| 14813 | RefExpr->IgnoreParenImpCasts()); |
| 14814 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14815 | if (!Res.isUsable() && !isa<OMPArraySectionExpr>(SimpleExpr)) { |
| 14816 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 14817 | << RefExpr->getSourceRange(); |
| 14818 | continue; |
| 14819 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14820 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14821 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 14822 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14823 | |
| 14824 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 14825 | TotalDepCount > VarList.size() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 14826 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14827 | DSAStack->getParentLoopControlVariable(VarList.size() + 1)) { |
| 14828 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 14829 | << 1 << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 14830 | } |
| 14831 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 14832 | Vars.empty()) |
| 14833 | return nullptr; |
| 14834 | |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 14835 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 14836 | DepKind, DepLoc, ColonLoc, Vars, |
| 14837 | TotalDepCount.getZExtValue()); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 14838 | if ((DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) && |
| 14839 | DSAStack->isParentOrderedRegion()) |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 14840 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 14841 | return C; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 14842 | } |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 14843 | |
| 14844 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 14845 | SourceLocation LParenLoc, |
| 14846 | SourceLocation EndLoc) { |
| 14847 | Expr *ValExpr = Device; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 14848 | Stmt *HelperValStmt = nullptr; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 14849 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 14850 | // OpenMP [2.9.1, Restrictions] |
| 14851 | // The device expression must evaluate to a non-negative integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14852 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 14853 | /*StrictlyPositive=*/false)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 14854 | return nullptr; |
| 14855 | |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 14856 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 14857 | OpenMPDirectiveKind CaptureRegion = |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 14858 | getOpenMPCaptureRegionForClause(DKind, OMPC_device, LangOpts.OpenMP); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 14859 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 14860 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14861 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 14862 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 14863 | HelperValStmt = buildPreInits(Context, Captures); |
| 14864 | } |
| 14865 | |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 14866 | return new (Context) OMPDeviceClause(ValExpr, HelperValStmt, CaptureRegion, |
| 14867 | StartLoc, LParenLoc, EndLoc); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 14868 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 14869 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14870 | static bool checkTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 14871 | DSAStackTy *Stack, QualType QTy, |
| 14872 | bool FullCheck = true) { |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 14873 | NamedDecl *ND; |
| 14874 | if (QTy->isIncompleteType(&ND)) { |
| 14875 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 14876 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 14877 | } |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 14878 | if (FullCheck && !SemaRef.CurContext->isDependentContext() && |
| 14879 | !QTy.isTrivialType(SemaRef.Context)) |
| 14880 | SemaRef.Diag(SL, diag::warn_omp_non_trivial_type_mapped) << QTy << SR; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 14881 | return true; |
| 14882 | } |
| 14883 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 14884 | /// Return true if it can be proven that the provided array expression |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14885 | /// (array section or array subscript) does NOT specify the whole size of the |
| 14886 | /// array whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14887 | static bool checkArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14888 | const Expr *E, |
| 14889 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14890 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14891 | |
| 14892 | // If this is an array subscript, it refers to the whole size if the size of |
| 14893 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 14894 | // format of an array subscript if no colon is used. |
| 14895 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14896 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14897 | return ATy->getSize().getSExtValue() != 1; |
| 14898 | // Size can't be evaluated statically. |
| 14899 | return false; |
| 14900 | } |
| 14901 | |
| 14902 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14903 | const Expr *LowerBound = OASE->getLowerBound(); |
| 14904 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14905 | |
| 14906 | // If there is a lower bound that does not evaluates to zero, we are not |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14907 | // covering the whole dimension. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14908 | if (LowerBound) { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14909 | Expr::EvalResult Result; |
| 14910 | if (!LowerBound->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14911 | return false; // Can't get the integer value as a constant. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14912 | |
| 14913 | llvm::APSInt ConstLowerBound = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14914 | if (ConstLowerBound.getSExtValue()) |
| 14915 | return true; |
| 14916 | } |
| 14917 | |
| 14918 | // If we don't have a length we covering the whole dimension. |
| 14919 | if (!Length) |
| 14920 | return false; |
| 14921 | |
| 14922 | // If the base is a pointer, we don't have a way to get the size of the |
| 14923 | // pointee. |
| 14924 | if (BaseQTy->isPointerType()) |
| 14925 | return false; |
| 14926 | |
| 14927 | // We can only check if the length is the same as the size of the dimension |
| 14928 | // if we have a constant array. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14929 | const auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14930 | if (!CATy) |
| 14931 | return false; |
| 14932 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14933 | Expr::EvalResult Result; |
| 14934 | if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14935 | return false; // Can't get the integer value as a constant. |
| 14936 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14937 | llvm::APSInt ConstLength = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14938 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 14939 | } |
| 14940 | |
| 14941 | // Return true if it can be proven that the provided array expression (array |
| 14942 | // section or array subscript) does NOT specify a single element of the array |
| 14943 | // whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14944 | static bool checkArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14945 | const Expr *E, |
| 14946 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14947 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14948 | |
| 14949 | // An array subscript always refer to a single element. Also, an array section |
| 14950 | // assumes the format of an array subscript if no colon is used. |
| 14951 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 14952 | return false; |
| 14953 | |
| 14954 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14955 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14956 | |
| 14957 | // If we don't have a length we have to check if the array has unitary size |
| 14958 | // for this dimension. Also, we should always expect a length if the base type |
| 14959 | // is pointer. |
| 14960 | if (!Length) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14961 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14962 | return ATy->getSize().getSExtValue() != 1; |
| 14963 | // We cannot assume anything. |
| 14964 | return false; |
| 14965 | } |
| 14966 | |
| 14967 | // Check if the length evaluates to 1. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14968 | Expr::EvalResult Result; |
| 14969 | if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14970 | return false; // Can't get the integer value as a constant. |
| 14971 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 14972 | llvm::APSInt ConstLength = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 14973 | return ConstLength.getSExtValue() != 1; |
| 14974 | } |
| 14975 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14976 | // Return the expression of the base of the mappable expression or null if it |
| 14977 | // cannot be determined and do all the necessary checks to see if the expression |
| 14978 | // is valid as a standalone mappable expression. In the process, record all the |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 14979 | // components of the expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14980 | static const Expr *checkMapClauseExpressionBase( |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 14981 | Sema &SemaRef, Expr *E, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14982 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 14983 | OpenMPClauseKind CKind, bool NoDiagnose) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 14984 | SourceLocation ELoc = E->getExprLoc(); |
| 14985 | SourceRange ERange = E->getSourceRange(); |
| 14986 | |
| 14987 | // The base of elements of list in a map clause have to be either: |
| 14988 | // - a reference to variable or field. |
| 14989 | // - a member expression. |
| 14990 | // - an array expression. |
| 14991 | // |
| 14992 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 14993 | // reference to 'r'. |
| 14994 | // |
| 14995 | // If we have: |
| 14996 | // |
| 14997 | // struct SS { |
| 14998 | // Bla S; |
| 14999 | // foo() { |
| 15000 | // #pragma omp target map (S.Arr[:12]); |
| 15001 | // } |
| 15002 | // } |
| 15003 | // |
| 15004 | // We want to retrieve the member expression 'this->S'; |
| 15005 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15006 | const Expr *RelevantExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15007 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15008 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 15009 | // If a list item is an array section, it must specify contiguous storage. |
| 15010 | // |
| 15011 | // For this restriction it is sufficient that we make sure only references |
| 15012 | // to variables or fields and array expressions, and that no array sections |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15013 | // exist except in the rightmost expression (unless they cover the whole |
| 15014 | // dimension of the array). E.g. these would be invalid: |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15015 | // |
| 15016 | // r.ArrS[3:5].Arr[6:7] |
| 15017 | // |
| 15018 | // r.ArrS[3:5].x |
| 15019 | // |
| 15020 | // but these would be valid: |
| 15021 | // r.ArrS[3].Arr[6:7] |
| 15022 | // |
| 15023 | // r.ArrS[3].x |
| 15024 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15025 | bool AllowUnitySizeArraySection = true; |
| 15026 | bool AllowWholeSizeArraySection = true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15027 | |
| Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 15028 | while (!RelevantExpr) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15029 | E = E->IgnoreParenImpCasts(); |
| 15030 | |
| 15031 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 15032 | if (!isa<VarDecl>(CurE->getDecl())) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15033 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15034 | |
| 15035 | RelevantExpr = CurE; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15036 | |
| 15037 | // If we got a reference to a declaration, we should not expect any array |
| 15038 | // section before that. |
| 15039 | AllowUnitySizeArraySection = false; |
| 15040 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15041 | |
| 15042 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15043 | CurComponents.emplace_back(CurE, CurE->getDecl()); |
| 15044 | } else if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15045 | Expr *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15046 | |
| 15047 | if (isa<CXXThisExpr>(BaseE)) |
| 15048 | // We found a base expression: this->Val. |
| 15049 | RelevantExpr = CurE; |
| 15050 | else |
| 15051 | E = BaseE; |
| 15052 | |
| 15053 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15054 | if (!NoDiagnose) { |
| 15055 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 15056 | << CurE->getSourceRange(); |
| 15057 | return nullptr; |
| 15058 | } |
| 15059 | if (RelevantExpr) |
| 15060 | return nullptr; |
| 15061 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15062 | } |
| 15063 | |
| 15064 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 15065 | |
| 15066 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 15067 | // A bit-field cannot appear in a map clause. |
| 15068 | // |
| 15069 | if (FD->isBitField()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15070 | if (!NoDiagnose) { |
| 15071 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 15072 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
| 15073 | return nullptr; |
| 15074 | } |
| 15075 | if (RelevantExpr) |
| 15076 | return nullptr; |
| 15077 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15078 | } |
| 15079 | |
| 15080 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 15081 | // If the type of a list item is a reference to a type T then the type |
| 15082 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15083 | QualType CurType = BaseE->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15084 | |
| 15085 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 15086 | // A list item cannot be a variable that is a member of a structure with |
| 15087 | // a union type. |
| 15088 | // |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15089 | if (CurType->isUnionType()) { |
| 15090 | if (!NoDiagnose) { |
| 15091 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 15092 | << CurE->getSourceRange(); |
| 15093 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15094 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15095 | continue; |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15096 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15097 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15098 | // If we got a member expression, we should not expect any array section |
| 15099 | // before that: |
| 15100 | // |
| 15101 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 15102 | // If a list item is an element of a structure, only the rightmost symbol |
| 15103 | // of the variable reference can be an array section. |
| 15104 | // |
| 15105 | AllowUnitySizeArraySection = false; |
| 15106 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15107 | |
| 15108 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15109 | CurComponents.emplace_back(CurE, FD); |
| 15110 | } else if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15111 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 15112 | |
| 15113 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15114 | if (!NoDiagnose) { |
| 15115 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 15116 | << 0 << CurE->getSourceRange(); |
| 15117 | return nullptr; |
| 15118 | } |
| 15119 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15120 | } |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15121 | |
| 15122 | // If we got an array subscript that express the whole dimension we |
| 15123 | // can have any array expressions before. If it only expressing part of |
| 15124 | // the dimension, we can only have unitary-size array expressions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15125 | if (checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15126 | E->getType())) |
| 15127 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15128 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 15129 | if (const auto *TE = dyn_cast<CXXThisExpr>(E)) { |
| 15130 | Expr::EvalResult Result; |
| 15131 | if (CurE->getIdx()->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 15132 | if (!Result.Val.getInt().isNullValue()) { |
| 15133 | SemaRef.Diag(CurE->getIdx()->getExprLoc(), |
| 15134 | diag::err_omp_invalid_map_this_expr); |
| 15135 | SemaRef.Diag(CurE->getIdx()->getExprLoc(), |
| 15136 | diag::note_omp_invalid_subscript_on_this_ptr_map); |
| 15137 | } |
| 15138 | } |
| 15139 | RelevantExpr = TE; |
| 15140 | } |
| 15141 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15142 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15143 | CurComponents.emplace_back(CurE, nullptr); |
| 15144 | } else if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15145 | assert(!NoDiagnose && "Array sections cannot be implicitly mapped."); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15146 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 15147 | |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15148 | QualType CurType = |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15149 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 15150 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15151 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 15152 | // If the type of a list item is a reference to a type T then the type |
| 15153 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15154 | if (CurType->isReferenceType()) |
| 15155 | CurType = CurType->getPointeeType(); |
| 15156 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15157 | bool IsPointer = CurType->isAnyPointerType(); |
| 15158 | |
| 15159 | if (!IsPointer && !CurType->isArrayType()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15160 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 15161 | << 0 << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15162 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15163 | } |
| 15164 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15165 | bool NotWhole = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15166 | checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15167 | bool NotUnity = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15168 | checkArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15169 | |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 15170 | if (AllowWholeSizeArraySection) { |
| 15171 | // Any array section is currently allowed. Allowing a whole size array |
| 15172 | // section implies allowing a unity array section as well. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15173 | // |
| 15174 | // If this array section refers to the whole dimension we can still |
| 15175 | // accept other array sections before this one, except if the base is a |
| 15176 | // pointer. Otherwise, only unitary sections are accepted. |
| 15177 | if (NotWhole || IsPointer) |
| 15178 | AllowWholeSizeArraySection = false; |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 15179 | } else if (AllowUnitySizeArraySection && NotUnity) { |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15180 | // A unity or whole array section is not allowed and that is not |
| 15181 | // compatible with the properties of the current array section. |
| 15182 | SemaRef.Diag( |
| 15183 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 15184 | << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15185 | return nullptr; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 15186 | } |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15187 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 15188 | if (const auto *TE = dyn_cast<CXXThisExpr>(E)) { |
| 15189 | Expr::EvalResult ResultR; |
| 15190 | Expr::EvalResult ResultL; |
| 15191 | if (CurE->getLength()->EvaluateAsInt(ResultR, |
| 15192 | SemaRef.getASTContext())) { |
| 15193 | if (!ResultR.Val.getInt().isOneValue()) { |
| 15194 | SemaRef.Diag(CurE->getLength()->getExprLoc(), |
| 15195 | diag::err_omp_invalid_map_this_expr); |
| 15196 | SemaRef.Diag(CurE->getLength()->getExprLoc(), |
| 15197 | diag::note_omp_invalid_length_on_this_ptr_mapping); |
| 15198 | } |
| 15199 | } |
| 15200 | if (CurE->getLowerBound() && CurE->getLowerBound()->EvaluateAsInt( |
| 15201 | ResultL, SemaRef.getASTContext())) { |
| 15202 | if (!ResultL.Val.getInt().isNullValue()) { |
| 15203 | SemaRef.Diag(CurE->getLowerBound()->getExprLoc(), |
| 15204 | diag::err_omp_invalid_map_this_expr); |
| 15205 | SemaRef.Diag(CurE->getLowerBound()->getExprLoc(), |
| 15206 | diag::note_omp_invalid_lower_bound_on_this_ptr_mapping); |
| 15207 | } |
| 15208 | } |
| 15209 | RelevantExpr = TE; |
| 15210 | } |
| 15211 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15212 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15213 | CurComponents.emplace_back(CurE, nullptr); |
| 15214 | } else { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 15215 | if (!NoDiagnose) { |
| 15216 | // If nothing else worked, this is not a valid map clause expression. |
| 15217 | SemaRef.Diag( |
| 15218 | ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 15219 | << ERange; |
| 15220 | } |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 15221 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15222 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15223 | } |
| 15224 | |
| 15225 | return RelevantExpr; |
| 15226 | } |
| 15227 | |
| 15228 | // Return true if expression E associated with value VD has conflicts with other |
| 15229 | // map information. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15230 | static bool checkMapConflicts( |
| 15231 | Sema &SemaRef, DSAStackTy *DSAS, const ValueDecl *VD, const Expr *E, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15232 | bool CurrentRegionOnly, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15233 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 15234 | OpenMPClauseKind CKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15235 | assert(VD && E); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15236 | SourceLocation ELoc = E->getExprLoc(); |
| 15237 | SourceRange ERange = E->getSourceRange(); |
| 15238 | |
| 15239 | // In order to easily check the conflicts we need to match each component of |
| 15240 | // the expression under test with the components of the expressions that are |
| 15241 | // already in the stack. |
| 15242 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15243 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15244 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15245 | "Map clause expression with unexpected base!"); |
| 15246 | |
| 15247 | // Variables to help detecting enclosing problems in data environment nests. |
| 15248 | bool IsEnclosedByDataEnvironmentExpr = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15249 | const Expr *EnclosingExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15250 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15251 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 15252 | VD, CurrentRegionOnly, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15253 | [&IsEnclosedByDataEnvironmentExpr, &SemaRef, VD, CurrentRegionOnly, ELoc, |
| 15254 | ERange, CKind, &EnclosingExpr, |
| 15255 | CurComponents](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 15256 | StackComponents, |
| 15257 | OpenMPClauseKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15258 | assert(!StackComponents.empty() && |
| 15259 | "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15260 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15261 | "Map clause expression with unexpected base!"); |
| Fangrui Song | 16fe49a | 2018-04-18 19:32:01 +0000 | [diff] [blame] | 15262 | (void)VD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15263 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15264 | // The whole expression in the stack. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15265 | const Expr *RE = StackComponents.front().getAssociatedExpression(); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15266 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15267 | // Expressions must start from the same base. Here we detect at which |
| 15268 | // point both expressions diverge from each other and see if we can |
| 15269 | // detect if the memory referred to both expressions is contiguous and |
| 15270 | // do not overlap. |
| 15271 | auto CI = CurComponents.rbegin(); |
| 15272 | auto CE = CurComponents.rend(); |
| 15273 | auto SI = StackComponents.rbegin(); |
| 15274 | auto SE = StackComponents.rend(); |
| 15275 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 15276 | |
| 15277 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 15278 | // At most one list item can be an array item derived from a given |
| 15279 | // variable in map clauses of the same construct. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15280 | if (CurrentRegionOnly && |
| 15281 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 15282 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 15283 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 15284 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 15285 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15286 | diag::err_omp_multiple_array_items_in_map_clause) |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15287 | << CI->getAssociatedExpression()->getSourceRange(); |
| 15288 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 15289 | diag::note_used_here) |
| 15290 | << SI->getAssociatedExpression()->getSourceRange(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15291 | return true; |
| 15292 | } |
| 15293 | |
| 15294 | // Do both expressions have the same kind? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15295 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 15296 | SI->getAssociatedExpression()->getStmtClass()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15297 | break; |
| 15298 | |
| 15299 | // Are we dealing with different variables/fields? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15300 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15301 | break; |
| 15302 | } |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 15303 | // Check if the extra components of the expressions in the enclosing |
| 15304 | // data environment are redundant for the current base declaration. |
| 15305 | // If they are, the maps completely overlap, which is legal. |
| 15306 | for (; SI != SE; ++SI) { |
| 15307 | QualType Type; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15308 | if (const auto *ASE = |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 15309 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 15310 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15311 | } else if (const auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 15312 | SI->getAssociatedExpression())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15313 | const Expr *E = OASE->getBase()->IgnoreParenImpCasts(); |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 15314 | Type = |
| 15315 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 15316 | } |
| 15317 | if (Type.isNull() || Type->isAnyPointerType() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15318 | checkArrayExpressionDoesNotReferToWholeSize( |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 15319 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 15320 | break; |
| 15321 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15322 | |
| 15323 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 15324 | // List items of map clauses in the same construct must not share |
| 15325 | // original storage. |
| 15326 | // |
| 15327 | // If the expressions are exactly the same or one is a subset of the |
| 15328 | // other, it means they are sharing storage. |
| 15329 | if (CI == CE && SI == SE) { |
| 15330 | if (CurrentRegionOnly) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15331 | if (CKind == OMPC_map) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15332 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15333 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 15334 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15335 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 15336 | << ERange; |
| 15337 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15338 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 15339 | << RE->getSourceRange(); |
| 15340 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15341 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15342 | // If we find the same expression in the enclosing data environment, |
| 15343 | // that is legal. |
| 15344 | IsEnclosedByDataEnvironmentExpr = true; |
| 15345 | return false; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15346 | } |
| 15347 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15348 | QualType DerivedType = |
| 15349 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 15350 | SourceLocation DerivedLoc = |
| 15351 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15352 | |
| 15353 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 15354 | // If the type of a list item is a reference to a type T then the type |
| 15355 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15356 | DerivedType = DerivedType.getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15357 | |
| 15358 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 15359 | // A variable for which the type is pointer and an array section |
| 15360 | // derived from that variable must not appear as list items of map |
| 15361 | // clauses of the same construct. |
| 15362 | // |
| 15363 | // Also, cover one of the cases in: |
| 15364 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 15365 | // If any part of the original storage of a list item has corresponding |
| 15366 | // storage in the device data environment, all of the original storage |
| 15367 | // must have corresponding storage in the device data environment. |
| 15368 | // |
| 15369 | if (DerivedType->isAnyPointerType()) { |
| 15370 | if (CI == CE || SI == SE) { |
| 15371 | SemaRef.Diag( |
| 15372 | DerivedLoc, |
| 15373 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 15374 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 15375 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 15376 | << RE->getSourceRange(); |
| 15377 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15378 | } |
| 15379 | if (CI->getAssociatedExpression()->getStmtClass() != |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 15380 | SI->getAssociatedExpression()->getStmtClass() || |
| 15381 | CI->getAssociatedDeclaration()->getCanonicalDecl() == |
| 15382 | SI->getAssociatedDeclaration()->getCanonicalDecl()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15383 | assert(CI != CE && SI != SE); |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 15384 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_dereferenced) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15385 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 15386 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 15387 | << RE->getSourceRange(); |
| 15388 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15389 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15390 | } |
| 15391 | |
| 15392 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 15393 | // List items of map clauses in the same construct must not share |
| 15394 | // original storage. |
| 15395 | // |
| 15396 | // An expression is a subset of the other. |
| 15397 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15398 | if (CKind == OMPC_map) { |
| Alexey Bataev | e82445f | 2018-09-20 13:54:02 +0000 | [diff] [blame] | 15399 | if (CI != CE || SI != SE) { |
| 15400 | // Allow constructs like this: map(s, s.ptr[0:1]), where s.ptr is |
| 15401 | // a pointer. |
| 15402 | auto Begin = |
| 15403 | CI != CE ? CurComponents.begin() : StackComponents.begin(); |
| 15404 | auto End = CI != CE ? CurComponents.end() : StackComponents.end(); |
| 15405 | auto It = Begin; |
| 15406 | while (It != End && !It->getAssociatedDeclaration()) |
| 15407 | std::advance(It, 1); |
| 15408 | assert(It != End && |
| 15409 | "Expected at least one component with the declaration."); |
| 15410 | if (It != Begin && It->getAssociatedDeclaration() |
| 15411 | ->getType() |
| 15412 | .getCanonicalType() |
| 15413 | ->isAnyPointerType()) { |
| 15414 | IsEnclosedByDataEnvironmentExpr = false; |
| 15415 | EnclosingExpr = nullptr; |
| 15416 | return false; |
| 15417 | } |
| 15418 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15419 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15420 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 15421 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15422 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 15423 | << ERange; |
| 15424 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15425 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 15426 | << RE->getSourceRange(); |
| 15427 | return true; |
| 15428 | } |
| 15429 | |
| 15430 | // The current expression uses the same base as other expression in the |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15431 | // data environment but does not contain it completely. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15432 | if (!CurrentRegionOnly && SI != SE) |
| 15433 | EnclosingExpr = RE; |
| 15434 | |
| 15435 | // The current expression is a subset of the expression in the data |
| 15436 | // environment. |
| 15437 | IsEnclosedByDataEnvironmentExpr |= |
| 15438 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 15439 | |
| 15440 | return false; |
| 15441 | }); |
| 15442 | |
| 15443 | if (CurrentRegionOnly) |
| 15444 | return FoundError; |
| 15445 | |
| 15446 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 15447 | // If any part of the original storage of a list item has corresponding |
| 15448 | // storage in the device data environment, all of the original storage must |
| 15449 | // have corresponding storage in the device data environment. |
| 15450 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 15451 | // If a list item is an element of a structure, and a different element of |
| 15452 | // the structure has a corresponding list item in the device data environment |
| 15453 | // prior to a task encountering the construct associated with the map clause, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15454 | // then the list item must also have a corresponding list item in the device |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15455 | // data environment prior to the task encountering the construct. |
| 15456 | // |
| 15457 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 15458 | SemaRef.Diag(ELoc, |
| 15459 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 15460 | << ERange; |
| 15461 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 15462 | << EnclosingExpr->getSourceRange(); |
| 15463 | return true; |
| 15464 | } |
| 15465 | |
| 15466 | return FoundError; |
| 15467 | } |
| 15468 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15469 | // Look up the user-defined mapper given the mapper name and mapped type, and |
| 15470 | // build a reference to it. |
| Benjamin Kramer | ba2ea93 | 2019-03-28 17:18:42 +0000 | [diff] [blame] | 15471 | static ExprResult buildUserDefinedMapperRef(Sema &SemaRef, Scope *S, |
| 15472 | CXXScopeSpec &MapperIdScopeSpec, |
| 15473 | const DeclarationNameInfo &MapperId, |
| 15474 | QualType Type, |
| 15475 | Expr *UnresolvedMapper) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15476 | if (MapperIdScopeSpec.isInvalid()) |
| 15477 | return ExprError(); |
| Michael Kruse | 945249b | 2019-09-26 22:53:01 +0000 | [diff] [blame] | 15478 | // Get the actual type for the array type. |
| 15479 | if (Type->isArrayType()) { |
| 15480 | assert(Type->getAsArrayTypeUnsafe() && "Expect to get a valid array type"); |
| 15481 | Type = Type->getAsArrayTypeUnsafe()->getElementType().getCanonicalType(); |
| 15482 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15483 | // Find all user-defined mappers with the given MapperId. |
| 15484 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 15485 | LookupResult Lookup(SemaRef, MapperId, Sema::LookupOMPMapperName); |
| 15486 | Lookup.suppressDiagnostics(); |
| 15487 | if (S) { |
| 15488 | while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec)) { |
| 15489 | NamedDecl *D = Lookup.getRepresentativeDecl(); |
| 15490 | while (S && !S->isDeclScope(D)) |
| 15491 | S = S->getParent(); |
| 15492 | if (S) |
| 15493 | S = S->getParent(); |
| 15494 | Lookups.emplace_back(); |
| 15495 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 15496 | Lookup.clear(); |
| 15497 | } |
| 15498 | } else if (auto *ULE = cast_or_null<UnresolvedLookupExpr>(UnresolvedMapper)) { |
| 15499 | // Extract the user-defined mappers with the given MapperId. |
| 15500 | Lookups.push_back(UnresolvedSet<8>()); |
| 15501 | for (NamedDecl *D : ULE->decls()) { |
| 15502 | auto *DMD = cast<OMPDeclareMapperDecl>(D); |
| 15503 | assert(DMD && "Expect valid OMPDeclareMapperDecl during instantiation."); |
| 15504 | Lookups.back().addDecl(DMD); |
| 15505 | } |
| 15506 | } |
| 15507 | // Defer the lookup for dependent types. The results will be passed through |
| 15508 | // UnresolvedMapper on instantiation. |
| 15509 | if (SemaRef.CurContext->isDependentContext() || Type->isDependentType() || |
| 15510 | Type->isInstantiationDependentType() || |
| 15511 | Type->containsUnexpandedParameterPack() || |
| 15512 | filterLookupForUDReductionAndMapper<bool>(Lookups, [](ValueDecl *D) { |
| 15513 | return !D->isInvalidDecl() && |
| 15514 | (D->getType()->isDependentType() || |
| 15515 | D->getType()->isInstantiationDependentType() || |
| 15516 | D->getType()->containsUnexpandedParameterPack()); |
| 15517 | })) { |
| 15518 | UnresolvedSet<8> URS; |
| 15519 | for (const UnresolvedSet<8> &Set : Lookups) { |
| 15520 | if (Set.empty()) |
| 15521 | continue; |
| 15522 | URS.append(Set.begin(), Set.end()); |
| 15523 | } |
| 15524 | return UnresolvedLookupExpr::Create( |
| 15525 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 15526 | MapperIdScopeSpec.getWithLocInContext(SemaRef.Context), MapperId, |
| 15527 | /*ADL=*/false, /*Overloaded=*/true, URS.begin(), URS.end()); |
| 15528 | } |
| Michael Kruse | 945249b | 2019-09-26 22:53:01 +0000 | [diff] [blame] | 15529 | SourceLocation Loc = MapperId.getLoc(); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15530 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 15531 | // The type must be of struct, union or class type in C and C++ |
| Michael Kruse | 945249b | 2019-09-26 22:53:01 +0000 | [diff] [blame] | 15532 | if (!Type->isStructureOrClassType() && !Type->isUnionType() && |
| 15533 | (MapperIdScopeSpec.isSet() || MapperId.getAsString() != "default")) { |
| 15534 | SemaRef.Diag(Loc, diag::err_omp_mapper_wrong_type); |
| 15535 | return ExprError(); |
| 15536 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15537 | // Perform argument dependent lookup. |
| 15538 | if (SemaRef.getLangOpts().CPlusPlus && !MapperIdScopeSpec.isSet()) |
| 15539 | argumentDependentLookup(SemaRef, MapperId, Loc, Type, Lookups); |
| 15540 | // Return the first user-defined mapper with the desired type. |
| 15541 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 15542 | Lookups, [&SemaRef, Type](ValueDecl *D) -> ValueDecl * { |
| 15543 | if (!D->isInvalidDecl() && |
| 15544 | SemaRef.Context.hasSameType(D->getType(), Type)) |
| 15545 | return D; |
| 15546 | return nullptr; |
| 15547 | })) |
| 15548 | return SemaRef.BuildDeclRefExpr(VD, Type, VK_LValue, Loc); |
| 15549 | // Find the first user-defined mapper with a type derived from the desired |
| 15550 | // type. |
| 15551 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 15552 | Lookups, [&SemaRef, Type, Loc](ValueDecl *D) -> ValueDecl * { |
| 15553 | if (!D->isInvalidDecl() && |
| 15554 | SemaRef.IsDerivedFrom(Loc, Type, D->getType()) && |
| 15555 | !Type.isMoreQualifiedThan(D->getType())) |
| 15556 | return D; |
| 15557 | return nullptr; |
| 15558 | })) { |
| 15559 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 15560 | /*DetectVirtual=*/false); |
| 15561 | if (SemaRef.IsDerivedFrom(Loc, Type, VD->getType(), Paths)) { |
| 15562 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 15563 | VD->getType().getUnqualifiedType()))) { |
| 15564 | if (SemaRef.CheckBaseClassAccess( |
| 15565 | Loc, VD->getType(), Type, Paths.front(), |
| 15566 | /*DiagID=*/0) != Sema::AR_inaccessible) { |
| 15567 | return SemaRef.BuildDeclRefExpr(VD, Type, VK_LValue, Loc); |
| 15568 | } |
| 15569 | } |
| 15570 | } |
| 15571 | } |
| 15572 | // Report error if a mapper is specified, but cannot be found. |
| 15573 | if (MapperIdScopeSpec.isSet() || MapperId.getAsString() != "default") { |
| 15574 | SemaRef.Diag(Loc, diag::err_omp_invalid_mapper) |
| 15575 | << Type << MapperId.getName(); |
| 15576 | return ExprError(); |
| 15577 | } |
| 15578 | return ExprEmpty(); |
| 15579 | } |
| 15580 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15581 | namespace { |
| 15582 | // Utility struct that gathers all the related lists associated with a mappable |
| 15583 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15584 | struct MappableVarListInfo { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15585 | // The list of expressions. |
| 15586 | ArrayRef<Expr *> VarList; |
| 15587 | // The list of processed expressions. |
| 15588 | SmallVector<Expr *, 16> ProcessedVarList; |
| 15589 | // The mappble components for each expression. |
| 15590 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 15591 | // The base declaration of the variable. |
| 15592 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15593 | // The reference to the user-defined mapper associated with every expression. |
| 15594 | SmallVector<Expr *, 16> UDMapperList; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15595 | |
| 15596 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 15597 | // We have a list of components and base declarations for each entry in the |
| 15598 | // variable list. |
| 15599 | VarComponents.reserve(VarList.size()); |
| 15600 | VarBaseDeclarations.reserve(VarList.size()); |
| 15601 | } |
| 15602 | }; |
| 15603 | } |
| 15604 | |
| 15605 | // Check the validity of the provided variable list for the provided clause kind |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15606 | // \a CKind. In the check process the valid expressions, mappable expression |
| 15607 | // components, variables, and user-defined mappers are extracted and used to |
| 15608 | // fill \a ProcessedVarList, \a VarComponents, \a VarBaseDeclarations, and \a |
| 15609 | // UDMapperList in MVLI. \a MapType, \a IsMapTypeImplicit, \a MapperIdScopeSpec, |
| 15610 | // and \a MapperId are expected to be valid if the clause kind is 'map'. |
| 15611 | static void checkMappableExpressionList( |
| 15612 | Sema &SemaRef, DSAStackTy *DSAS, OpenMPClauseKind CKind, |
| 15613 | MappableVarListInfo &MVLI, SourceLocation StartLoc, |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15614 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo MapperId, |
| 15615 | ArrayRef<Expr *> UnresolvedMappers, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15616 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15617 | bool IsMapTypeImplicit = false) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 15618 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 15619 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15620 | "Unexpected clause kind with mappable expressions!"); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15621 | |
| 15622 | // If the identifier of user-defined mapper is not specified, it is "default". |
| 15623 | // We do not change the actual name in this clause to distinguish whether a |
| 15624 | // mapper is specified explicitly, i.e., it is not explicitly specified when |
| 15625 | // MapperId.getName() is empty. |
| 15626 | if (!MapperId.getName() || MapperId.getName().isEmpty()) { |
| 15627 | auto &DeclNames = SemaRef.getASTContext().DeclarationNames; |
| 15628 | MapperId.setName(DeclNames.getIdentifier( |
| 15629 | &SemaRef.getASTContext().Idents.get("default"))); |
| 15630 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15631 | |
| 15632 | // Iterators to find the current unresolved mapper expression. |
| 15633 | auto UMIt = UnresolvedMappers.begin(), UMEnd = UnresolvedMappers.end(); |
| 15634 | bool UpdateUMIt = false; |
| 15635 | Expr *UnresolvedMapper = nullptr; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15636 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15637 | // Keep track of the mappable components and base declarations in this clause. |
| 15638 | // Each entry in the list is going to have a list of components associated. We |
| 15639 | // record each set of the components so that we can build the clause later on. |
| 15640 | // In the end we should have the same amount of declarations and component |
| 15641 | // lists. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15642 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15643 | for (Expr *RE : MVLI.VarList) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 15644 | assert(RE && "Null expr in omp to/from/map clause"); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15645 | SourceLocation ELoc = RE->getExprLoc(); |
| 15646 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15647 | // Find the current unresolved mapper expression. |
| 15648 | if (UpdateUMIt && UMIt != UMEnd) { |
| 15649 | UMIt++; |
| 15650 | assert( |
| 15651 | UMIt != UMEnd && |
| 15652 | "Expect the size of UnresolvedMappers to match with that of VarList"); |
| 15653 | } |
| 15654 | UpdateUMIt = true; |
| 15655 | if (UMIt != UMEnd) |
| 15656 | UnresolvedMapper = *UMIt; |
| 15657 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15658 | const Expr *VE = RE->IgnoreParenLValueCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15659 | |
| 15660 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 15661 | VE->isInstantiationDependent() || |
| 15662 | VE->containsUnexpandedParameterPack()) { |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 15663 | // Try to find the associated user-defined mapper. |
| 15664 | ExprResult ER = buildUserDefinedMapperRef( |
| 15665 | SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId, |
| 15666 | VE->getType().getCanonicalType(), UnresolvedMapper); |
| 15667 | if (ER.isInvalid()) |
| 15668 | continue; |
| 15669 | MVLI.UDMapperList.push_back(ER.get()); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15670 | // We can only analyze this information once the missing information is |
| 15671 | // resolved. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15672 | MVLI.ProcessedVarList.push_back(RE); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15673 | continue; |
| 15674 | } |
| 15675 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15676 | Expr *SimpleExpr = RE->IgnoreParenCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15677 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15678 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15679 | SemaRef.Diag(ELoc, |
| 15680 | diag::err_omp_expected_named_var_member_or_array_expression) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15681 | << RE->getSourceRange(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15682 | continue; |
| 15683 | } |
| 15684 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15685 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 15686 | ValueDecl *CurDeclaration = nullptr; |
| 15687 | |
| 15688 | // Obtain the array or member expression bases if required. Also, fill the |
| 15689 | // components array with all the components identified in the process. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15690 | const Expr *BE = checkMapClauseExpressionBase( |
| 15691 | SemaRef, SimpleExpr, CurComponents, CKind, /*NoDiagnose=*/false); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15692 | if (!BE) |
| 15693 | continue; |
| 15694 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15695 | assert(!CurComponents.empty() && |
| 15696 | "Invalid mappable expression information."); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15697 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 15698 | if (const auto *TE = dyn_cast<CXXThisExpr>(BE)) { |
| 15699 | // Add store "this" pointer to class in DSAStackTy for future checking |
| 15700 | DSAS->addMappedClassesQualTypes(TE->getType()); |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 15701 | // Try to find the associated user-defined mapper. |
| 15702 | ExprResult ER = buildUserDefinedMapperRef( |
| 15703 | SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId, |
| 15704 | VE->getType().getCanonicalType(), UnresolvedMapper); |
| 15705 | if (ER.isInvalid()) |
| 15706 | continue; |
| 15707 | MVLI.UDMapperList.push_back(ER.get()); |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 15708 | // Skip restriction checking for variable or field declarations |
| 15709 | MVLI.ProcessedVarList.push_back(RE); |
| 15710 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 15711 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 15712 | CurComponents.end()); |
| 15713 | MVLI.VarBaseDeclarations.push_back(nullptr); |
| 15714 | continue; |
| 15715 | } |
| 15716 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15717 | // For the following checks, we rely on the base declaration which is |
| 15718 | // expected to be associated with the last component. The declaration is |
| 15719 | // expected to be a variable or a field (if 'this' is being mapped). |
| 15720 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 15721 | assert(CurDeclaration && "Null decl on map clause."); |
| 15722 | assert( |
| 15723 | CurDeclaration->isCanonicalDecl() && |
| 15724 | "Expecting components to have associated only canonical declarations."); |
| 15725 | |
| 15726 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15727 | const auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15728 | |
| 15729 | assert((VD || FD) && "Only variables or fields are expected here!"); |
| NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 15730 | (void)FD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15731 | |
| 15732 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15733 | // threadprivate variables cannot appear in a map clause. |
| 15734 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 15735 | // threadprivate variables cannot appear in a from clause. |
| 15736 | if (VD && DSAS->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15737 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15738 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 15739 | << getOpenMPClauseName(CKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15740 | reportOriginalDsa(SemaRef, DSAS, VD, DVar); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15741 | continue; |
| 15742 | } |
| 15743 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15744 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 15745 | // A list item cannot appear in both a map clause and a data-sharing |
| 15746 | // attribute clause on the same construct. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15747 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15748 | // Check conflicts with other map clause expressions. We check the conflicts |
| 15749 | // with the current construct separately from the enclosing data |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15750 | // environment, because the restrictions are different. We only have to |
| 15751 | // check conflicts across regions for the map clauses. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15752 | if (checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15753 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15754 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15755 | if (CKind == OMPC_map && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15756 | checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15757 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15758 | break; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15759 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15760 | // OpenMP 4.5 [2.10.5, target update Construct] |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15761 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 15762 | // If the type of a list item is a reference to a type T then the type will |
| 15763 | // be considered to be T for all purposes of this clause. |
| Alexey Bataev | 354df2e | 2018-05-02 18:44:10 +0000 | [diff] [blame] | 15764 | auto I = llvm::find_if( |
| 15765 | CurComponents, |
| 15766 | [](const OMPClauseMappableExprCommon::MappableComponent &MC) { |
| 15767 | return MC.getAssociatedDeclaration(); |
| 15768 | }); |
| 15769 | assert(I != CurComponents.end() && "Null decl on map clause."); |
| 15770 | QualType Type = |
| 15771 | I->getAssociatedDeclaration()->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15772 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15773 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 15774 | // A list item in a to or from clause must have a mappable type. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15775 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15776 | // A list item must have a mappable type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15777 | if (!checkTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15778 | DSAS, Type)) |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15779 | continue; |
| 15780 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15781 | if (CKind == OMPC_map) { |
| 15782 | // target enter data |
| 15783 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 15784 | // A map-type must be specified in all map clauses and must be either |
| 15785 | // to or alloc. |
| 15786 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 15787 | if (DKind == OMPD_target_enter_data && |
| 15788 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 15789 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 15790 | << (IsMapTypeImplicit ? 1 : 0) |
| 15791 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 15792 | << getOpenMPDirectiveName(DKind); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 15793 | continue; |
| 15794 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15795 | |
| 15796 | // target exit_data |
| 15797 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 15798 | // A map-type must be specified in all map clauses and must be either |
| 15799 | // from, release, or delete. |
| 15800 | if (DKind == OMPD_target_exit_data && |
| 15801 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 15802 | MapType == OMPC_MAP_delete)) { |
| 15803 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 15804 | << (IsMapTypeImplicit ? 1 : 0) |
| 15805 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 15806 | << getOpenMPDirectiveName(DKind); |
| 15807 | continue; |
| 15808 | } |
| 15809 | |
| 15810 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 15811 | // A list item cannot appear in both a map clause and a data-sharing |
| 15812 | // attribute clause on the same construct |
| Joel E. Denny | 7d5bc55 | 2019-08-22 03:34:30 +0000 | [diff] [blame] | 15813 | // |
| 15814 | // OpenMP 5.0 [2.19.7.1, Restrictions, p.7] |
| 15815 | // A list item cannot appear in both a map clause and a data-sharing |
| 15816 | // attribute clause on the same construct unless the construct is a |
| 15817 | // combined construct. |
| 15818 | if (VD && ((SemaRef.LangOpts.OpenMP <= 45 && |
| 15819 | isOpenMPTargetExecutionDirective(DKind)) || |
| 15820 | DKind == OMPD_target)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15821 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15822 | if (isOpenMPPrivate(DVar.CKind)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 15823 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15824 | << getOpenMPClauseName(DVar.CKind) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 15825 | << getOpenMPClauseName(OMPC_map) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15826 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15827 | reportOriginalDsa(SemaRef, DSAS, CurDeclaration, DVar); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15828 | continue; |
| 15829 | } |
| 15830 | } |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15831 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15832 | |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15833 | // Try to find the associated user-defined mapper. |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 15834 | ExprResult ER = buildUserDefinedMapperRef( |
| 15835 | SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId, |
| 15836 | Type.getCanonicalType(), UnresolvedMapper); |
| 15837 | if (ER.isInvalid()) |
| 15838 | continue; |
| 15839 | MVLI.UDMapperList.push_back(ER.get()); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 15840 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15841 | // Save the current expression. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15842 | MVLI.ProcessedVarList.push_back(RE); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15843 | |
| 15844 | // Store the components in the stack so that they can be used to check |
| 15845 | // against other clauses later on. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 15846 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 15847 | /*WhereFoundClauseKind=*/OMPC_map); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 15848 | |
| 15849 | // Save the components and declaration to create the clause. For purposes of |
| 15850 | // the clause creation, any component list that has has base 'this' uses |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 15851 | // null as base declaration. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15852 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 15853 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 15854 | CurComponents.end()); |
| 15855 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 15856 | : CurDeclaration); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15857 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 15858 | } |
| 15859 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15860 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 15861 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 15862 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 15863 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
| 15864 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, |
| 15865 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 15866 | const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
| 15867 | OpenMPMapModifierKind Modifiers[] = {OMPC_MAP_MODIFIER_unknown, |
| 15868 | OMPC_MAP_MODIFIER_unknown, |
| 15869 | OMPC_MAP_MODIFIER_unknown}; |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 15870 | SourceLocation ModifiersLoc[OMPMapClause::NumberOfModifiers]; |
| 15871 | |
| 15872 | // Process map-type-modifiers, flag errors for duplicate modifiers. |
| 15873 | unsigned Count = 0; |
| 15874 | for (unsigned I = 0, E = MapTypeModifiers.size(); I < E; ++I) { |
| 15875 | if (MapTypeModifiers[I] != OMPC_MAP_MODIFIER_unknown && |
| 15876 | llvm::find(Modifiers, MapTypeModifiers[I]) != std::end(Modifiers)) { |
| 15877 | Diag(MapTypeModifiersLoc[I], diag::err_omp_duplicate_map_type_modifier); |
| 15878 | continue; |
| 15879 | } |
| 15880 | assert(Count < OMPMapClause::NumberOfModifiers && |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 15881 | "Modifiers exceed the allowed number of map type modifiers"); |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 15882 | Modifiers[Count] = MapTypeModifiers[I]; |
| 15883 | ModifiersLoc[Count] = MapTypeModifiersLoc[I]; |
| 15884 | ++Count; |
| 15885 | } |
| 15886 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15887 | MappableVarListInfo MVLI(VarList); |
| 15888 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, Locs.StartLoc, |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 15889 | MapperIdScopeSpec, MapperId, UnresolvedMappers, |
| 15890 | MapType, IsMapTypeImplicit); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15891 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 15892 | // We need to produce a map clause even if we don't have variables so that |
| 15893 | // other diagnostics related with non-existing map clauses are accurate. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 15894 | return OMPMapClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 15895 | MVLI.VarBaseDeclarations, MVLI.VarComponents, |
| 15896 | MVLI.UDMapperList, Modifiers, ModifiersLoc, |
| 15897 | MapperIdScopeSpec.getWithLocInContext(Context), |
| 15898 | MapperId, MapType, IsMapTypeImplicit, MapLoc); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 15899 | } |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 15900 | |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15901 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 15902 | TypeResult ParsedType) { |
| 15903 | assert(ParsedType.isUsable()); |
| 15904 | |
| 15905 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 15906 | if (ReductionType.isNull()) |
| 15907 | return QualType(); |
| 15908 | |
| 15909 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 15910 | // A type name in a declare reduction directive cannot be a function type, an |
| 15911 | // array type, a reference type, or a type qualified with const, volatile or |
| 15912 | // restrict. |
| 15913 | if (ReductionType.hasQualifiers()) { |
| 15914 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 15915 | return QualType(); |
| 15916 | } |
| 15917 | |
| 15918 | if (ReductionType->isFunctionType()) { |
| 15919 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 15920 | return QualType(); |
| 15921 | } |
| 15922 | if (ReductionType->isReferenceType()) { |
| 15923 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 15924 | return QualType(); |
| 15925 | } |
| 15926 | if (ReductionType->isArrayType()) { |
| 15927 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 15928 | return QualType(); |
| 15929 | } |
| 15930 | return ReductionType; |
| 15931 | } |
| 15932 | |
| 15933 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 15934 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 15935 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 15936 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 15937 | SmallVector<Decl *, 8> Decls; |
| 15938 | Decls.reserve(ReductionTypes.size()); |
| 15939 | |
| 15940 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| Richard Smith | becb92d | 2017-10-10 22:33:17 +0000 | [diff] [blame] | 15941 | forRedeclarationInCurContext()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15942 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 15943 | // A reduction-identifier may not be re-declared in the current scope for the |
| 15944 | // same type or for a type that is compatible according to the base language |
| 15945 | // rules. |
| 15946 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 15947 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 15948 | bool InCompoundScope = true; |
| 15949 | if (S != nullptr) { |
| 15950 | // Find previous declaration with the same name not referenced in other |
| 15951 | // declarations. |
| 15952 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 15953 | InCompoundScope = |
| 15954 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 15955 | LookupName(Lookup, S); |
| 15956 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 15957 | /*AllowInlineNamespace=*/false); |
| 15958 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15959 | LookupResult::Filter Filter = Lookup.makeFilter(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15960 | while (Filter.hasNext()) { |
| 15961 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 15962 | if (InCompoundScope) { |
| 15963 | auto I = UsedAsPrevious.find(PrevDecl); |
| 15964 | if (I == UsedAsPrevious.end()) |
| 15965 | UsedAsPrevious[PrevDecl] = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15966 | if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope()) |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15967 | UsedAsPrevious[D] = true; |
| 15968 | } |
| 15969 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 15970 | PrevDecl->getLocation(); |
| 15971 | } |
| 15972 | Filter.done(); |
| 15973 | if (InCompoundScope) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15974 | for (const auto &PrevData : UsedAsPrevious) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15975 | if (!PrevData.second) { |
| 15976 | PrevDRD = PrevData.first; |
| 15977 | break; |
| 15978 | } |
| 15979 | } |
| 15980 | } |
| 15981 | } else if (PrevDeclInScope != nullptr) { |
| 15982 | auto *PrevDRDInScope = PrevDRD = |
| 15983 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 15984 | do { |
| 15985 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 15986 | PrevDRDInScope->getLocation(); |
| 15987 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 15988 | } while (PrevDRDInScope != nullptr); |
| 15989 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 15990 | for (const auto &TyData : ReductionTypes) { |
| 15991 | const auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 15992 | bool Invalid = false; |
| 15993 | if (I != PreviousRedeclTypes.end()) { |
| 15994 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 15995 | << TyData.first; |
| 15996 | Diag(I->second, diag::note_previous_definition); |
| 15997 | Invalid = true; |
| 15998 | } |
| 15999 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 16000 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 16001 | Name, TyData.first, PrevDRD); |
| 16002 | DC->addDecl(DRD); |
| 16003 | DRD->setAccess(AS); |
| 16004 | Decls.push_back(DRD); |
| 16005 | if (Invalid) |
| 16006 | DRD->setInvalidDecl(); |
| 16007 | else |
| 16008 | PrevDRD = DRD; |
| 16009 | } |
| 16010 | |
| 16011 | return DeclGroupPtrTy::make( |
| 16012 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 16013 | } |
| 16014 | |
| 16015 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 16016 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 16017 | |
| 16018 | // Enter new function scope. |
| 16019 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 16020 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16021 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 16022 | |
| 16023 | if (S != nullptr) |
| 16024 | PushDeclContext(S, DRD); |
| 16025 | else |
| 16026 | CurContext = DRD; |
| 16027 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 16028 | PushExpressionEvaluationContext( |
| 16029 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16030 | |
| 16031 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 16032 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 16033 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 16034 | // uses semantics of argument handles by value, but it should be passed by |
| 16035 | // reference. C lang does not support references, so pass all parameters as |
| 16036 | // pointers. |
| 16037 | // Create 'T omp_in;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16038 | VarDecl *OmpInParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 16039 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16040 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 16041 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 16042 | // uses semantics of argument handles by value, but it should be passed by |
| 16043 | // reference. C lang does not support references, so pass all parameters as |
| 16044 | // pointers. |
| 16045 | // Create 'T omp_out;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16046 | VarDecl *OmpOutParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16047 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 16048 | if (S != nullptr) { |
| 16049 | PushOnScopeChains(OmpInParm, S); |
| 16050 | PushOnScopeChains(OmpOutParm, S); |
| 16051 | } else { |
| 16052 | DRD->addDecl(OmpInParm); |
| 16053 | DRD->addDecl(OmpOutParm); |
| 16054 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 16055 | Expr *InE = |
| 16056 | ::buildDeclRefExpr(*this, OmpInParm, ReductionType, D->getLocation()); |
| 16057 | Expr *OutE = |
| 16058 | ::buildDeclRefExpr(*this, OmpOutParm, ReductionType, D->getLocation()); |
| 16059 | DRD->setCombinerData(InE, OutE); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16060 | } |
| 16061 | |
| 16062 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 16063 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 16064 | DiscardCleanupsInEvaluationContext(); |
| 16065 | PopExpressionEvaluationContext(); |
| 16066 | |
| 16067 | PopDeclContext(); |
| 16068 | PopFunctionScopeInfo(); |
| 16069 | |
| 16070 | if (Combiner != nullptr) |
| 16071 | DRD->setCombiner(Combiner); |
| 16072 | else |
| 16073 | DRD->setInvalidDecl(); |
| 16074 | } |
| 16075 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 16076 | VarDecl *Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16077 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 16078 | |
| 16079 | // Enter new function scope. |
| 16080 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 16081 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16082 | |
| 16083 | if (S != nullptr) |
| 16084 | PushDeclContext(S, DRD); |
| 16085 | else |
| 16086 | CurContext = DRD; |
| 16087 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 16088 | PushExpressionEvaluationContext( |
| 16089 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16090 | |
| 16091 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16092 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 16093 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 16094 | // uses semantics of argument handles by value, but it should be passed by |
| 16095 | // reference. C lang does not support references, so pass all parameters as |
| 16096 | // pointers. |
| 16097 | // Create 'T omp_priv;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16098 | VarDecl *OmpPrivParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16099 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 16100 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 16101 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 16102 | // uses semantics of argument handles by value, but it should be passed by |
| 16103 | // reference. C lang does not support references, so pass all parameters as |
| 16104 | // pointers. |
| 16105 | // Create 'T omp_orig;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16106 | VarDecl *OmpOrigParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 16107 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16108 | if (S != nullptr) { |
| 16109 | PushOnScopeChains(OmpPrivParm, S); |
| 16110 | PushOnScopeChains(OmpOrigParm, S); |
| 16111 | } else { |
| 16112 | DRD->addDecl(OmpPrivParm); |
| 16113 | DRD->addDecl(OmpOrigParm); |
| 16114 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 16115 | Expr *OrigE = |
| 16116 | ::buildDeclRefExpr(*this, OmpOrigParm, ReductionType, D->getLocation()); |
| 16117 | Expr *PrivE = |
| 16118 | ::buildDeclRefExpr(*this, OmpPrivParm, ReductionType, D->getLocation()); |
| 16119 | DRD->setInitializerData(OrigE, PrivE); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 16120 | return OmpPrivParm; |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16121 | } |
| 16122 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 16123 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
| 16124 | VarDecl *OmpPrivParm) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16125 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 16126 | DiscardCleanupsInEvaluationContext(); |
| 16127 | PopExpressionEvaluationContext(); |
| 16128 | |
| 16129 | PopDeclContext(); |
| 16130 | PopFunctionScopeInfo(); |
| 16131 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 16132 | if (Initializer != nullptr) { |
| 16133 | DRD->setInitializer(Initializer, OMPDeclareReductionDecl::CallInit); |
| 16134 | } else if (OmpPrivParm->hasInit()) { |
| 16135 | DRD->setInitializer(OmpPrivParm->getInit(), |
| 16136 | OmpPrivParm->isDirectInit() |
| 16137 | ? OMPDeclareReductionDecl::DirectInit |
| 16138 | : OMPDeclareReductionDecl::CopyInit); |
| 16139 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16140 | DRD->setInvalidDecl(); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 16141 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16142 | } |
| 16143 | |
| 16144 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 16145 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16146 | for (Decl *D : DeclReductions.get()) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16147 | if (IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16148 | if (S) |
| 16149 | PushOnScopeChains(cast<OMPDeclareReductionDecl>(D), S, |
| 16150 | /*AddToContext=*/false); |
| 16151 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16152 | D->setInvalidDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16153 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 16154 | } |
| 16155 | return DeclReductions; |
| 16156 | } |
| 16157 | |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 16158 | TypeResult Sema::ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D) { |
| 16159 | TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); |
| 16160 | QualType T = TInfo->getType(); |
| 16161 | if (D.isInvalidType()) |
| 16162 | return true; |
| 16163 | |
| 16164 | if (getLangOpts().CPlusPlus) { |
| 16165 | // Check that there are no default arguments (C++ only). |
| 16166 | CheckExtraCXXDefaultArguments(D); |
| 16167 | } |
| 16168 | |
| 16169 | return CreateParsedType(T, TInfo); |
| 16170 | } |
| 16171 | |
| 16172 | QualType Sema::ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
| 16173 | TypeResult ParsedType) { |
| 16174 | assert(ParsedType.isUsable() && "Expect usable parsed mapper type"); |
| 16175 | |
| 16176 | QualType MapperType = GetTypeFromParser(ParsedType.get()); |
| 16177 | assert(!MapperType.isNull() && "Expect valid mapper type"); |
| 16178 | |
| 16179 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 16180 | // The type must be of struct, union or class type in C and C++ |
| 16181 | if (!MapperType->isStructureOrClassType() && !MapperType->isUnionType()) { |
| 16182 | Diag(TyLoc, diag::err_omp_mapper_wrong_type); |
| 16183 | return QualType(); |
| 16184 | } |
| 16185 | return MapperType; |
| 16186 | } |
| 16187 | |
| 16188 | OMPDeclareMapperDecl *Sema::ActOnOpenMPDeclareMapperDirectiveStart( |
| 16189 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
| 16190 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
| 16191 | Decl *PrevDeclInScope) { |
| 16192 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPMapperName, |
| 16193 | forRedeclarationInCurContext()); |
| 16194 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 16195 | // A mapper-identifier may not be redeclared in the current scope for the |
| 16196 | // same type or for a type that is compatible according to the base language |
| 16197 | // rules. |
| 16198 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 16199 | OMPDeclareMapperDecl *PrevDMD = nullptr; |
| 16200 | bool InCompoundScope = true; |
| 16201 | if (S != nullptr) { |
| 16202 | // Find previous declaration with the same name not referenced in other |
| 16203 | // declarations. |
| 16204 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 16205 | InCompoundScope = |
| 16206 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 16207 | LookupName(Lookup, S); |
| 16208 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 16209 | /*AllowInlineNamespace=*/false); |
| 16210 | llvm::DenseMap<OMPDeclareMapperDecl *, bool> UsedAsPrevious; |
| 16211 | LookupResult::Filter Filter = Lookup.makeFilter(); |
| 16212 | while (Filter.hasNext()) { |
| 16213 | auto *PrevDecl = cast<OMPDeclareMapperDecl>(Filter.next()); |
| 16214 | if (InCompoundScope) { |
| 16215 | auto I = UsedAsPrevious.find(PrevDecl); |
| 16216 | if (I == UsedAsPrevious.end()) |
| 16217 | UsedAsPrevious[PrevDecl] = false; |
| 16218 | if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope()) |
| 16219 | UsedAsPrevious[D] = true; |
| 16220 | } |
| 16221 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 16222 | PrevDecl->getLocation(); |
| 16223 | } |
| 16224 | Filter.done(); |
| 16225 | if (InCompoundScope) { |
| 16226 | for (const auto &PrevData : UsedAsPrevious) { |
| 16227 | if (!PrevData.second) { |
| 16228 | PrevDMD = PrevData.first; |
| 16229 | break; |
| 16230 | } |
| 16231 | } |
| 16232 | } |
| 16233 | } else if (PrevDeclInScope) { |
| 16234 | auto *PrevDMDInScope = PrevDMD = |
| 16235 | cast<OMPDeclareMapperDecl>(PrevDeclInScope); |
| 16236 | do { |
| 16237 | PreviousRedeclTypes[PrevDMDInScope->getType().getCanonicalType()] = |
| 16238 | PrevDMDInScope->getLocation(); |
| 16239 | PrevDMDInScope = PrevDMDInScope->getPrevDeclInScope(); |
| 16240 | } while (PrevDMDInScope != nullptr); |
| 16241 | } |
| 16242 | const auto I = PreviousRedeclTypes.find(MapperType.getCanonicalType()); |
| 16243 | bool Invalid = false; |
| 16244 | if (I != PreviousRedeclTypes.end()) { |
| 16245 | Diag(StartLoc, diag::err_omp_declare_mapper_redefinition) |
| 16246 | << MapperType << Name; |
| 16247 | Diag(I->second, diag::note_previous_definition); |
| 16248 | Invalid = true; |
| 16249 | } |
| 16250 | auto *DMD = OMPDeclareMapperDecl::Create(Context, DC, StartLoc, Name, |
| 16251 | MapperType, VN, PrevDMD); |
| 16252 | DC->addDecl(DMD); |
| 16253 | DMD->setAccess(AS); |
| 16254 | if (Invalid) |
| 16255 | DMD->setInvalidDecl(); |
| 16256 | |
| 16257 | // Enter new function scope. |
| 16258 | PushFunctionScope(); |
| 16259 | setFunctionHasBranchProtectedScope(); |
| 16260 | |
| 16261 | CurContext = DMD; |
| 16262 | |
| 16263 | return DMD; |
| 16264 | } |
| 16265 | |
| 16266 | void Sema::ActOnOpenMPDeclareMapperDirectiveVarDecl(OMPDeclareMapperDecl *DMD, |
| 16267 | Scope *S, |
| 16268 | QualType MapperType, |
| 16269 | SourceLocation StartLoc, |
| 16270 | DeclarationName VN) { |
| 16271 | VarDecl *VD = buildVarDecl(*this, StartLoc, MapperType, VN.getAsString()); |
| 16272 | if (S) |
| 16273 | PushOnScopeChains(VD, S); |
| 16274 | else |
| 16275 | DMD->addDecl(VD); |
| 16276 | Expr *MapperVarRefExpr = buildDeclRefExpr(*this, VD, MapperType, StartLoc); |
| 16277 | DMD->setMapperVarRef(MapperVarRefExpr); |
| 16278 | } |
| 16279 | |
| 16280 | Sema::DeclGroupPtrTy |
| 16281 | Sema::ActOnOpenMPDeclareMapperDirectiveEnd(OMPDeclareMapperDecl *D, Scope *S, |
| 16282 | ArrayRef<OMPClause *> ClauseList) { |
| 16283 | PopDeclContext(); |
| 16284 | PopFunctionScopeInfo(); |
| 16285 | |
| 16286 | if (D) { |
| 16287 | if (S) |
| 16288 | PushOnScopeChains(D, S, /*AddToContext=*/false); |
| 16289 | D->CreateClauses(Context, ClauseList); |
| 16290 | } |
| 16291 | |
| 16292 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 16293 | } |
| 16294 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 16295 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 16296 | SourceLocation StartLoc, |
| 16297 | SourceLocation LParenLoc, |
| 16298 | SourceLocation EndLoc) { |
| 16299 | Expr *ValExpr = NumTeams; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 16300 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 16301 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16302 | // OpenMP [teams Constrcut, Restrictions] |
| 16303 | // The num_teams expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16304 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16305 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16306 | return nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 16307 | |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 16308 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 16309 | OpenMPDirectiveKind CaptureRegion = |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 16310 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams, LangOpts.OpenMP); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 16311 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 16312 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16313 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 16314 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 16315 | HelperValStmt = buildPreInits(Context, Captures); |
| 16316 | } |
| 16317 | |
| 16318 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 16319 | StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 16320 | } |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16321 | |
| 16322 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 16323 | SourceLocation StartLoc, |
| 16324 | SourceLocation LParenLoc, |
| 16325 | SourceLocation EndLoc) { |
| 16326 | Expr *ValExpr = ThreadLimit; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 16327 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16328 | |
| 16329 | // OpenMP [teams Constrcut, Restrictions] |
| 16330 | // The thread_limit expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16331 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16332 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16333 | return nullptr; |
| 16334 | |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 16335 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 16336 | OpenMPDirectiveKind CaptureRegion = getOpenMPCaptureRegionForClause( |
| 16337 | DKind, OMPC_thread_limit, LangOpts.OpenMP); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 16338 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 16339 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16340 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 16341 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 16342 | HelperValStmt = buildPreInits(Context, Captures); |
| 16343 | } |
| 16344 | |
| 16345 | return new (Context) OMPThreadLimitClause( |
| 16346 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 16347 | } |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16348 | |
| 16349 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 16350 | SourceLocation StartLoc, |
| 16351 | SourceLocation LParenLoc, |
| 16352 | SourceLocation EndLoc) { |
| 16353 | Expr *ValExpr = Priority; |
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 16354 | Stmt *HelperValStmt = nullptr; |
| 16355 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16356 | |
| 16357 | // OpenMP [2.9.1, task Constrcut] |
| 16358 | // The priority-value is a non-negative numerical scalar expression. |
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 16359 | if (!isNonNegativeIntegerValue( |
| 16360 | ValExpr, *this, OMPC_priority, |
| 16361 | /*StrictlyPositive=*/false, /*BuildCapture=*/true, |
| 16362 | DSAStack->getCurrentDirective(), &CaptureRegion, &HelperValStmt)) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16363 | return nullptr; |
| 16364 | |
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 16365 | return new (Context) OMPPriorityClause(ValExpr, HelperValStmt, CaptureRegion, |
| 16366 | StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 16367 | } |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 16368 | |
| 16369 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 16370 | SourceLocation StartLoc, |
| 16371 | SourceLocation LParenLoc, |
| 16372 | SourceLocation EndLoc) { |
| 16373 | Expr *ValExpr = Grainsize; |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 16374 | Stmt *HelperValStmt = nullptr; |
| 16375 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 16376 | |
| 16377 | // OpenMP [2.9.2, taskloop Constrcut] |
| 16378 | // The parameter of the grainsize clause must be a positive integer |
| 16379 | // expression. |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 16380 | if (!isNonNegativeIntegerValue( |
| 16381 | ValExpr, *this, OMPC_grainsize, |
| 16382 | /*StrictlyPositive=*/true, /*BuildCapture=*/true, |
| 16383 | DSAStack->getCurrentDirective(), &CaptureRegion, &HelperValStmt)) |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 16384 | return nullptr; |
| 16385 | |
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 16386 | return new (Context) OMPGrainsizeClause(ValExpr, HelperValStmt, CaptureRegion, |
| 16387 | StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 16388 | } |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 16389 | |
| 16390 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 16391 | SourceLocation StartLoc, |
| 16392 | SourceLocation LParenLoc, |
| 16393 | SourceLocation EndLoc) { |
| 16394 | Expr *ValExpr = NumTasks; |
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 16395 | Stmt *HelperValStmt = nullptr; |
| 16396 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 16397 | |
| 16398 | // OpenMP [2.9.2, taskloop Constrcut] |
| 16399 | // The parameter of the num_tasks clause must be a positive integer |
| 16400 | // expression. |
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 16401 | if (!isNonNegativeIntegerValue( |
| 16402 | ValExpr, *this, OMPC_num_tasks, |
| 16403 | /*StrictlyPositive=*/true, /*BuildCapture=*/true, |
| 16404 | DSAStack->getCurrentDirective(), &CaptureRegion, &HelperValStmt)) |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 16405 | return nullptr; |
| 16406 | |
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 16407 | return new (Context) OMPNumTasksClause(ValExpr, HelperValStmt, CaptureRegion, |
| 16408 | StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 16409 | } |
| 16410 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 16411 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 16412 | SourceLocation LParenLoc, |
| 16413 | SourceLocation EndLoc) { |
| 16414 | // OpenMP [2.13.2, critical construct, Description] |
| 16415 | // ... where hint-expression is an integer constant expression that evaluates |
| 16416 | // to a valid lock hint. |
| 16417 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 16418 | if (HintExpr.isInvalid()) |
| 16419 | return nullptr; |
| 16420 | return new (Context) |
| 16421 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 16422 | } |
| 16423 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 16424 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 16425 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 16426 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 16427 | SourceLocation EndLoc) { |
| 16428 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 16429 | std::string Values; |
| 16430 | Values += "'"; |
| 16431 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 16432 | Values += "'"; |
| 16433 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 16434 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 16435 | return nullptr; |
| 16436 | } |
| 16437 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 16438 | Stmt *HelperValStmt = nullptr; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 16439 | if (ChunkSize) { |
| 16440 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 16441 | !ChunkSize->isInstantiationDependent() && |
| 16442 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 16443 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 16444 | ExprResult Val = |
| 16445 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 16446 | if (Val.isInvalid()) |
| 16447 | return nullptr; |
| 16448 | |
| 16449 | ValExpr = Val.get(); |
| 16450 | |
| 16451 | // OpenMP [2.7.1, Restrictions] |
| 16452 | // chunk_size must be a loop invariant integer expression with a positive |
| 16453 | // value. |
| 16454 | llvm::APSInt Result; |
| 16455 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 16456 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 16457 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 16458 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 16459 | return nullptr; |
| 16460 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 16461 | } else if (getOpenMPCaptureRegionForClause( |
| Alexey Bataev | 6120582 | 2019-12-04 09:50:21 -0500 | [diff] [blame] | 16462 | DSAStack->getCurrentDirective(), OMPC_dist_schedule, |
| 16463 | LangOpts.OpenMP) != OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 16464 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 16465 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16466 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 16467 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 16468 | HelperValStmt = buildPreInits(Context, Captures); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 16469 | } |
| 16470 | } |
| 16471 | } |
| 16472 | |
| 16473 | return new (Context) |
| 16474 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 16475 | Kind, ValExpr, HelperValStmt); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 16476 | } |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 16477 | |
| 16478 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 16479 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 16480 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 16481 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 16482 | if (getLangOpts().OpenMP < 50) { |
| 16483 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 16484 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 16485 | std::string Value; |
| 16486 | SourceLocation Loc; |
| 16487 | Value += "'"; |
| 16488 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 16489 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 16490 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 16491 | Loc = MLoc; |
| 16492 | } else { |
| 16493 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 16494 | OMPC_DEFAULTMAP_scalar); |
| 16495 | Loc = KindLoc; |
| 16496 | } |
| 16497 | Value += "'"; |
| 16498 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 16499 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 16500 | return nullptr; |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 16501 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 16502 | } else { |
| 16503 | bool isDefaultmapModifier = (M != OMPC_DEFAULTMAP_MODIFIER_unknown); |
| 16504 | bool isDefaultmapKind = (Kind != OMPC_DEFAULTMAP_unknown); |
| 16505 | if (!isDefaultmapKind || !isDefaultmapModifier) { |
| 16506 | std::string ModifierValue = "'alloc', 'from', 'to', 'tofrom', " |
| 16507 | "'firstprivate', 'none', 'default'"; |
| 16508 | std::string KindValue = "'scalar', 'aggregate', 'pointer'"; |
| 16509 | if (!isDefaultmapKind && isDefaultmapModifier) { |
| 16510 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 16511 | << KindValue << getOpenMPClauseName(OMPC_defaultmap); |
| 16512 | } else if (isDefaultmapKind && !isDefaultmapModifier) { |
| 16513 | Diag(MLoc, diag::err_omp_unexpected_clause_value) |
| 16514 | << ModifierValue << getOpenMPClauseName(OMPC_defaultmap); |
| 16515 | } else { |
| 16516 | Diag(MLoc, diag::err_omp_unexpected_clause_value) |
| 16517 | << ModifierValue << getOpenMPClauseName(OMPC_defaultmap); |
| 16518 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 16519 | << KindValue << getOpenMPClauseName(OMPC_defaultmap); |
| 16520 | } |
| 16521 | return nullptr; |
| 16522 | } |
| 16523 | |
| 16524 | // OpenMP [5.0, 2.12.5, Restrictions, p. 174] |
| 16525 | // At most one defaultmap clause for each category can appear on the |
| 16526 | // directive. |
| 16527 | if (DSAStack->checkDefaultmapCategory(Kind)) { |
| 16528 | Diag(StartLoc, diag::err_omp_one_defaultmap_each_category); |
| 16529 | return nullptr; |
| 16530 | } |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 16531 | } |
| cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 16532 | DSAStack->setDefaultDMAAttr(M, Kind, StartLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 16533 | |
| 16534 | return new (Context) |
| 16535 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 16536 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16537 | |
| 16538 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 16539 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 16540 | if (!CurLexicalContext->isFileContext() && |
| 16541 | !CurLexicalContext->isExternCContext() && |
| Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 16542 | !CurLexicalContext->isExternCXXContext() && |
| 16543 | !isa<CXXRecordDecl>(CurLexicalContext) && |
| 16544 | !isa<ClassTemplateDecl>(CurLexicalContext) && |
| 16545 | !isa<ClassTemplatePartialSpecializationDecl>(CurLexicalContext) && |
| 16546 | !isa<ClassTemplateSpecializationDecl>(CurLexicalContext)) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16547 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 16548 | return false; |
| 16549 | } |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 16550 | ++DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16551 | return true; |
| 16552 | } |
| 16553 | |
| 16554 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 16555 | assert(DeclareTargetNestingLevel > 0 && |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16556 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 16557 | --DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16558 | } |
| 16559 | |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16560 | NamedDecl * |
| 16561 | Sema::lookupOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
| 16562 | const DeclarationNameInfo &Id, |
| 16563 | NamedDeclSetType &SameDirectiveDecls) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16564 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 16565 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 16566 | |
| 16567 | if (Lookup.isAmbiguous()) |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16568 | return nullptr; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16569 | Lookup.suppressDiagnostics(); |
| 16570 | |
| 16571 | if (!Lookup.isSingleResult()) { |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 16572 | VarOrFuncDeclFilterCCC CCC(*this); |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16573 | if (TypoCorrection Corrected = |
| Bruno Ricci | 70ad396 | 2019-03-25 17:08:51 +0000 | [diff] [blame] | 16574 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, CCC, |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16575 | CTK_ErrorRecovery)) { |
| 16576 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 16577 | << Id.getName()); |
| 16578 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16579 | return nullptr; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16580 | } |
| 16581 | |
| 16582 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16583 | return nullptr; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16584 | } |
| 16585 | |
| 16586 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16587 | if (!isa<VarDecl>(ND) && !isa<FunctionDecl>(ND) && |
| 16588 | !isa<FunctionTemplateDecl>(ND)) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16589 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16590 | return nullptr; |
| 16591 | } |
| 16592 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 16593 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 16594 | return ND; |
| 16595 | } |
| 16596 | |
| 16597 | void Sema::ActOnOpenMPDeclareTargetName( |
| 16598 | NamedDecl *ND, SourceLocation Loc, OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 16599 | OMPDeclareTargetDeclAttr::DevTypeTy DT) { |
| 16600 | assert((isa<VarDecl>(ND) || isa<FunctionDecl>(ND) || |
| 16601 | isa<FunctionTemplateDecl>(ND)) && |
| 16602 | "Expected variable, function or function template."); |
| 16603 | |
| 16604 | // Diagnose marking after use as it may lead to incorrect diagnosis and |
| 16605 | // codegen. |
| 16606 | if (LangOpts.OpenMP >= 50 && |
| 16607 | (ND->isUsed(/*CheckUsedAttr=*/false) || ND->isReferenced())) |
| 16608 | Diag(Loc, diag::warn_omp_declare_target_after_first_use); |
| 16609 | |
| 16610 | Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy = |
| 16611 | OMPDeclareTargetDeclAttr::getDeviceType(cast<ValueDecl>(ND)); |
| 16612 | if (DevTy.hasValue() && *DevTy != DT) { |
| 16613 | Diag(Loc, diag::err_omp_device_type_mismatch) |
| 16614 | << OMPDeclareTargetDeclAttr::ConvertDevTypeTyToStr(DT) |
| 16615 | << OMPDeclareTargetDeclAttr::ConvertDevTypeTyToStr(*DevTy); |
| 16616 | return; |
| 16617 | } |
| 16618 | Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 16619 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(cast<ValueDecl>(ND)); |
| 16620 | if (!Res) { |
| 16621 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT, DT, |
| 16622 | SourceRange(Loc, Loc)); |
| 16623 | ND->addAttr(A); |
| 16624 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 16625 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 16626 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc); |
| 16627 | } else if (*Res != MT) { |
| 16628 | Diag(Loc, diag::err_omp_declare_target_to_and_link) << ND; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16629 | } |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 16630 | } |
| 16631 | |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16632 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 16633 | Sema &SemaRef, Decl *D) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16634 | if (!D || !isa<VarDecl>(D)) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16635 | return; |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16636 | auto *VD = cast<VarDecl>(D); |
| Alexey Bataev | 217ff1e | 2019-08-16 20:15:02 +0000 | [diff] [blame] | 16637 | Optional<OMPDeclareTargetDeclAttr::MapTypeTy> MapTy = |
| 16638 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
| 16639 | if (SemaRef.LangOpts.OpenMP >= 50 && |
| 16640 | (SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true) || |
| 16641 | SemaRef.getCurBlock() || SemaRef.getCurCapturedRegion()) && |
| 16642 | VD->hasGlobalStorage()) { |
| 16643 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> MapTy = |
| 16644 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
| 16645 | if (!MapTy || *MapTy != OMPDeclareTargetDeclAttr::MT_To) { |
| 16646 | // OpenMP 5.0, 2.12.7 declare target Directive, Restrictions |
| 16647 | // If a lambda declaration and definition appears between a |
| 16648 | // declare target directive and the matching end declare target |
| 16649 | // directive, all variables that are captured by the lambda |
| 16650 | // expression must also appear in a to clause. |
| 16651 | SemaRef.Diag(VD->getLocation(), |
| Alexey Bataev | c429955 | 2019-08-20 17:50:13 +0000 | [diff] [blame] | 16652 | diag::err_omp_lambda_capture_in_declare_target_not_to); |
| Alexey Bataev | 217ff1e | 2019-08-16 20:15:02 +0000 | [diff] [blame] | 16653 | SemaRef.Diag(SL, diag::note_var_explicitly_captured_here) |
| 16654 | << VD << 0 << SR; |
| 16655 | return; |
| 16656 | } |
| 16657 | } |
| 16658 | if (MapTy.hasValue()) |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16659 | return; |
| 16660 | SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_target_context); |
| 16661 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16662 | } |
| 16663 | |
| 16664 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 16665 | Sema &SemaRef, DSAStackTy *Stack, |
| 16666 | ValueDecl *VD) { |
| Alexey Bataev | ebcfc9e | 2019-08-22 16:48:26 +0000 | [diff] [blame] | 16667 | return OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD) || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16668 | checkTypeMappable(SL, SR, SemaRef, Stack, VD->getType(), |
| 16669 | /*FullCheck=*/false); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16670 | } |
| 16671 | |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 16672 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
| 16673 | SourceLocation IdLoc) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16674 | if (!D || D->isInvalidDecl()) |
| 16675 | return; |
| 16676 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 16677 | SourceLocation SL = E ? E->getBeginLoc() : D->getLocation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16678 | if (auto *VD = dyn_cast<VarDecl>(D)) { |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 16679 | // Only global variables can be marked as declare target. |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16680 | if (!VD->isFileVarDecl() && !VD->isStaticLocal() && |
| 16681 | !VD->isStaticDataMember()) |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 16682 | return; |
| 16683 | // 2.10.6: threadprivate variable cannot appear in a declare target |
| 16684 | // directive. |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16685 | if (DSAStack->isThreadPrivate(VD)) { |
| 16686 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16687 | reportOriginalDsa(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16688 | return; |
| 16689 | } |
| 16690 | } |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 16691 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 16692 | D = FTD->getTemplatedDecl(); |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 16693 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16694 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 16695 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD); |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 16696 | if (IdLoc.isValid() && Res && *Res == OMPDeclareTargetDeclAttr::MT_Link) { |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 16697 | Diag(IdLoc, diag::err_omp_function_in_link_clause); |
| 16698 | Diag(FD->getLocation(), diag::note_defined_here) << FD; |
| 16699 | return; |
| 16700 | } |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 16701 | // Mark the function as must be emitted for the device. |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16702 | Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy = |
| 16703 | OMPDeclareTargetDeclAttr::getDeviceType(FD); |
| 16704 | if (LangOpts.OpenMPIsDevice && Res.hasValue() && IdLoc.isValid() && |
| 16705 | *DevTy != OMPDeclareTargetDeclAttr::DT_Host) |
| Alexey Bataev | 9fd495b | 2019-08-20 19:50:13 +0000 | [diff] [blame] | 16706 | checkOpenMPDeviceFunction(IdLoc, FD, /*CheckForDelayedContext=*/false); |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16707 | if (!LangOpts.OpenMPIsDevice && Res.hasValue() && IdLoc.isValid() && |
| 16708 | *DevTy != OMPDeclareTargetDeclAttr::DT_NoHost) |
| 16709 | checkOpenMPHostFunction(IdLoc, FD, /*CheckCaller=*/false); |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 16710 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16711 | if (auto *VD = dyn_cast<ValueDecl>(D)) { |
| 16712 | // Problem if any with var declared with incomplete type will be reported |
| 16713 | // as normal, so no need to check it here. |
| 16714 | if ((E || !VD->getType()->isIncompleteType()) && |
| 16715 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) |
| 16716 | return; |
| 16717 | if (!E && !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) { |
| 16718 | // Checking declaration inside declare target region. |
| 16719 | if (isa<VarDecl>(D) || isa<FunctionDecl>(D) || |
| 16720 | isa<FunctionTemplateDecl>(D)) { |
| 16721 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 16722 | Context, OMPDeclareTargetDeclAttr::MT_To, |
| 16723 | OMPDeclareTargetDeclAttr::DT_Any, SourceRange(IdLoc, IdLoc)); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16724 | D->addAttr(A); |
| 16725 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 16726 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
| 16727 | } |
| 16728 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16729 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16730 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 16731 | if (!E) |
| 16732 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 16733 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 16734 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 16735 | |
| 16736 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 16737 | CXXScopeSpec &MapperIdScopeSpec, |
| 16738 | DeclarationNameInfo &MapperId, |
| 16739 | const OMPVarListLocTy &Locs, |
| 16740 | ArrayRef<Expr *> UnresolvedMappers) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 16741 | MappableVarListInfo MVLI(VarList); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 16742 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, Locs.StartLoc, |
| 16743 | MapperIdScopeSpec, MapperId, UnresolvedMappers); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 16744 | if (MVLI.ProcessedVarList.empty()) |
| 16745 | return nullptr; |
| 16746 | |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 16747 | return OMPToClause::Create( |
| 16748 | Context, Locs, MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 16749 | MVLI.VarComponents, MVLI.UDMapperList, |
| 16750 | MapperIdScopeSpec.getWithLocInContext(Context), MapperId); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 16751 | } |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 16752 | |
| 16753 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 16754 | CXXScopeSpec &MapperIdScopeSpec, |
| 16755 | DeclarationNameInfo &MapperId, |
| 16756 | const OMPVarListLocTy &Locs, |
| 16757 | ArrayRef<Expr *> UnresolvedMappers) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 16758 | MappableVarListInfo MVLI(VarList); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 16759 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, Locs.StartLoc, |
| 16760 | MapperIdScopeSpec, MapperId, UnresolvedMappers); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 16761 | if (MVLI.ProcessedVarList.empty()) |
| 16762 | return nullptr; |
| 16763 | |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 16764 | return OMPFromClause::Create( |
| 16765 | Context, Locs, MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 16766 | MVLI.VarComponents, MVLI.UDMapperList, |
| 16767 | MapperIdScopeSpec.getWithLocInContext(Context), MapperId); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 16768 | } |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16769 | |
| 16770 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 16771 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16772 | MappableVarListInfo MVLI(VarList); |
| 16773 | SmallVector<Expr *, 8> PrivateCopies; |
| 16774 | SmallVector<Expr *, 8> Inits; |
| 16775 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16776 | for (Expr *RefExpr : VarList) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16777 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 16778 | SourceLocation ELoc; |
| 16779 | SourceRange ERange; |
| 16780 | Expr *SimpleRefExpr = RefExpr; |
| 16781 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 16782 | if (Res.second) { |
| 16783 | // It will be analyzed later. |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16784 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 16785 | PrivateCopies.push_back(nullptr); |
| 16786 | Inits.push_back(nullptr); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16787 | } |
| 16788 | ValueDecl *D = Res.first; |
| 16789 | if (!D) |
| 16790 | continue; |
| 16791 | |
| 16792 | QualType Type = D->getType(); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16793 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 16794 | |
| 16795 | auto *VD = dyn_cast<VarDecl>(D); |
| 16796 | |
| 16797 | // Item should be a pointer or reference to pointer. |
| 16798 | if (!Type->isPointerType()) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16799 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 16800 | << 0 << RefExpr->getSourceRange(); |
| 16801 | continue; |
| 16802 | } |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16803 | |
| 16804 | // Build the private variable and the expression that refers to it. |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 16805 | auto VDPrivate = |
| 16806 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 16807 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 16808 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16809 | if (VDPrivate->isInvalidDecl()) |
| 16810 | continue; |
| 16811 | |
| 16812 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16813 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16814 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 16815 | |
| 16816 | // Add temporary variable to initialize the private copy of the pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16817 | VarDecl *VDInit = |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16818 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16819 | DeclRefExpr *VDInitRefExpr = buildDeclRefExpr( |
| 16820 | *this, VDInit, RefExpr->getType(), RefExpr->getExprLoc()); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16821 | AddInitializerToDecl(VDPrivate, |
| 16822 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 16823 | /*DirectInit=*/false); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16824 | |
| 16825 | // If required, build a capture to implement the privatization initialized |
| 16826 | // with the current list item value. |
| 16827 | DeclRefExpr *Ref = nullptr; |
| 16828 | if (!VD) |
| 16829 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 16830 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 16831 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 16832 | Inits.push_back(VDInitRefExpr); |
| 16833 | |
| 16834 | // We need to add a data sharing attribute for this variable to make sure it |
| 16835 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 16836 | // similar properties of a first private variable. |
| 16837 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 16838 | |
| 16839 | // Create a mappable component for the list item. List items in this clause |
| 16840 | // only need a component. |
| 16841 | MVLI.VarBaseDeclarations.push_back(D); |
| 16842 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 16843 | MVLI.VarComponents.back().push_back( |
| 16844 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16845 | } |
| 16846 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16847 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16848 | return nullptr; |
| 16849 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 16850 | return OMPUseDevicePtrClause::Create( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 16851 | Context, Locs, MVLI.ProcessedVarList, PrivateCopies, Inits, |
| 16852 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 16853 | } |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16854 | |
| 16855 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 16856 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16857 | MappableVarListInfo MVLI(VarList); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16858 | for (Expr *RefExpr : VarList) { |
| Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 16859 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16860 | SourceLocation ELoc; |
| 16861 | SourceRange ERange; |
| 16862 | Expr *SimpleRefExpr = RefExpr; |
| 16863 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 16864 | if (Res.second) { |
| 16865 | // It will be analyzed later. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16866 | MVLI.ProcessedVarList.push_back(RefExpr); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16867 | } |
| 16868 | ValueDecl *D = Res.first; |
| 16869 | if (!D) |
| 16870 | continue; |
| 16871 | |
| 16872 | QualType Type = D->getType(); |
| 16873 | // item should be a pointer or array or reference to pointer or array |
| 16874 | if (!Type.getNonReferenceType()->isPointerType() && |
| 16875 | !Type.getNonReferenceType()->isArrayType()) { |
| 16876 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 16877 | << 0 << RefExpr->getSourceRange(); |
| 16878 | continue; |
| 16879 | } |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16880 | |
| 16881 | // Check if the declaration in the clause does not show up in any data |
| 16882 | // sharing attribute. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16883 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16884 | if (isOpenMPPrivate(DVar.CKind)) { |
| 16885 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 16886 | << getOpenMPClauseName(DVar.CKind) |
| 16887 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 16888 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16889 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16890 | continue; |
| 16891 | } |
| 16892 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 16893 | const Expr *ConflictExpr; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16894 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 16895 | D, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16896 | [&ConflictExpr]( |
| 16897 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 16898 | OpenMPClauseKind) -> bool { |
| 16899 | ConflictExpr = R.front().getAssociatedExpression(); |
| 16900 | return true; |
| 16901 | })) { |
| 16902 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 16903 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 16904 | << ConflictExpr->getSourceRange(); |
| 16905 | continue; |
| 16906 | } |
| 16907 | |
| 16908 | // Store the components in the stack so that they can be used to check |
| 16909 | // against other clauses later on. |
| 16910 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 16911 | DSAStack->addMappableExpressionComponents( |
| 16912 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 16913 | |
| 16914 | // Record the expression we've just processed. |
| 16915 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 16916 | |
| 16917 | // Create a mappable component for the list item. List items in this clause |
| 16918 | // only need a component. We use a null declaration to signal fields in |
| 16919 | // 'this'. |
| 16920 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 16921 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 16922 | "Unexpected device pointer expression!"); |
| 16923 | MVLI.VarBaseDeclarations.push_back( |
| 16924 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 16925 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 16926 | MVLI.VarComponents.back().push_back(MC); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16927 | } |
| 16928 | |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 16929 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16930 | return nullptr; |
| 16931 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 16932 | return OMPIsDevicePtrClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 16933 | MVLI.VarBaseDeclarations, |
| 16934 | MVLI.VarComponents); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 16935 | } |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 16936 | |
| 16937 | OMPClause *Sema::ActOnOpenMPAllocateClause( |
| 16938 | Expr *Allocator, ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 16939 | SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 16940 | if (Allocator) { |
| 16941 | // OpenMP [2.11.4 allocate Clause, Description] |
| 16942 | // allocator is an expression of omp_allocator_handle_t type. |
| 16943 | if (!findOMPAllocatorHandleT(*this, Allocator->getExprLoc(), DSAStack)) |
| 16944 | return nullptr; |
| 16945 | |
| 16946 | ExprResult AllocatorRes = DefaultLvalueConversion(Allocator); |
| 16947 | if (AllocatorRes.isInvalid()) |
| 16948 | return nullptr; |
| 16949 | AllocatorRes = PerformImplicitConversion(AllocatorRes.get(), |
| 16950 | DSAStack->getOMPAllocatorHandleT(), |
| 16951 | Sema::AA_Initializing, |
| 16952 | /*AllowExplicit=*/true); |
| 16953 | if (AllocatorRes.isInvalid()) |
| 16954 | return nullptr; |
| 16955 | Allocator = AllocatorRes.get(); |
| Alexey Bataev | 84c8bae | 2019-04-01 16:56:59 +0000 | [diff] [blame] | 16956 | } else { |
| 16957 | // OpenMP 5.0, 2.11.4 allocate Clause, Restrictions. |
| 16958 | // allocate clauses that appear on a target construct or on constructs in a |
| 16959 | // target region must specify an allocator expression unless a requires |
| 16960 | // directive with the dynamic_allocators clause is present in the same |
| 16961 | // compilation unit. |
| 16962 | if (LangOpts.OpenMPIsDevice && |
| 16963 | !DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>()) |
| 16964 | targetDiag(StartLoc, diag::err_expected_allocator_expression); |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 16965 | } |
| 16966 | // Analyze and build list of variables. |
| 16967 | SmallVector<Expr *, 8> Vars; |
| 16968 | for (Expr *RefExpr : VarList) { |
| 16969 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 16970 | SourceLocation ELoc; |
| 16971 | SourceRange ERange; |
| 16972 | Expr *SimpleRefExpr = RefExpr; |
| 16973 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 16974 | if (Res.second) { |
| 16975 | // It will be analyzed later. |
| 16976 | Vars.push_back(RefExpr); |
| 16977 | } |
| 16978 | ValueDecl *D = Res.first; |
| 16979 | if (!D) |
| 16980 | continue; |
| 16981 | |
| 16982 | auto *VD = dyn_cast<VarDecl>(D); |
| 16983 | DeclRefExpr *Ref = nullptr; |
| 16984 | if (!VD && !CurContext->isDependentContext()) |
| 16985 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 16986 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 16987 | ? RefExpr->IgnoreParens() |
| 16988 | : Ref); |
| 16989 | } |
| 16990 | |
| 16991 | if (Vars.empty()) |
| 16992 | return nullptr; |
| 16993 | |
| 16994 | return OMPAllocateClause::Create(Context, StartLoc, LParenLoc, Allocator, |
| 16995 | ColonLoc, EndLoc, Vars); |
| 16996 | } |