| 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 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10 | /// This file implements semantic analysis for OpenMP directives and |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclOpenMP.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtCXX.h" |
| 23 | #include "clang/AST/StmtOpenMP.h" |
| 24 | #include "clang/AST/StmtVisitor.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 | |
| 51 | /// Attributes of the defaultmap clause. |
| 52 | enum DefaultMapAttributes { |
| 53 | DMA_unspecified, /// Default mapping is not specified. |
| 54 | DMA_tofrom_scalar, /// Default mapping is 'tofrom:scalar'. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 55 | }; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 56 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 57 | /// Stack for tracking declarations used in OpenMP directives and |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 58 | /// clauses and their data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 59 | class DSAStackTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 60 | public: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 61 | struct DSAVarData { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 62 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 63 | OpenMPClauseKind CKind = OMPC_unknown; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 64 | const Expr *RefExpr = nullptr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 65 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 66 | SourceLocation ImplicitDSALoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 67 | DSAVarData() = default; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 68 | DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 69 | const Expr *RefExpr, DeclRefExpr *PrivateCopy, |
| 70 | SourceLocation ImplicitDSALoc) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 71 | : DKind(DKind), CKind(CKind), RefExpr(RefExpr), |
| 72 | PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {} |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 73 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 74 | using OperatorOffsetTy = |
| 75 | llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4>; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 76 | using DoacrossDependMapTy = |
| 77 | llvm::DenseMap<OMPDependClause *, OperatorOffsetTy>; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 78 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 79 | private: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 80 | struct DSAInfo { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 81 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 82 | /// Pointer to a reference expression and a flag which shows that the |
| 83 | /// variable is marked as lastprivate(true) or not (false). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 84 | llvm::PointerIntPair<const Expr *, 1, bool> RefExpr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 85 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 87 | using DeclSAMapTy = llvm::SmallDenseMap<const ValueDecl *, DSAInfo, 8>; |
| 88 | using AlignedMapTy = llvm::SmallDenseMap<const ValueDecl *, const Expr *, 8>; |
| 89 | using LCDeclInfo = std::pair<unsigned, VarDecl *>; |
| 90 | using LoopControlVariablesMapTy = |
| 91 | llvm::SmallDenseMap<const ValueDecl *, LCDeclInfo, 8>; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 92 | /// Struct that associates a component with the clause kind where they are |
| 93 | /// found. |
| 94 | struct MappedExprComponentTy { |
| 95 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 96 | OpenMPClauseKind Kind = OMPC_unknown; |
| 97 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 98 | using MappedExprComponentsTy = |
| 99 | llvm::DenseMap<const ValueDecl *, MappedExprComponentTy>; |
| 100 | using CriticalsWithHintsTy = |
| 101 | llvm::StringMap<std::pair<const OMPCriticalDirective *, llvm::APSInt>>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 102 | struct ReductionData { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 103 | using BOKPtrType = llvm::PointerEmbeddedInt<BinaryOperatorKind, 16>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 104 | SourceRange ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 105 | llvm::PointerUnion<const Expr *, BOKPtrType> ReductionOp; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 106 | ReductionData() = default; |
| 107 | void set(BinaryOperatorKind BO, SourceRange RR) { |
| 108 | ReductionRange = RR; |
| 109 | ReductionOp = BO; |
| 110 | } |
| 111 | void set(const Expr *RefExpr, SourceRange RR) { |
| 112 | ReductionRange = RR; |
| 113 | ReductionOp = RefExpr; |
| 114 | } |
| 115 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 116 | using DeclReductionMapTy = |
| 117 | llvm::SmallDenseMap<const ValueDecl *, ReductionData, 4>; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 118 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 119 | struct SharingMapTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 120 | DeclSAMapTy SharingMap; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 121 | DeclReductionMapTy ReductionMap; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 122 | AlignedMapTy AlignedMap; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 123 | MappedExprComponentsTy MappedExprComponents; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 124 | LoopControlVariablesMapTy LCVMap; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 125 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 126 | SourceLocation DefaultAttrLoc; |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 127 | DefaultMapAttributes DefaultMapAttr = DMA_unspecified; |
| 128 | SourceLocation DefaultMapAttrLoc; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 129 | OpenMPDirectiveKind Directive = OMPD_unknown; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 130 | DeclarationNameInfo DirectiveName; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 131 | Scope *CurScope = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 132 | SourceLocation ConstructLoc; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 133 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 134 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 135 | /// This data is required during codegen. |
| 136 | DoacrossDependMapTy DoacrossDepends; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 137 | /// first argument (Expr *) contains optional argument of the |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 138 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 139 | /// clause, false otherwise. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 140 | llvm::Optional<std::pair<const Expr *, OMPOrderedClause *>> OrderedRegion; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 141 | bool NowaitRegion = false; |
| 142 | bool CancelRegion = false; |
| 143 | unsigned AssociatedLoops = 1; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 144 | SourceLocation InnerTeamsRegionLoc; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 145 | /// Reference to the taskgroup task_reduction reference expression. |
| 146 | Expr *TaskgroupReductionRef = nullptr; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 147 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 148 | Scope *CurScope, SourceLocation Loc) |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 149 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 150 | ConstructLoc(Loc) {} |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 151 | SharingMapTy() = default; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 154 | using StackTy = SmallVector<SharingMapTy, 4>; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 156 | /// Stack of used declaration and their data-sharing attributes. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 157 | DeclSAMapTy Threadprivates; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 158 | const FunctionScopeInfo *CurrentNonCapturingFunctionScope = nullptr; |
| 159 | SmallVector<std::pair<StackTy, const FunctionScopeInfo *>, 4> Stack; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 160 | /// true, if check for DSA must be from parent directive, false, if |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 161 | /// from current directive. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 162 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 163 | Sema &SemaRef; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 164 | bool ForceCapturing = false; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 165 | CriticalsWithHintsTy Criticals; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 166 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 167 | using iterator = StackTy::const_reverse_iterator; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 168 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 169 | DSAVarData getDSA(iterator &Iter, ValueDecl *D) const; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 170 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 171 | /// Checks if the variable is a local for OpenMP region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 172 | bool isOpenMPLocal(VarDecl *D, iterator Iter) const; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 173 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 174 | bool isStackEmpty() const { |
| 175 | return Stack.empty() || |
| 176 | Stack.back().second != CurrentNonCapturingFunctionScope || |
| 177 | Stack.back().first.empty(); |
| 178 | } |
| 179 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 180 | public: |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 181 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 182 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 183 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 184 | OpenMPClauseKind getClauseParsingMode() const { |
| 185 | assert(isClauseParsingMode() && "Must be in clause parsing mode."); |
| 186 | return ClauseKindMode; |
| 187 | } |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 188 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 189 | |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 190 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 191 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 192 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 193 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 194 | Scope *CurScope, SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 195 | if (Stack.empty() || |
| 196 | Stack.back().second != CurrentNonCapturingFunctionScope) |
| 197 | Stack.emplace_back(StackTy(), CurrentNonCapturingFunctionScope); |
| 198 | Stack.back().first.emplace_back(DKind, DirName, CurScope, Loc); |
| 199 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void pop() { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 203 | assert(!Stack.back().first.empty() && |
| 204 | "Data-sharing attributes stack is empty!"); |
| 205 | Stack.back().first.pop_back(); |
| 206 | } |
| 207 | |
| 208 | /// Start new OpenMP region stack in new non-capturing function. |
| 209 | void pushFunction() { |
| 210 | const FunctionScopeInfo *CurFnScope = SemaRef.getCurFunction(); |
| 211 | assert(!isa<CapturingScopeInfo>(CurFnScope)); |
| 212 | CurrentNonCapturingFunctionScope = CurFnScope; |
| 213 | } |
| 214 | /// Pop region stack for non-capturing function. |
| 215 | void popFunction(const FunctionScopeInfo *OldFSI) { |
| 216 | if (!Stack.empty() && Stack.back().second == OldFSI) { |
| 217 | assert(Stack.back().first.empty()); |
| 218 | Stack.pop_back(); |
| 219 | } |
| 220 | CurrentNonCapturingFunctionScope = nullptr; |
| 221 | for (const FunctionScopeInfo *FSI : llvm::reverse(SemaRef.FunctionScopes)) { |
| 222 | if (!isa<CapturingScopeInfo>(FSI)) { |
| 223 | CurrentNonCapturingFunctionScope = FSI; |
| 224 | break; |
| 225 | } |
| 226 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 229 | void addCriticalWithHint(const OMPCriticalDirective *D, llvm::APSInt Hint) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 230 | Criticals.try_emplace(D->getDirectiveName().getAsString(), D, Hint); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 231 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 232 | const std::pair<const OMPCriticalDirective *, llvm::APSInt> |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 233 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 234 | auto I = Criticals.find(Name.getAsString()); |
| 235 | if (I != Criticals.end()) |
| 236 | return I->second; |
| 237 | return std::make_pair(nullptr, llvm::APSInt()); |
| 238 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 239 | /// If 'aligned' declaration for given variable \a D was not seen yet, |
| Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 240 | /// add it and return NULL; otherwise return previous occurrence's expression |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 241 | /// for diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 242 | const Expr *addUniqueAligned(const ValueDecl *D, const Expr *NewDE); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 243 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 244 | /// Register specified variable as loop control variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 245 | void addLoopControlVariable(const ValueDecl *D, VarDecl *Capture); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 246 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 247 | /// current region. |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 248 | /// \return The index of the loop control variable in the list of associated |
| 249 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 250 | const LCDeclInfo isLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 251 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 252 | /// parent region. |
| 253 | /// \return The index of the loop control variable in the list of associated |
| 254 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 255 | const LCDeclInfo isParentLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 256 | /// 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] | 257 | /// parent directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 258 | const ValueDecl *getParentLoopControlVariable(unsigned I) const; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 259 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 260 | /// Adds explicit data sharing attribute to the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 261 | void addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 262 | DeclRefExpr *PrivateCopy = nullptr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 263 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 264 | /// Adds additional information for the reduction items with the reduction id |
| 265 | /// represented as an operator. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 266 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 267 | BinaryOperatorKind BOK); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 268 | /// Adds additional information for the reduction items with the reduction id |
| 269 | /// represented as reduction identifier. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 270 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 271 | const Expr *ReductionRef); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 272 | /// Returns the location and reduction operation from the innermost parent |
| 273 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 274 | const DSAVarData |
| 275 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 276 | BinaryOperatorKind &BOK, |
| 277 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 278 | /// Returns the location and reduction operation from the innermost parent |
| 279 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 280 | const DSAVarData |
| 281 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 282 | const Expr *&ReductionRef, |
| 283 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 284 | /// Return reduction reference expression for the current taskgroup. |
| 285 | Expr *getTaskgroupReductionRef() const { |
| 286 | assert(Stack.back().first.back().Directive == OMPD_taskgroup && |
| 287 | "taskgroup reference expression requested for non taskgroup " |
| 288 | "directive."); |
| 289 | return Stack.back().first.back().TaskgroupReductionRef; |
| 290 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 291 | /// Checks if the given \p VD declaration is actually a taskgroup reduction |
| 292 | /// descriptor variable at the \p Level of OpenMP regions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 293 | bool isTaskgroupReductionRef(const ValueDecl *VD, unsigned Level) const { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 294 | return Stack.back().first[Level].TaskgroupReductionRef && |
| 295 | cast<DeclRefExpr>(Stack.back().first[Level].TaskgroupReductionRef) |
| 296 | ->getDecl() == VD; |
| 297 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 298 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 299 | /// Returns data sharing attributes from top of the stack for the |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 300 | /// specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 301 | const DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 302 | /// Returns data-sharing attributes for the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 303 | const DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 304 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 305 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 306 | /// predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 307 | const DSAVarData |
| 308 | hasDSA(ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 309 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 310 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 311 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 312 | /// match specified \a CPred predicate in any innermost directive which |
| 313 | /// matches \a DPred predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 314 | const DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 315 | hasInnermostDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 316 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 317 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 318 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 319 | /// Checks if the specified variables has explicit data-sharing |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 320 | /// attributes which match specified \a CPred predicate at the specified |
| 321 | /// OpenMP region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 322 | bool hasExplicitDSA(const ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 323 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 324 | unsigned Level, bool NotLastprivate = false) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 325 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 326 | /// Returns true if the directive at level \Level matches in the |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 327 | /// specified \a DPred predicate. |
| 328 | bool hasExplicitDirective( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 329 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 330 | unsigned Level) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 331 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 332 | /// Finds a directive which matches specified \a DPred predicate. |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 333 | bool hasDirective( |
| 334 | const llvm::function_ref<bool( |
| 335 | OpenMPDirectiveKind, const DeclarationNameInfo &, SourceLocation)> |
| 336 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 337 | bool FromParent) const; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 338 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 339 | /// Returns currently analyzed directive. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | OpenMPDirectiveKind getCurrentDirective() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 341 | return isStackEmpty() ? OMPD_unknown : Stack.back().first.back().Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 342 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 343 | /// Returns directive kind at specified level. |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 344 | OpenMPDirectiveKind getDirective(unsigned Level) const { |
| 345 | assert(!isStackEmpty() && "No directive at specified level."); |
| 346 | return Stack.back().first[Level].Directive; |
| 347 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 348 | /// Returns parent directive. |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 349 | OpenMPDirectiveKind getParentDirective() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 350 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 351 | return OMPD_unknown; |
| 352 | return std::next(Stack.back().first.rbegin())->Directive; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 353 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 354 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 355 | /// Set default data sharing attribute to none. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 356 | void setDefaultDSANone(SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 357 | assert(!isStackEmpty()); |
| 358 | Stack.back().first.back().DefaultAttr = DSA_none; |
| 359 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 360 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 361 | /// Set default data sharing attribute to shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 362 | void setDefaultDSAShared(SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 363 | assert(!isStackEmpty()); |
| 364 | Stack.back().first.back().DefaultAttr = DSA_shared; |
| 365 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 366 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 367 | /// Set default data mapping attribute to 'tofrom:scalar'. |
| 368 | void setDefaultDMAToFromScalar(SourceLocation Loc) { |
| 369 | assert(!isStackEmpty()); |
| 370 | Stack.back().first.back().DefaultMapAttr = DMA_tofrom_scalar; |
| 371 | Stack.back().first.back().DefaultMapAttrLoc = Loc; |
| 372 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | |
| 374 | DefaultDataSharingAttributes getDefaultDSA() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 375 | return isStackEmpty() ? DSA_unspecified |
| 376 | : Stack.back().first.back().DefaultAttr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 377 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 378 | SourceLocation getDefaultDSALocation() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 379 | return isStackEmpty() ? SourceLocation() |
| 380 | : Stack.back().first.back().DefaultAttrLoc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 381 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 382 | DefaultMapAttributes getDefaultDMA() const { |
| 383 | return isStackEmpty() ? DMA_unspecified |
| 384 | : Stack.back().first.back().DefaultMapAttr; |
| 385 | } |
| 386 | DefaultMapAttributes getDefaultDMAAtLevel(unsigned Level) const { |
| 387 | return Stack.back().first[Level].DefaultMapAttr; |
| 388 | } |
| 389 | SourceLocation getDefaultDMALocation() const { |
| 390 | return isStackEmpty() ? SourceLocation() |
| 391 | : Stack.back().first.back().DefaultMapAttrLoc; |
| 392 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 393 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 394 | /// Checks if the specified variable is a threadprivate. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 395 | bool isThreadPrivate(VarDecl *D) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 396 | const DSAVarData DVar = getTopDSA(D, false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 397 | return isOpenMPThreadPrivate(DVar.CKind); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 400 | /// Marks current region as ordered (it has an 'ordered' clause). |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 401 | void setOrderedRegion(bool IsOrdered, const Expr *Param, |
| 402 | OMPOrderedClause *Clause) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 403 | assert(!isStackEmpty()); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 404 | if (IsOrdered) |
| 405 | Stack.back().first.back().OrderedRegion.emplace(Param, Clause); |
| 406 | else |
| 407 | Stack.back().first.back().OrderedRegion.reset(); |
| 408 | } |
| 409 | /// Returns true, if region is ordered (has associated 'ordered' clause), |
| 410 | /// false - otherwise. |
| 411 | bool isOrderedRegion() const { |
| 412 | if (isStackEmpty()) |
| 413 | return false; |
| 414 | return Stack.back().first.rbegin()->OrderedRegion.hasValue(); |
| 415 | } |
| 416 | /// Returns optional parameter for the ordered region. |
| 417 | std::pair<const Expr *, OMPOrderedClause *> getOrderedRegionParam() const { |
| 418 | if (isStackEmpty() || |
| 419 | !Stack.back().first.rbegin()->OrderedRegion.hasValue()) |
| 420 | return std::make_pair(nullptr, nullptr); |
| 421 | return Stack.back().first.rbegin()->OrderedRegion.getValue(); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 422 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 423 | /// Returns true, if parent region is ordered (has associated |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 424 | /// 'ordered' clause), false - otherwise. |
| 425 | bool isParentOrderedRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 426 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 427 | return false; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 428 | return std::next(Stack.back().first.rbegin())->OrderedRegion.hasValue(); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 429 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 430 | /// Returns optional parameter for the ordered region. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 431 | std::pair<const Expr *, OMPOrderedClause *> |
| 432 | getParentOrderedRegionParam() const { |
| 433 | if (isStackEmpty() || Stack.back().first.size() == 1 || |
| 434 | !std::next(Stack.back().first.rbegin())->OrderedRegion.hasValue()) |
| 435 | return std::make_pair(nullptr, nullptr); |
| 436 | return std::next(Stack.back().first.rbegin())->OrderedRegion.getValue(); |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 437 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 438 | /// Marks current region as nowait (it has a 'nowait' clause). |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 439 | void setNowaitRegion(bool IsNowait = true) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 440 | assert(!isStackEmpty()); |
| 441 | Stack.back().first.back().NowaitRegion = IsNowait; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 442 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 443 | /// Returns true, if parent region is nowait (has associated |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 444 | /// 'nowait' clause), false - otherwise. |
| 445 | bool isParentNowaitRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 446 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 447 | return false; |
| 448 | return std::next(Stack.back().first.rbegin())->NowaitRegion; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 449 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 450 | /// Marks parent region as cancel region. |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 451 | void setParentCancelRegion(bool Cancel = true) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 452 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 453 | auto &StackElemRef = *std::next(Stack.back().first.rbegin()); |
| 454 | StackElemRef.CancelRegion |= StackElemRef.CancelRegion || Cancel; |
| 455 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 456 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 457 | /// Return true if current region has inner cancel construct. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 458 | bool isCancelRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 459 | return isStackEmpty() ? false : Stack.back().first.back().CancelRegion; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 460 | } |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 461 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 462 | /// Set collapse value for the region. |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 463 | void setAssociatedLoops(unsigned Val) { |
| 464 | assert(!isStackEmpty()); |
| 465 | Stack.back().first.back().AssociatedLoops = Val; |
| 466 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 467 | /// Return collapse value for region. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 468 | unsigned getAssociatedLoops() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 469 | return isStackEmpty() ? 0 : Stack.back().first.back().AssociatedLoops; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 470 | } |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 471 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 472 | /// Marks current target region as one with closely nested teams |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 473 | /// region. |
| 474 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 475 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 476 | std::next(Stack.back().first.rbegin())->InnerTeamsRegionLoc = |
| 477 | TeamsRegionLoc; |
| 478 | } |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 479 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 480 | /// Returns true, if current region has closely nested teams region. |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 481 | bool hasInnerTeamsRegion() const { |
| 482 | return getInnerTeamsRegionLoc().isValid(); |
| 483 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 484 | /// Returns location of the nested teams region (if any). |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 485 | SourceLocation getInnerTeamsRegionLoc() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 486 | return isStackEmpty() ? SourceLocation() |
| 487 | : Stack.back().first.back().InnerTeamsRegionLoc; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 490 | Scope *getCurScope() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 491 | return isStackEmpty() ? nullptr : Stack.back().first.back().CurScope; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 492 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 493 | SourceLocation getConstructLoc() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 494 | return isStackEmpty() ? SourceLocation() |
| 495 | : Stack.back().first.back().ConstructLoc; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 496 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 497 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 498 | /// Do the check specified in \a Check to all component lists and return true |
| 499 | /// if any issue is found. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 500 | bool checkMappableExprComponentListsForDecl( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 501 | const ValueDecl *VD, bool CurrentRegionOnly, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 502 | const llvm::function_ref< |
| 503 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 504 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 505 | Check) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 506 | if (isStackEmpty()) |
| 507 | return false; |
| 508 | auto SI = Stack.back().first.rbegin(); |
| 509 | auto SE = Stack.back().first.rend(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 510 | |
| 511 | if (SI == SE) |
| 512 | return false; |
| 513 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 514 | if (CurrentRegionOnly) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 515 | SE = std::next(SI); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 516 | else |
| 517 | std::advance(SI, 1); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 518 | |
| 519 | for (; SI != SE; ++SI) { |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 520 | auto MI = SI->MappedExprComponents.find(VD); |
| 521 | if (MI != SI->MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 522 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 523 | MI->second.Components) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 524 | if (Check(L, MI->second.Kind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 525 | return true; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 526 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 527 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 530 | /// Do the check specified in \a Check to all component lists at a given level |
| 531 | /// and return true if any issue is found. |
| 532 | bool checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 533 | const ValueDecl *VD, unsigned Level, |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 534 | const llvm::function_ref< |
| 535 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 536 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 537 | Check) const { |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 538 | if (isStackEmpty()) |
| 539 | return false; |
| 540 | |
| 541 | auto StartI = Stack.back().first.begin(); |
| 542 | auto EndI = Stack.back().first.end(); |
| 543 | if (std::distance(StartI, EndI) <= (int)Level) |
| 544 | return false; |
| 545 | std::advance(StartI, Level); |
| 546 | |
| 547 | auto MI = StartI->MappedExprComponents.find(VD); |
| 548 | if (MI != StartI->MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 549 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 550 | MI->second.Components) |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 551 | if (Check(L, MI->second.Kind)) |
| 552 | return true; |
| 553 | return false; |
| 554 | } |
| 555 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 556 | /// Create a new mappable expression component list associated with a given |
| 557 | /// declaration and initialize it with the provided list of components. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 558 | void addMappableExpressionComponents( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 559 | const ValueDecl *VD, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 560 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 561 | OpenMPClauseKind WhereFoundClauseKind) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 562 | assert(!isStackEmpty() && |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 563 | "Not expecting to retrieve components from a empty stack!"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 564 | MappedExprComponentTy &MEC = |
| 565 | Stack.back().first.back().MappedExprComponents[VD]; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 566 | // Create new entry and append the new components there. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 567 | MEC.Components.resize(MEC.Components.size() + 1); |
| 568 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 569 | MEC.Kind = WhereFoundClauseKind; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 570 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 571 | |
| 572 | unsigned getNestingLevel() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 573 | assert(!isStackEmpty()); |
| 574 | return Stack.back().first.size() - 1; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 575 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 576 | void addDoacrossDependClause(OMPDependClause *C, |
| 577 | const OperatorOffsetTy &OpsOffs) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 578 | assert(!isStackEmpty() && Stack.back().first.size() > 1); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 579 | SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 580 | assert(isOpenMPWorksharingDirective(StackElem.Directive)); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 581 | StackElem.DoacrossDepends.try_emplace(C, OpsOffs); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 582 | } |
| 583 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 584 | getDoacrossDependClauses() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 585 | assert(!isStackEmpty()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 586 | const SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 587 | if (isOpenMPWorksharingDirective(StackElem.Directive)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 588 | const DoacrossDependMapTy &Ref = StackElem.DoacrossDepends; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 589 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 590 | } |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 591 | return llvm::make_range(StackElem.DoacrossDepends.end(), |
| 592 | StackElem.DoacrossDepends.end()); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 593 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | }; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 595 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 596 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 597 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 598 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 599 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 600 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 601 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 602 | static const Expr *getExprAsWritten(const Expr *E) { |
| 603 | if (const auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 604 | E = ExprTemp->getSubExpr(); |
| 605 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 606 | if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 607 | E = MTE->GetTemporaryExpr(); |
| 608 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 609 | while (const auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 610 | E = Binder->getSubExpr(); |
| 611 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 612 | if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 613 | E = ICE->getSubExprAsWritten(); |
| 614 | return E->IgnoreParens(); |
| 615 | } |
| 616 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 617 | static Expr *getExprAsWritten(Expr *E) { |
| 618 | return const_cast<Expr *>(getExprAsWritten(const_cast<const Expr *>(E))); |
| 619 | } |
| 620 | |
| 621 | static const ValueDecl *getCanonicalDecl(const ValueDecl *D) { |
| 622 | if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) |
| 623 | if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 624 | D = ME->getMemberDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 625 | const auto *VD = dyn_cast<VarDecl>(D); |
| 626 | const auto *FD = dyn_cast<FieldDecl>(D); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 627 | if (VD != nullptr) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 628 | VD = VD->getCanonicalDecl(); |
| 629 | D = VD; |
| 630 | } else { |
| 631 | assert(FD); |
| 632 | FD = FD->getCanonicalDecl(); |
| 633 | D = FD; |
| 634 | } |
| 635 | return D; |
| 636 | } |
| 637 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 638 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 639 | return const_cast<ValueDecl *>( |
| 640 | getCanonicalDecl(const_cast<const ValueDecl *>(D))); |
| 641 | } |
| 642 | |
| 643 | DSAStackTy::DSAVarData DSAStackTy::getDSA(iterator &Iter, |
| 644 | ValueDecl *D) const { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 645 | D = getCanonicalDecl(D); |
| 646 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 647 | const auto *FD = dyn_cast<FieldDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 648 | DSAVarData DVar; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 649 | if (isStackEmpty() || Iter == Stack.back().first.rend()) { |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 650 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 651 | // in a region but not in construct] |
| 652 | // File-scope or namespace-scope variables referenced in called routines |
| 653 | // in the region are shared unless they appear in a threadprivate |
| 654 | // directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 655 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(VD)) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 656 | DVar.CKind = OMPC_shared; |
| 657 | |
| 658 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 659 | // in a region but not in construct] |
| 660 | // Variables with static storage duration that are declared in called |
| 661 | // routines in the region are shared. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 662 | if (VD && VD->hasGlobalStorage()) |
| 663 | DVar.CKind = OMPC_shared; |
| 664 | |
| 665 | // Non-static data members are shared by default. |
| 666 | if (FD) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 667 | DVar.CKind = OMPC_shared; |
| 668 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 669 | return DVar; |
| 670 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 671 | |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 672 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 673 | // in a Construct, C/C++, predetermined, p.1] |
| 674 | // Variables with automatic storage duration that are declared in a scope |
| 675 | // inside the construct are private. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 676 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 677 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 678 | DVar.CKind = OMPC_private; |
| 679 | return DVar; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 682 | DVar.DKind = Iter->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 683 | // Explicitly specified attributes and local variables with predetermined |
| 684 | // attributes. |
| 685 | if (Iter->SharingMap.count(D)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 686 | const DSAInfo &Data = Iter->SharingMap.lookup(D); |
| 687 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 688 | DVar.PrivateCopy = Data.PrivateCopy; |
| 689 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 690 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 691 | return DVar; |
| 692 | } |
| 693 | |
| 694 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 695 | // in a Construct, C/C++, implicitly determined, p.1] |
| 696 | // In a parallel or task construct, the data-sharing attributes of these |
| 697 | // variables are determined by the default clause, if present. |
| 698 | switch (Iter->DefaultAttr) { |
| 699 | case DSA_shared: |
| 700 | DVar.CKind = OMPC_shared; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 701 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 702 | return DVar; |
| 703 | case DSA_none: |
| 704 | return DVar; |
| 705 | case DSA_unspecified: |
| 706 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 707 | // in a Construct, implicitly determined, p.2] |
| 708 | // In a parallel construct, if no default clause is present, these |
| 709 | // variables are shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 710 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 711 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 712 | isOpenMPTeamsDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 713 | DVar.CKind = OMPC_shared; |
| 714 | return DVar; |
| 715 | } |
| 716 | |
| 717 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 718 | // in a Construct, implicitly determined, p.4] |
| 719 | // In a task construct, if no default clause is present, a variable that in |
| 720 | // the enclosing context is determined to be shared by all implicit tasks |
| 721 | // bound to the current team is shared. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 722 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 723 | DSAVarData DVarTemp; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 724 | iterator I = Iter, E = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 725 | do { |
| 726 | ++I; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 727 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 728 | // Referenced in a Construct, implicitly determined, p.6] |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 729 | // In a task construct, if no default clause is present, a variable |
| 730 | // whose data-sharing attribute is not determined by the rules above is |
| 731 | // firstprivate. |
| 732 | DVarTemp = getDSA(I, D); |
| 733 | if (DVarTemp.CKind != OMPC_shared) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 734 | DVar.RefExpr = nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 735 | DVar.CKind = OMPC_firstprivate; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 736 | return DVar; |
| 737 | } |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 738 | } while (I != E && !isParallelOrTaskRegion(I->Directive)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 739 | DVar.CKind = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 740 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 741 | return DVar; |
| 742 | } |
| 743 | } |
| 744 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 745 | // in a Construct, implicitly determined, p.3] |
| 746 | // For constructs other than task, if no default clause is present, these |
| 747 | // variables inherit their data-sharing attributes from the enclosing |
| 748 | // context. |
| Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 749 | return getDSA(++Iter, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 752 | const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D, |
| 753 | const Expr *NewDE) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 754 | assert(!isStackEmpty() && "Data sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 755 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 756 | SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 757 | auto It = StackElem.AlignedMap.find(D); |
| 758 | if (It == StackElem.AlignedMap.end()) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 759 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 760 | StackElem.AlignedMap[D] = NewDE; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 761 | return nullptr; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 762 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 763 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 764 | return It->second; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 767 | void DSAStackTy::addLoopControlVariable(const ValueDecl *D, VarDecl *Capture) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 768 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 769 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 770 | SharingMapTy &StackElem = Stack.back().first.back(); |
| 771 | StackElem.LCVMap.try_emplace( |
| 772 | D, LCDeclInfo(StackElem.LCVMap.size() + 1, Capture)); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 775 | const DSAStackTy::LCDeclInfo |
| 776 | DSAStackTy::isLoopControlVariable(const ValueDecl *D) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 777 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 778 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 779 | const SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 780 | auto It = StackElem.LCVMap.find(D); |
| 781 | if (It != StackElem.LCVMap.end()) |
| 782 | return It->second; |
| 783 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 786 | const DSAStackTy::LCDeclInfo |
| 787 | DSAStackTy::isParentLoopControlVariable(const ValueDecl *D) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 788 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 789 | "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 790 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 791 | const SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 792 | auto It = StackElem.LCVMap.find(D); |
| 793 | if (It != StackElem.LCVMap.end()) |
| 794 | return It->second; |
| 795 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 798 | const ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 799 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 800 | "Data-sharing attributes stack is empty"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 801 | const SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 802 | if (StackElem.LCVMap.size() < I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 803 | return nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 804 | for (const auto &Pair : StackElem.LCVMap) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 805 | if (Pair.second.first == I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 806 | return Pair.first; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 807 | return nullptr; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 810 | void DSAStackTy::addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 811 | DeclRefExpr *PrivateCopy) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 812 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 813 | if (A == OMPC_threadprivate) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 814 | DSAInfo &Data = Threadprivates[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 815 | Data.Attributes = A; |
| 816 | Data.RefExpr.setPointer(E); |
| 817 | Data.PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 818 | } else { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 819 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 820 | DSAInfo &Data = Stack.back().first.back().SharingMap[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 821 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 822 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 823 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 824 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 825 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 826 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 827 | return; |
| 828 | } |
| 829 | const bool IsLastprivate = |
| 830 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 831 | Data.Attributes = A; |
| 832 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 833 | Data.PrivateCopy = PrivateCopy; |
| 834 | if (PrivateCopy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 835 | DSAInfo &Data = |
| 836 | Stack.back().first.back().SharingMap[PrivateCopy->getDecl()]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 837 | Data.Attributes = A; |
| 838 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 839 | Data.PrivateCopy = nullptr; |
| 840 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 844 | /// Build a variable declaration for OpenMP loop iteration variable. |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 845 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 846 | StringRef Name, const AttrVec *Attrs = nullptr, |
| 847 | DeclRefExpr *OrigRef = nullptr) { |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 848 | DeclContext *DC = SemaRef.CurContext; |
| 849 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 850 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 851 | auto *Decl = |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 852 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 853 | if (Attrs) { |
| 854 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 855 | I != E; ++I) |
| 856 | Decl->addAttr(*I); |
| 857 | } |
| 858 | Decl->setImplicit(); |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 859 | if (OrigRef) { |
| 860 | Decl->addAttr( |
| 861 | OMPReferencedVarAttr::CreateImplicit(SemaRef.Context, OrigRef)); |
| 862 | } |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 863 | return Decl; |
| 864 | } |
| 865 | |
| 866 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 867 | SourceLocation Loc, |
| 868 | bool RefersToCapture = false) { |
| 869 | D->setReferenced(); |
| 870 | D->markUsed(S.Context); |
| 871 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 872 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 873 | VK_LValue); |
| 874 | } |
| 875 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 876 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 877 | BinaryOperatorKind BOK) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 878 | D = getCanonicalDecl(D); |
| 879 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 880 | assert( |
| Richard Trieu | 09f1411 | 2017-07-21 21:29:35 +0000 | [diff] [blame] | 881 | Stack.back().first.back().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 882 | "Additional reduction info may be specified only for reduction items."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 883 | ReductionData &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 884 | assert(ReductionData.ReductionRange.isInvalid() && |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 885 | Stack.back().first.back().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 886 | "Additional reduction info may be specified only once for reduction " |
| 887 | "items."); |
| 888 | ReductionData.set(BOK, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 889 | Expr *&TaskgroupReductionRef = |
| 890 | Stack.back().first.back().TaskgroupReductionRef; |
| 891 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 892 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 893 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 894 | TaskgroupReductionRef = |
| 895 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 896 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 899 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 900 | const Expr *ReductionRef) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 901 | D = getCanonicalDecl(D); |
| 902 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 903 | assert( |
| Richard Trieu | 09f1411 | 2017-07-21 21:29:35 +0000 | [diff] [blame] | 904 | Stack.back().first.back().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 905 | "Additional reduction info may be specified only for reduction items."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 906 | ReductionData &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 907 | assert(ReductionData.ReductionRange.isInvalid() && |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 908 | Stack.back().first.back().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 909 | "Additional reduction info may be specified only once for reduction " |
| 910 | "items."); |
| 911 | ReductionData.set(ReductionRef, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 912 | Expr *&TaskgroupReductionRef = |
| 913 | Stack.back().first.back().TaskgroupReductionRef; |
| 914 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 915 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 916 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 917 | TaskgroupReductionRef = |
| 918 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 919 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 922 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 923 | const ValueDecl *D, SourceRange &SR, BinaryOperatorKind &BOK, |
| 924 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 925 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 926 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| 927 | if (Stack.back().first.empty()) |
| 928 | return DSAVarData(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 929 | for (iterator I = std::next(Stack.back().first.rbegin(), 1), |
| 930 | E = Stack.back().first.rend(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 931 | I != E; std::advance(I, 1)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 932 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 933 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 934 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 935 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 936 | if (!ReductionData.ReductionOp || |
| 937 | ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 938 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 939 | SR = ReductionData.ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 940 | BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 941 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 942 | "expression for the descriptor is not " |
| 943 | "set."); |
| 944 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 945 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 946 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 947 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 948 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 951 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 952 | const ValueDecl *D, SourceRange &SR, const Expr *&ReductionRef, |
| 953 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 954 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 955 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| 956 | if (Stack.back().first.empty()) |
| 957 | return DSAVarData(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 958 | for (iterator I = std::next(Stack.back().first.rbegin(), 1), |
| 959 | E = Stack.back().first.rend(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 960 | I != E; std::advance(I, 1)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 961 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 962 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 963 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 964 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 965 | if (!ReductionData.ReductionOp || |
| 966 | !ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 967 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 968 | SR = ReductionData.ReductionRange; |
| 969 | ReductionRef = ReductionData.ReductionOp.get<const Expr *>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 970 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 971 | "expression for the descriptor is not " |
| 972 | "set."); |
| 973 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 974 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 975 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 976 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 977 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 980 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, iterator Iter) const { |
| Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 981 | D = D->getCanonicalDecl(); |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 982 | if (!isStackEmpty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 983 | iterator I = Iter, E = Stack.back().first.rend(); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 984 | Scope *TopScope = nullptr; |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 985 | while (I != E && !isParallelOrTaskRegion(I->Directive) && |
| 986 | !isOpenMPTargetExecutionDirective(I->Directive)) |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 987 | ++I; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 988 | if (I == E) |
| 989 | return false; |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 990 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 991 | Scope *CurScope = getCurScope(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 992 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 993 | CurScope = CurScope->getParent(); |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 994 | return CurScope != TopScope; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 995 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 996 | return false; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 999 | const DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, |
| 1000 | bool FromParent) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1001 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1002 | DSAVarData DVar; |
| 1003 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1004 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1005 | auto TI = Threadprivates.find(D); |
| 1006 | if (TI != Threadprivates.end()) { |
| 1007 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1008 | DVar.CKind = OMPC_threadprivate; |
| 1009 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1010 | } |
| 1011 | if (VD && VD->hasAttr<OMPThreadPrivateDeclAttr>()) { |
| Alexey Bataev | 817d7f3 | 2017-11-14 21:01:01 +0000 | [diff] [blame] | 1012 | DVar.RefExpr = buildDeclRefExpr( |
| 1013 | SemaRef, VD, D->getType().getNonReferenceType(), |
| 1014 | VD->getAttr<OMPThreadPrivateDeclAttr>()->getLocation()); |
| 1015 | DVar.CKind = OMPC_threadprivate; |
| 1016 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1017 | return DVar; |
| 1018 | } |
| 1019 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1020 | // in a Construct, C/C++, predetermined, p.1] |
| 1021 | // Variables appearing in threadprivate directives are threadprivate. |
| 1022 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 1023 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1024 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 1025 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
| 1026 | (VD && VD->getStorageClass() == SC_Register && |
| 1027 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 1028 | DVar.RefExpr = buildDeclRefExpr( |
| 1029 | SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation()); |
| 1030 | DVar.CKind = OMPC_threadprivate; |
| 1031 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| 1032 | return DVar; |
| 1033 | } |
| 1034 | if (SemaRef.getLangOpts().OpenMPCUDAMode && VD && |
| 1035 | VD->isLocalVarDeclOrParm() && !isStackEmpty() && |
| 1036 | !isLoopControlVariable(D).first) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1037 | iterator IterTarget = |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1038 | std::find_if(Stack.back().first.rbegin(), Stack.back().first.rend(), |
| 1039 | [](const SharingMapTy &Data) { |
| 1040 | return isOpenMPTargetExecutionDirective(Data.Directive); |
| 1041 | }); |
| 1042 | if (IterTarget != Stack.back().first.rend()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1043 | iterator ParentIterTarget = std::next(IterTarget, 1); |
| 1044 | for (iterator Iter = Stack.back().first.rbegin(); |
| 1045 | Iter != ParentIterTarget; std::advance(Iter, 1)) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1046 | if (isOpenMPLocal(VD, Iter)) { |
| 1047 | DVar.RefExpr = |
| 1048 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1049 | D->getLocation()); |
| 1050 | DVar.CKind = OMPC_threadprivate; |
| 1051 | return DVar; |
| 1052 | } |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1053 | } |
| 1054 | if (!isClauseParsingMode() || IterTarget != Stack.back().first.rbegin()) { |
| 1055 | auto DSAIter = IterTarget->SharingMap.find(D); |
| 1056 | if (DSAIter != IterTarget->SharingMap.end() && |
| 1057 | isOpenMPPrivate(DSAIter->getSecond().Attributes)) { |
| 1058 | DVar.RefExpr = DSAIter->getSecond().RefExpr.getPointer(); |
| 1059 | DVar.CKind = OMPC_threadprivate; |
| 1060 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1061 | } |
| 1062 | iterator End = Stack.back().first.rend(); |
| 1063 | if (!SemaRef.isOpenMPCapturedByRef( |
| 1064 | D, std::distance(ParentIterTarget, End))) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1065 | DVar.RefExpr = |
| 1066 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1067 | IterTarget->ConstructLoc); |
| 1068 | DVar.CKind = OMPC_threadprivate; |
| 1069 | return DVar; |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1075 | if (isStackEmpty()) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1076 | // Not in OpenMP execution region and top scope was already checked. |
| 1077 | return DVar; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1078 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1079 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1080 | // in a Construct, C/C++, predetermined, p.4] |
| 1081 | // Static data members are shared. |
| 1082 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1083 | // in a Construct, C/C++, predetermined, p.7] |
| 1084 | // Variables with static storage duration that are declared in a scope |
| 1085 | // inside the construct are shared. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1086 | auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; }; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1087 | if (VD && VD->isStaticDataMember()) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1088 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1089 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1090 | return DVar; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1091 | |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1092 | DVar.CKind = OMPC_shared; |
| 1093 | return DVar; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 1097 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 1098 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1099 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1100 | // in a Construct, C/C++, predetermined, p.6] |
| 1101 | // Variables with const qualified type having no mutable member are |
| 1102 | // shared. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1103 | const CXXRecordDecl *RD = |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1104 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1105 | if (const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 1106 | if (const ClassTemplateDecl *CTD = CTSD->getSpecializedTemplate()) |
| Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 1107 | RD = CTD->getTemplatedDecl(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1108 | if (IsConstant && |
| Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 1109 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 1110 | RD->hasMutableFields())) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1111 | // Variables with const-qualified type having no mutable member may be |
| 1112 | // listed in a firstprivate clause, even if they are static data members. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1113 | DSAVarData DVarTemp = |
| 1114 | hasDSA(D, [](OpenMPClauseKind C) { return C == OMPC_firstprivate; }, |
| 1115 | MatchesAlways, FromParent); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1116 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| Alexey Bataev | 9a75738 | 2018-02-16 19:16:54 +0000 | [diff] [blame] | 1117 | return DVarTemp; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1118 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1119 | DVar.CKind = OMPC_shared; |
| 1120 | return DVar; |
| 1121 | } |
| 1122 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1123 | // Explicitly specified attributes and local variables with predetermined |
| 1124 | // attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1125 | iterator I = Stack.back().first.rbegin(); |
| 1126 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1127 | if (FromParent && I != EndI) |
| 1128 | std::advance(I, 1); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1129 | auto It = I->SharingMap.find(D); |
| 1130 | if (It != I->SharingMap.end()) { |
| 1131 | const DSAInfo &Data = It->getSecond(); |
| 1132 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 1133 | DVar.PrivateCopy = Data.PrivateCopy; |
| 1134 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1135 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 1136 | DVar.DKind = I->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | return DVar; |
| 1140 | } |
| 1141 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1142 | const DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 1143 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1144 | if (isStackEmpty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1145 | iterator I; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1146 | return getDSA(I, D); |
| 1147 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1148 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1149 | iterator StartI = Stack.back().first.rbegin(); |
| 1150 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1151 | if (FromParent && StartI != EndI) |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1152 | std::advance(StartI, 1); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1153 | return getDSA(StartI, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1156 | const DSAStackTy::DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1157 | DSAStackTy::hasDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1158 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1159 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1160 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1161 | if (isStackEmpty()) |
| 1162 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1163 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1164 | iterator I = Stack.back().first.rbegin(); |
| 1165 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1166 | if (FromParent && I != EndI) |
| Alexey Bataev | 0e6fc1c | 2017-04-27 14:46:26 +0000 | [diff] [blame] | 1167 | std::advance(I, 1); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1168 | for (; I != EndI; std::advance(I, 1)) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1169 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1170 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1171 | iterator NewI = I; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1172 | DSAVarData DVar = getDSA(NewI, D); |
| 1173 | if (I == NewI && CPred(DVar.CKind)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1174 | return DVar; |
| Alexey Bataev | 60859c0 | 2017-04-27 15:10:33 +0000 | [diff] [blame] | 1175 | } |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1176 | return {}; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1179 | const DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1180 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1181 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1182 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1183 | if (isStackEmpty()) |
| 1184 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1185 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1186 | iterator StartI = Stack.back().first.rbegin(); |
| 1187 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1188 | if (FromParent && StartI != EndI) |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1189 | std::advance(StartI, 1); |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1190 | if (StartI == EndI || !DPred(StartI->Directive)) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1191 | return {}; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1192 | iterator NewI = StartI; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1193 | DSAVarData DVar = getDSA(NewI, D); |
| 1194 | return (NewI == StartI && CPred(DVar.CKind)) ? DVar : DSAVarData(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1197 | bool DSAStackTy::hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1198 | const ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1199 | unsigned Level, bool NotLastprivate) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1200 | if (isStackEmpty()) |
| 1201 | return false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1202 | D = getCanonicalDecl(D); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1203 | auto StartI = Stack.back().first.begin(); |
| 1204 | auto EndI = Stack.back().first.end(); |
| NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 1205 | if (std::distance(StartI, EndI) <= (int)Level) |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1206 | return false; |
| 1207 | std::advance(StartI, Level); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1208 | auto I = StartI->SharingMap.find(D); |
| 1209 | return (I != StartI->SharingMap.end()) && |
| 1210 | I->getSecond().RefExpr.getPointer() && |
| 1211 | CPred(I->getSecond().Attributes) && |
| 1212 | (!NotLastprivate || !I->getSecond().RefExpr.getInt()); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1215 | bool DSAStackTy::hasExplicitDirective( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1216 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 1217 | unsigned Level) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1218 | if (isStackEmpty()) |
| 1219 | return false; |
| 1220 | auto StartI = Stack.back().first.begin(); |
| 1221 | auto EndI = Stack.back().first.end(); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1222 | if (std::distance(StartI, EndI) <= (int)Level) |
| 1223 | return false; |
| 1224 | std::advance(StartI, Level); |
| 1225 | return DPred(StartI->Directive); |
| 1226 | } |
| 1227 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1228 | bool DSAStackTy::hasDirective( |
| 1229 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 1230 | const DeclarationNameInfo &, SourceLocation)> |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1231 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1232 | bool FromParent) const { |
| Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1233 | // We look only in the enclosing region. |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1234 | if (isStackEmpty()) |
| Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1235 | return false; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1236 | auto StartI = std::next(Stack.back().first.rbegin()); |
| 1237 | auto EndI = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1238 | if (FromParent && StartI != EndI) |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1239 | StartI = std::next(StartI); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1240 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 1241 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 1242 | return true; |
| 1243 | } |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1247 | void Sema::InitDataSharingAttributesStack() { |
| 1248 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 1249 | } |
| 1250 | |
| 1251 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 1252 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1253 | void Sema::pushOpenMPFunctionRegion() { |
| 1254 | DSAStack->pushFunction(); |
| 1255 | } |
| 1256 | |
| 1257 | void Sema::popOpenMPFunctionRegion(const FunctionScopeInfo *OldFSI) { |
| 1258 | DSAStack->popFunction(OldFSI); |
| 1259 | } |
| 1260 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1261 | bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level) const { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1262 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1263 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1264 | ASTContext &Ctx = getASTContext(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1265 | bool IsByRef = true; |
| 1266 | |
| 1267 | // Find the directive that is associated with the provided scope. |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 1268 | D = cast<ValueDecl>(D->getCanonicalDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1269 | QualType Ty = D->getType(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1270 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1271 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1272 | // This table summarizes how a given variable should be passed to the device |
| 1273 | // given its type and the clauses where it appears. This table is based on |
| 1274 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 1275 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 1276 | // |
| 1277 | // ========================================================================= |
| 1278 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 1279 | // | |(tofrom:scalar)| | pvt | | | | |
| 1280 | // ========================================================================= |
| 1281 | // | scl | | | | - | | bycopy| |
| 1282 | // | scl | | - | x | - | - | bycopy| |
| 1283 | // | scl | | x | - | - | - | null | |
| 1284 | // | scl | x | | | - | | byref | |
| 1285 | // | scl | x | - | x | - | - | bycopy| |
| 1286 | // | scl | x | x | - | - | - | null | |
| 1287 | // | scl | | - | - | - | x | byref | |
| 1288 | // | scl | x | - | - | - | x | byref | |
| 1289 | // |
| 1290 | // | agg | n.a. | | | - | | byref | |
| 1291 | // | agg | n.a. | - | x | - | - | byref | |
| 1292 | // | agg | n.a. | x | - | - | - | null | |
| 1293 | // | agg | n.a. | - | - | - | x | byref | |
| 1294 | // | agg | n.a. | - | - | - | x[] | byref | |
| 1295 | // |
| 1296 | // | ptr | n.a. | | | - | | bycopy| |
| 1297 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 1298 | // | ptr | n.a. | x | - | - | - | null | |
| 1299 | // | ptr | n.a. | - | - | - | x | byref | |
| 1300 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 1301 | // | ptr | n.a. | - | - | x | | bycopy| |
| 1302 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 1303 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 1304 | // ========================================================================= |
| 1305 | // Legend: |
| 1306 | // scl - scalar |
| 1307 | // ptr - pointer |
| 1308 | // agg - aggregate |
| 1309 | // x - applies |
| 1310 | // - - invalid in this combination |
| 1311 | // [] - mapped with an array section |
| 1312 | // byref - should be mapped by reference |
| 1313 | // byval - should be mapped by value |
| 1314 | // null - initialize a local variable to null on the device |
| 1315 | // |
| 1316 | // Observations: |
| 1317 | // - All scalar declarations that show up in a map clause have to be passed |
| 1318 | // by reference, because they may have been mapped in the enclosing data |
| 1319 | // environment. |
| 1320 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 1321 | // passed by reference, regardless the result in the table above. |
| 1322 | // - For pointers mapped by value that have either an implicit map or an |
| 1323 | // array section, the runtime library may pass the NULL value to the |
| 1324 | // device instead of the value passed to it by the compiler. |
| 1325 | |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1326 | if (Ty->isReferenceType()) |
| 1327 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1328 | |
| 1329 | // Locate map clauses and see if the variable being captured is referred to |
| 1330 | // in any of those clauses. Here we only care about variables, not fields, |
| 1331 | // because fields are part of aggregates. |
| 1332 | bool IsVariableUsedInMapClause = false; |
| 1333 | bool IsVariableAssociatedWithSection = false; |
| 1334 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 1335 | DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1336 | D, Level, |
| 1337 | [&IsVariableUsedInMapClause, &IsVariableAssociatedWithSection, D]( |
| 1338 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1339 | MapExprComponents, |
| 1340 | OpenMPClauseKind WhereFoundClauseKind) { |
| 1341 | // Only the map clause information influences how a variable is |
| 1342 | // captured. E.g. is_device_ptr does not require changing the default |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 1343 | // behavior. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1344 | if (WhereFoundClauseKind != OMPC_map) |
| 1345 | return false; |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1346 | |
| 1347 | auto EI = MapExprComponents.rbegin(); |
| 1348 | auto EE = MapExprComponents.rend(); |
| 1349 | |
| 1350 | assert(EI != EE && "Invalid map expression!"); |
| 1351 | |
| 1352 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 1353 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 1354 | |
| 1355 | ++EI; |
| 1356 | if (EI == EE) |
| 1357 | return false; |
| 1358 | |
| 1359 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 1360 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 1361 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 1362 | IsVariableAssociatedWithSection = true; |
| 1363 | // There is nothing more we need to know about this variable. |
| 1364 | return true; |
| 1365 | } |
| 1366 | |
| 1367 | // Keep looking for more map info. |
| 1368 | return false; |
| 1369 | }); |
| 1370 | |
| 1371 | if (IsVariableUsedInMapClause) { |
| 1372 | // If variable is identified in a map clause it is always captured by |
| 1373 | // reference except if it is a pointer that is dereferenced somehow. |
| 1374 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 1375 | } else { |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1376 | // By default, all the data that has a scalar type is mapped by copy |
| 1377 | // (except for reduction variables). |
| 1378 | IsByRef = |
| 1379 | !Ty->isScalarType() || |
| 1380 | DSAStack->getDefaultDMAAtLevel(Level) == DMA_tofrom_scalar || |
| 1381 | DSAStack->hasExplicitDSA( |
| 1382 | D, [](OpenMPClauseKind K) { return K == OMPC_reduction; }, Level); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1383 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1386 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 1387 | IsByRef = |
| 1388 | !DSAStack->hasExplicitDSA( |
| 1389 | D, |
| 1390 | [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 1391 | Level, /*NotLastprivate=*/true) && |
| 1392 | // If the variable is artificial and must be captured by value - try to |
| 1393 | // capture by value. |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 1394 | !(isa<OMPCapturedExprDecl>(D) && !D->hasAttr<OMPCaptureNoInitAttr>() && |
| 1395 | !cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1398 | // 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] | 1399 | // and alignment, because the runtime library only deals with uintptr types. |
| 1400 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 1401 | // instead. |
| 1402 | if (!IsByRef && |
| 1403 | (Ctx.getTypeSizeInChars(Ty) > |
| 1404 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1405 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1406 | IsByRef = true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1407 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1408 | |
| 1409 | return IsByRef; |
| 1410 | } |
| 1411 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1412 | unsigned Sema::getOpenMPNestingLevel() const { |
| 1413 | assert(getLangOpts().OpenMP); |
| 1414 | return DSAStack->getNestingLevel(); |
| 1415 | } |
| 1416 | |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 1417 | bool Sema::isInOpenMPTargetExecutionDirective() const { |
| 1418 | return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) && |
| 1419 | !DSAStack->isClauseParsingMode()) || |
| 1420 | DSAStack->hasDirective( |
| 1421 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1422 | SourceLocation) -> bool { |
| 1423 | return isOpenMPTargetExecutionDirective(K); |
| 1424 | }, |
| 1425 | false); |
| 1426 | } |
| 1427 | |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1428 | VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D) { |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1429 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1430 | D = getCanonicalDecl(D); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1431 | |
| 1432 | // If we are attempting to capture a global variable in a directive with |
| 1433 | // 'target' we return true so that this global is also mapped to the device. |
| 1434 | // |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1435 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1436 | if (VD && !VD->hasLocalStorage()) { |
| 1437 | if (isInOpenMPDeclareTargetContext() && |
| 1438 | (getCurCapturedRegion() || getCurBlock() || getCurLambda())) { |
| 1439 | // Try to mark variable as declare target if it is used in capturing |
| 1440 | // regions. |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1441 | if (!OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1442 | checkDeclIsAllowedInOpenMPTarget(nullptr, VD); |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1443 | return nullptr; |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1444 | } else if (isInOpenMPTargetExecutionDirective()) { |
| 1445 | // If the declaration is enclosed in a 'declare target' directive, |
| 1446 | // then it should not be captured. |
| 1447 | // |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1448 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1449 | return nullptr; |
| 1450 | return VD; |
| 1451 | } |
| Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1452 | } |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1453 | |
| Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1454 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1455 | (!DSAStack->isClauseParsingMode() || |
| 1456 | DSAStack->getParentDirective() != OMPD_unknown)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1457 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1458 | if (Info.first || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1459 | (VD && VD->hasLocalStorage() && |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1460 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1461 | (VD && DSAStack->isForceVarCapturing())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1462 | return VD ? VD : Info.second; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1463 | DSAStackTy::DSAVarData DVarPrivate = |
| 1464 | DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1465 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1466 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1467 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, |
| 1468 | [](OpenMPDirectiveKind) { return true; }, |
| 1469 | DSAStack->isClauseParsingMode()); |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1470 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1471 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1472 | } |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1473 | return nullptr; |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 1476 | void Sema::adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
| 1477 | unsigned Level) const { |
| 1478 | SmallVector<OpenMPDirectiveKind, 4> Regions; |
| 1479 | getOpenMPCaptureRegions(Regions, DSAStack->getDirective(Level)); |
| 1480 | FunctionScopesIndex -= Regions.size(); |
| 1481 | } |
| 1482 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1483 | bool Sema::isOpenMPPrivateDecl(const ValueDecl *D, unsigned Level) const { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1484 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1485 | return DSAStack->hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1486 | D, [](OpenMPClauseKind K) { return K == OMPC_private; }, Level) || |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 1487 | (DSAStack->isClauseParsingMode() && |
| 1488 | DSAStack->getClauseParsingMode() == OMPC_private) || |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1489 | // Consider taskgroup reduction descriptor variable a private to avoid |
| 1490 | // possible capture in the region. |
| 1491 | (DSAStack->hasExplicitDirective( |
| 1492 | [](OpenMPDirectiveKind K) { return K == OMPD_taskgroup; }, |
| 1493 | Level) && |
| 1494 | DSAStack->isTaskgroupReductionRef(D, Level)); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1497 | void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, |
| 1498 | unsigned Level) { |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1499 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1500 | D = getCanonicalDecl(D); |
| 1501 | OpenMPClauseKind OMPC = OMPC_unknown; |
| 1502 | for (unsigned I = DSAStack->getNestingLevel() + 1; I > Level; --I) { |
| 1503 | const unsigned NewLevel = I - 1; |
| 1504 | if (DSAStack->hasExplicitDSA(D, |
| 1505 | [&OMPC](const OpenMPClauseKind K) { |
| 1506 | if (isOpenMPPrivate(K)) { |
| 1507 | OMPC = K; |
| 1508 | return true; |
| 1509 | } |
| 1510 | return false; |
| 1511 | }, |
| 1512 | NewLevel)) |
| 1513 | break; |
| 1514 | if (DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| 1515 | D, NewLevel, |
| 1516 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 1517 | OpenMPClauseKind) { return true; })) { |
| 1518 | OMPC = OMPC_map; |
| 1519 | break; |
| 1520 | } |
| 1521 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1522 | NewLevel)) { |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1523 | OMPC = OMPC_map; |
| 1524 | if (D->getType()->isScalarType() && |
| 1525 | DSAStack->getDefaultDMAAtLevel(NewLevel) != |
| 1526 | DefaultMapAttributes::DMA_tofrom_scalar) |
| 1527 | OMPC = OMPC_firstprivate; |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | } |
| 1530 | } |
| 1531 | if (OMPC != OMPC_unknown) |
| 1532 | FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, OMPC)); |
| 1533 | } |
| 1534 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1535 | bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, |
| 1536 | unsigned Level) const { |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1537 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1538 | // Return true if the current level is no longer enclosed in a target region. |
| 1539 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1540 | const auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1541 | return VD && !VD->hasLocalStorage() && |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1542 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1543 | Level); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1546 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1547 | |
| 1548 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1549 | const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1550 | Scope *CurScope, SourceLocation Loc) { |
| 1551 | DSAStack->push(DKind, DirName, CurScope, Loc); |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 1552 | PushExpressionEvaluationContext( |
| 1553 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1556 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1557 | DSAStack->setClauseParsingMode(K); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1560 | void Sema::EndOpenMPClause() { |
| 1561 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1564 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1565 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1566 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1567 | // clause requires an accessible, unambiguous default constructor for the |
| 1568 | // class type, unless the list item is also specified in a firstprivate |
| 1569 | // clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1570 | if (const auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
| 1571 | for (OMPClause *C : D->clauses()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1572 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1573 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1574 | for (Expr *DE : Clause->varlists()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1575 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1576 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1577 | continue; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1578 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1579 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1580 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1581 | QualType Type = VD->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1582 | const DSAStackTy::DSAVarData DVar = |
| 1583 | DSAStack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1584 | if (DVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1585 | // Generate helper private variable and initialize it with the |
| 1586 | // default value. The address of the original variable is replaced |
| 1587 | // by the address of the new private variable in CodeGen. This new |
| 1588 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1589 | // region uses original variable for proper diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1590 | VarDecl *VDPrivate = buildVarDecl( |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1591 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1592 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr, DRE); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1593 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1594 | if (VDPrivate->isInvalidDecl()) |
| 1595 | continue; |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1596 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1597 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1598 | } else { |
| 1599 | // The variable is also a firstprivate, so initialization sequence |
| 1600 | // for private copy is generated already. |
| 1601 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1602 | } |
| 1603 | } |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1604 | // Set initializers to private copies if no errors were found. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1605 | if (PrivateCopies.size() == Clause->varlist_size()) |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1606 | Clause->setPrivateCopies(PrivateCopies); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1611 | DSAStack->pop(); |
| 1612 | DiscardCleanupsInEvaluationContext(); |
| 1613 | PopExpressionEvaluationContext(); |
| 1614 | } |
| 1615 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1616 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1617 | Expr *NumIterations, Sema &SemaRef, |
| 1618 | Scope *S, DSAStackTy *Stack); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1619 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1620 | namespace { |
| 1621 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1622 | class VarDeclFilterCCC final : public CorrectionCandidateCallback { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1623 | private: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1624 | Sema &SemaRef; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1625 | |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1626 | public: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1627 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1628 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1629 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1630 | if (const auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1631 | return VD->hasGlobalStorage() && |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1632 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1633 | SemaRef.getCurScope()); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1634 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1635 | return false; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1636 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1637 | }; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1638 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1639 | class VarOrFuncDeclFilterCCC final : public CorrectionCandidateCallback { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1640 | private: |
| 1641 | Sema &SemaRef; |
| 1642 | |
| 1643 | public: |
| 1644 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1645 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1646 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Kelvin Li | 59e3d19 | 2017-11-30 18:52:06 +0000 | [diff] [blame] | 1647 | if (ND && (isa<VarDecl>(ND) || isa<FunctionDecl>(ND))) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1648 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1649 | SemaRef.getCurScope()); |
| 1650 | } |
| 1651 | return false; |
| 1652 | } |
| 1653 | }; |
| 1654 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1655 | } // namespace |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1656 | |
| 1657 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1658 | CXXScopeSpec &ScopeSpec, |
| 1659 | const DeclarationNameInfo &Id) { |
| 1660 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1661 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1662 | |
| 1663 | if (Lookup.isAmbiguous()) |
| 1664 | return ExprError(); |
| 1665 | |
| 1666 | VarDecl *VD; |
| 1667 | if (!Lookup.isSingleResult()) { |
| Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1668 | if (TypoCorrection Corrected = CorrectTypo( |
| 1669 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1670 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1671 | diagnoseTypo(Corrected, |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1672 | PDiag(Lookup.empty() |
| 1673 | ? diag::err_undeclared_var_use_suggest |
| 1674 | : diag::err_omp_expected_var_arg_suggest) |
| 1675 | << Id.getName()); |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1676 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1677 | } else { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1678 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1679 | : diag::err_omp_expected_var_arg) |
| 1680 | << Id.getName(); |
| 1681 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1682 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1683 | } else if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
| 1684 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
| 1685 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1686 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1687 | } |
| 1688 | Lookup.suppressDiagnostics(); |
| 1689 | |
| 1690 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1691 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1692 | if (!VD->hasGlobalStorage()) { |
| 1693 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1694 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1695 | bool IsDecl = |
| 1696 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1697 | Diag(VD->getLocation(), |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1698 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1699 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1700 | return ExprError(); |
| 1701 | } |
| 1702 | |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1703 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1704 | NamedDecl *ND = CanonicalVD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1705 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1706 | // A threadprivate directive for file-scope variables must appear outside |
| 1707 | // any definition or declaration. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1708 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1709 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1710 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1711 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1712 | bool IsDecl = |
| 1713 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1714 | Diag(VD->getLocation(), |
| 1715 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1716 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1717 | return ExprError(); |
| 1718 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1719 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1720 | // A threadprivate directive for static class member variables must appear |
| 1721 | // in the class definition, in the same scope in which the member |
| 1722 | // variables are declared. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1723 | if (CanonicalVD->isStaticDataMember() && |
| 1724 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1725 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1726 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1727 | bool IsDecl = |
| 1728 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1729 | Diag(VD->getLocation(), |
| 1730 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1731 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1732 | return ExprError(); |
| 1733 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1734 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1735 | // A threadprivate directive for namespace-scope variables must appear |
| 1736 | // outside any definition or declaration other than the namespace |
| 1737 | // definition itself. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1738 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1739 | (!getCurLexicalContext()->isFileContext() || |
| 1740 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1741 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1742 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1743 | bool IsDecl = |
| 1744 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1745 | Diag(VD->getLocation(), |
| 1746 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1747 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1748 | return ExprError(); |
| 1749 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1750 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1751 | // A threadprivate directive for static block-scope variables must appear |
| 1752 | // in the scope of the variable and not in a nested scope. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1753 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1754 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1755 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1756 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1757 | bool IsDecl = |
| 1758 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1759 | Diag(VD->getLocation(), |
| 1760 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1761 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1762 | return ExprError(); |
| 1763 | } |
| 1764 | |
| 1765 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1766 | // A threadprivate directive must lexically precede all references to any |
| 1767 | // of the variables in its list. |
| Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1768 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1769 | Diag(Id.getLoc(), diag::err_omp_var_used) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1770 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1771 | return ExprError(); |
| 1772 | } |
| 1773 | |
| 1774 | QualType ExprType = VD->getType().getNonReferenceType(); |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1775 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1776 | SourceLocation(), VD, |
| 1777 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1778 | Id.getLoc(), ExprType, VK_LValue); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1781 | Sema::DeclGroupPtrTy |
| 1782 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1783 | ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1784 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1785 | CurContext->addDecl(D); |
| 1786 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1787 | } |
| David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1788 | return nullptr; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1791 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1792 | class LocalVarRefChecker final |
| 1793 | : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1794 | Sema &SemaRef; |
| 1795 | |
| 1796 | public: |
| 1797 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1798 | if (const auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1799 | if (VD->hasLocalStorage()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 1800 | SemaRef.Diag(E->getBeginLoc(), |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1801 | diag::err_omp_local_var_in_threadprivate_init) |
| 1802 | << E->getSourceRange(); |
| 1803 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1804 | << VD << VD->getSourceRange(); |
| 1805 | return true; |
| 1806 | } |
| 1807 | } |
| 1808 | return false; |
| 1809 | } |
| 1810 | bool VisitStmt(const Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1811 | for (const Stmt *Child : S->children()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1812 | if (Child && Visit(Child)) |
| 1813 | return true; |
| 1814 | } |
| 1815 | return false; |
| 1816 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1817 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1818 | }; |
| 1819 | } // namespace |
| 1820 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1821 | OMPThreadPrivateDecl * |
| 1822 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1823 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1824 | for (Expr *RefExpr : VarList) { |
| 1825 | auto *DE = cast<DeclRefExpr>(RefExpr); |
| 1826 | auto *VD = cast<VarDecl>(DE->getDecl()); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1827 | SourceLocation ILoc = DE->getExprLoc(); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1828 | |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1829 | // Mark variable as used. |
| 1830 | VD->setReferenced(); |
| 1831 | VD->markUsed(Context); |
| 1832 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1833 | QualType QType = VD->getType(); |
| 1834 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1835 | // It will be analyzed later. |
| 1836 | Vars.push_back(DE); |
| 1837 | continue; |
| 1838 | } |
| 1839 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1840 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1841 | // A threadprivate variable must not have an incomplete type. |
| 1842 | if (RequireCompleteType(ILoc, VD->getType(), |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1843 | diag::err_omp_threadprivate_incomplete_type)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1844 | continue; |
| 1845 | } |
| 1846 | |
| 1847 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1848 | // A threadprivate variable must not have a reference type. |
| 1849 | if (VD->getType()->isReferenceType()) { |
| 1850 | Diag(ILoc, diag::err_omp_ref_type_arg) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1851 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1852 | bool IsDecl = |
| 1853 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1854 | Diag(VD->getLocation(), |
| 1855 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1856 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1857 | continue; |
| 1858 | } |
| 1859 | |
| Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1860 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1861 | // the corresponding diagnostic. |
| 1862 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1863 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1864 | getLangOpts().OpenMPUseTLS && |
| 1865 | getASTContext().getTargetInfo().isTLSSupported())) || |
| Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1866 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1867 | !VD->isLocalVarDecl())) { |
| Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1868 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1869 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1870 | bool IsDecl = |
| 1871 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1872 | Diag(VD->getLocation(), |
| 1873 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1874 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1875 | continue; |
| 1876 | } |
| 1877 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1878 | // Check if initial value of threadprivate variable reference variable with |
| 1879 | // local storage (it is not supported by runtime). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1880 | if (const Expr *Init = VD->getAnyInitializer()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1881 | LocalVarRefChecker Checker(*this); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1882 | if (Checker.Visit(Init)) |
| 1883 | continue; |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1886 | Vars.push_back(RefExpr); |
| Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1887 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1888 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1889 | Context, SourceRange(Loc, Loc))); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1890 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1891 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1892 | } |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1893 | OMPThreadPrivateDecl *D = nullptr; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1894 | if (!Vars.empty()) { |
| 1895 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1896 | Vars); |
| 1897 | D->setAccess(AS_public); |
| 1898 | } |
| 1899 | return D; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1900 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1901 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1902 | static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, |
| 1903 | const ValueDecl *D, |
| 1904 | const DSAStackTy::DSAVarData &DVar, |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1905 | bool IsLoopIterVar = false) { |
| 1906 | if (DVar.RefExpr) { |
| 1907 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1908 | << getOpenMPClauseName(DVar.CKind); |
| 1909 | return; |
| 1910 | } |
| 1911 | enum { |
| 1912 | PDSA_StaticMemberShared, |
| 1913 | PDSA_StaticLocalVarShared, |
| 1914 | PDSA_LoopIterVarPrivate, |
| 1915 | PDSA_LoopIterVarLinear, |
| 1916 | PDSA_LoopIterVarLastprivate, |
| 1917 | PDSA_ConstVarShared, |
| 1918 | PDSA_GlobalVarShared, |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1919 | PDSA_TaskVarFirstprivate, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1920 | PDSA_LocalVarPrivate, |
| 1921 | PDSA_Implicit |
| 1922 | } Reason = PDSA_Implicit; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1923 | bool ReportHint = false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1924 | auto ReportLoc = D->getLocation(); |
| 1925 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1926 | if (IsLoopIterVar) { |
| 1927 | if (DVar.CKind == OMPC_private) |
| 1928 | Reason = PDSA_LoopIterVarPrivate; |
| 1929 | else if (DVar.CKind == OMPC_lastprivate) |
| 1930 | Reason = PDSA_LoopIterVarLastprivate; |
| 1931 | else |
| 1932 | Reason = PDSA_LoopIterVarLinear; |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1933 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1934 | DVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1935 | Reason = PDSA_TaskVarFirstprivate; |
| 1936 | ReportLoc = DVar.ImplicitDSALoc; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1937 | } else if (VD && VD->isStaticLocal()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1938 | Reason = PDSA_StaticLocalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1939 | else if (VD && VD->isStaticDataMember()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1940 | Reason = PDSA_StaticMemberShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1941 | else if (VD && VD->isFileVarDecl()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1942 | Reason = PDSA_GlobalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1943 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1944 | Reason = PDSA_ConstVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1945 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1946 | ReportHint = true; |
| 1947 | Reason = PDSA_LocalVarPrivate; |
| 1948 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1949 | if (Reason != PDSA_Implicit) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1950 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1951 | << Reason << ReportHint |
| 1952 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1953 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1954 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1955 | << getOpenMPClauseName(DVar.CKind); |
| 1956 | } |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1959 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1960 | class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1961 | DSAStackTy *Stack; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1962 | Sema &SemaRef; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1963 | bool ErrorFound = false; |
| 1964 | CapturedStmt *CS = nullptr; |
| 1965 | llvm::SmallVector<Expr *, 4> ImplicitFirstprivate; |
| 1966 | llvm::SmallVector<Expr *, 4> ImplicitMap; |
| 1967 | Sema::VarsWithInheritedDSAType VarsWithInheritedDSA; |
| 1968 | llvm::SmallDenseSet<const ValueDecl *, 4> ImplicitDeclarations; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1969 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1970 | public: |
| 1971 | void VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1972 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1973 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1974 | return; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1975 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 1976 | VD = VD->getCanonicalDecl(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1977 | // Skip internally declared variables. |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 1978 | if (VD->hasLocalStorage() && !CS->capturesVariable(VD)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1979 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1980 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1981 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1982 | // 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] | 1983 | if (DVar.RefExpr || !ImplicitDeclarations.insert(VD).second) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1984 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1985 | |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 1986 | // Skip internally declared static variables. |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1987 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1988 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1989 | if (VD->hasGlobalStorage() && !CS->capturesVariable(VD) && |
| 1990 | (!Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)) |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 1991 | return; |
| 1992 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1993 | SourceLocation ELoc = E->getExprLoc(); |
| 1994 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1995 | // The default(none) clause requires that each variable that is referenced |
| 1996 | // in the construct, and does not have a predetermined data-sharing |
| 1997 | // attribute, must have its data-sharing attribute explicitly determined |
| 1998 | // by being listed in a data-sharing attribute clause. |
| 1999 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2000 | isParallelOrTaskRegion(DKind) && |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2001 | VarsWithInheritedDSA.count(VD) == 0) { |
| 2002 | VarsWithInheritedDSA[VD] = E; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2003 | return; |
| 2004 | } |
| 2005 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2006 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 2007 | !Stack->isLoopControlVariable(VD).first) { |
| 2008 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2009 | VD, /*CurrentRegionOnly=*/true, |
| 2010 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2011 | StackComponents, |
| 2012 | OpenMPClauseKind) { |
| 2013 | // Variable is used if it has been marked as an array, array |
| 2014 | // section or the variable iself. |
| 2015 | return StackComponents.size() == 1 || |
| 2016 | std::all_of( |
| 2017 | std::next(StackComponents.rbegin()), |
| 2018 | StackComponents.rend(), |
| 2019 | [](const OMPClauseMappableExprCommon:: |
| 2020 | MappableComponent &MC) { |
| 2021 | return MC.getAssociatedDeclaration() == |
| 2022 | nullptr && |
| 2023 | (isa<OMPArraySectionExpr>( |
| 2024 | MC.getAssociatedExpression()) || |
| 2025 | isa<ArraySubscriptExpr>( |
| 2026 | MC.getAssociatedExpression())); |
| 2027 | }); |
| 2028 | })) { |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2029 | bool IsFirstprivate = false; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2030 | // By default lambdas are captured as firstprivates. |
| 2031 | if (const auto *RD = |
| 2032 | VD->getType().getNonReferenceType()->getAsCXXRecordDecl()) |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2033 | IsFirstprivate = RD->isLambda(); |
| 2034 | IsFirstprivate = |
| 2035 | IsFirstprivate || |
| 2036 | (VD->getType().getNonReferenceType()->isScalarType() && |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 2037 | Stack->getDefaultDMA() != DMA_tofrom_scalar && !Res); |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2038 | if (IsFirstprivate) |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2039 | ImplicitFirstprivate.emplace_back(E); |
| 2040 | else |
| 2041 | ImplicitMap.emplace_back(E); |
| 2042 | return; |
| 2043 | } |
| 2044 | } |
| 2045 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2046 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 2047 | // A list item that appears in a reduction clause of the innermost |
| 2048 | // enclosing worksharing or parallel construct may not be accessed in an |
| 2049 | // explicit task. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2050 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2051 | VD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 2052 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2053 | return isOpenMPParallelDirective(K) || |
| 2054 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 2055 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 2056 | /*FromParent=*/true); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2057 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2058 | ErrorFound = true; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2059 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2060 | reportOriginalDsa(SemaRef, Stack, VD, DVar); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2061 | return; |
| 2062 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2063 | |
| 2064 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2065 | DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2066 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 2067 | !Stack->isLoopControlVariable(VD).first) |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2068 | ImplicitFirstprivate.push_back(E); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2069 | } |
| 2070 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2071 | void VisitMemberExpr(MemberExpr *E) { |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 2072 | if (E->isTypeDependent() || E->isValueDependent() || |
| 2073 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 2074 | return; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2075 | auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2076 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2077 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2078 | if (!FD) |
| 2079 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2080 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2081 | // Check if the variable has explicit DSA set and stop analysis if it |
| 2082 | // so. |
| 2083 | if (DVar.RefExpr || !ImplicitDeclarations.insert(FD).second) |
| 2084 | return; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2085 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2086 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 2087 | !Stack->isLoopControlVariable(FD).first && |
| 2088 | !Stack->checkMappableExprComponentListsForDecl( |
| 2089 | FD, /*CurrentRegionOnly=*/true, |
| 2090 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2091 | StackComponents, |
| 2092 | OpenMPClauseKind) { |
| 2093 | return isa<CXXThisExpr>( |
| 2094 | cast<MemberExpr>( |
| 2095 | StackComponents.back().getAssociatedExpression()) |
| 2096 | ->getBase() |
| 2097 | ->IgnoreParens()); |
| 2098 | })) { |
| 2099 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 2100 | // A bit-field cannot appear in a map clause. |
| 2101 | // |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2102 | if (FD->isBitField()) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2103 | return; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2104 | ImplicitMap.emplace_back(E); |
| 2105 | return; |
| 2106 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2107 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2108 | SourceLocation ELoc = E->getExprLoc(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2109 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 2110 | // A list item that appears in a reduction clause of the innermost |
| 2111 | // enclosing worksharing or parallel construct may not be accessed in |
| 2112 | // an explicit task. |
| 2113 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2114 | FD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 2115 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2116 | return isOpenMPParallelDirective(K) || |
| 2117 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 2118 | }, |
| 2119 | /*FromParent=*/true); |
| 2120 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| 2121 | ErrorFound = true; |
| 2122 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2123 | reportOriginalDsa(SemaRef, Stack, FD, DVar); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2124 | return; |
| 2125 | } |
| 2126 | |
| 2127 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2128 | DVar = Stack->getImplicitDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2129 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 2130 | !Stack->isLoopControlVariable(FD).first) |
| 2131 | ImplicitFirstprivate.push_back(E); |
| 2132 | return; |
| 2133 | } |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2134 | if (isOpenMPTargetExecutionDirective(DKind)) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2135 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2136 | if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2137 | /*NoDiagnose=*/true)) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 2138 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2139 | const auto *VD = cast<ValueDecl>( |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2140 | CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); |
| 2141 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2142 | VD, /*CurrentRegionOnly=*/true, |
| 2143 | [&CurComponents]( |
| 2144 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2145 | StackComponents, |
| 2146 | OpenMPClauseKind) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2147 | auto CCI = CurComponents.rbegin(); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 2148 | auto CCE = CurComponents.rend(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2149 | for (const auto &SC : llvm::reverse(StackComponents)) { |
| 2150 | // Do both expressions have the same kind? |
| 2151 | if (CCI->getAssociatedExpression()->getStmtClass() != |
| 2152 | SC.getAssociatedExpression()->getStmtClass()) |
| 2153 | if (!(isa<OMPArraySectionExpr>( |
| 2154 | SC.getAssociatedExpression()) && |
| 2155 | isa<ArraySubscriptExpr>( |
| 2156 | CCI->getAssociatedExpression()))) |
| 2157 | return false; |
| 2158 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2159 | const Decl *CCD = CCI->getAssociatedDeclaration(); |
| 2160 | const Decl *SCD = SC.getAssociatedDeclaration(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2161 | CCD = CCD ? CCD->getCanonicalDecl() : nullptr; |
| 2162 | SCD = SCD ? SCD->getCanonicalDecl() : nullptr; |
| 2163 | if (SCD != CCD) |
| 2164 | return false; |
| 2165 | std::advance(CCI, 1); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 2166 | if (CCI == CCE) |
| 2167 | break; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2168 | } |
| 2169 | return true; |
| 2170 | })) { |
| 2171 | Visit(E->getBase()); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2172 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2173 | } else { |
| Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 2174 | Visit(E->getBase()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2175 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2176 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2177 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2178 | for (OMPClause *C : S->clauses()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2179 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2180 | // for task|target directives. |
| 2181 | // Skip analysis of arguments of implicitly defined map clause for target |
| 2182 | // directives. |
| 2183 | if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) && |
| 2184 | C->isImplicit())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2185 | for (Stmt *CC : C->children()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2186 | if (CC) |
| 2187 | Visit(CC); |
| 2188 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2189 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2190 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2191 | } |
| 2192 | void VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2193 | for (Stmt *C : S->children()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2194 | if (C && !isa<OMPExecutableDirective>(C)) |
| 2195 | Visit(C); |
| 2196 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2197 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2198 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2199 | bool isErrorFound() const { return ErrorFound; } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2200 | ArrayRef<Expr *> getImplicitFirstprivate() const { |
| 2201 | return ImplicitFirstprivate; |
| 2202 | } |
| 2203 | ArrayRef<Expr *> getImplicitMap() const { return ImplicitMap; } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2204 | const Sema::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const { |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2205 | return VarsWithInheritedDSA; |
| 2206 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2207 | |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2208 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 2209 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2210 | }; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2211 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2212 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2213 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2214 | switch (DKind) { |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2215 | case OMPD_parallel: |
| 2216 | case OMPD_parallel_for: |
| 2217 | case OMPD_parallel_for_simd: |
| 2218 | case OMPD_parallel_sections: |
| Carlo Bertolli | ba1487b | 2017-10-04 14:12:09 +0000 | [diff] [blame] | 2219 | case OMPD_teams: |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 2220 | case OMPD_teams_distribute: |
| 2221 | case OMPD_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2222 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 2223 | QualType KmpInt32PtrTy = |
| 2224 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2225 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2226 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2227 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2228 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2229 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2230 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2231 | Params); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | } |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2234 | case OMPD_target_teams: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 2235 | case OMPD_target_parallel: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 2236 | case OMPD_target_parallel_for: |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 2237 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 2238 | case OMPD_target_teams_distribute: |
| 2239 | case OMPD_target_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2240 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2241 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2242 | QualType KmpInt32PtrTy = |
| 2243 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2244 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2245 | FunctionProtoType::ExtProtoInfo EPI; |
| 2246 | EPI.Variadic = true; |
| 2247 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2248 | Sema::CapturedParamNameType Params[] = { |
| 2249 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2250 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2251 | std::make_pair(".privates.", VoidPtrTy), |
| 2252 | std::make_pair( |
| 2253 | ".copy_fn.", |
| 2254 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2255 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2256 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2257 | }; |
| 2258 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2259 | Params); |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 2260 | // Mark this captured region as inlined, because we don't use outlined |
| 2261 | // function directly. |
| 2262 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2263 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2264 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2265 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 2266 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2267 | }; |
| 2268 | // Start a captured region for 'target' with no implicit parameters. |
| 2269 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2270 | ParamsTarget); |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2271 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2272 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2273 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2274 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2275 | }; |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2276 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2277 | // the same implicit parameters. |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2278 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2279 | ParamsTeamsOrParallel); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2280 | break; |
| 2281 | } |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2282 | case OMPD_target: |
| 2283 | case OMPD_target_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2284 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2285 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2286 | QualType KmpInt32PtrTy = |
| 2287 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2288 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2289 | FunctionProtoType::ExtProtoInfo EPI; |
| 2290 | EPI.Variadic = true; |
| 2291 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2292 | Sema::CapturedParamNameType Params[] = { |
| 2293 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2294 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2295 | std::make_pair(".privates.", VoidPtrTy), |
| 2296 | std::make_pair( |
| 2297 | ".copy_fn.", |
| 2298 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2299 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2300 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2301 | }; |
| 2302 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2303 | Params); |
| 2304 | // Mark this captured region as inlined, because we don't use outlined |
| 2305 | // function directly. |
| 2306 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2307 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2308 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2309 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2310 | std::make_pair(StringRef(), QualType())); |
| 2311 | break; |
| 2312 | } |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2313 | case OMPD_simd: |
| 2314 | case OMPD_for: |
| 2315 | case OMPD_for_simd: |
| 2316 | case OMPD_sections: |
| 2317 | case OMPD_section: |
| 2318 | case OMPD_single: |
| 2319 | case OMPD_master: |
| 2320 | case OMPD_critical: |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2321 | case OMPD_taskgroup: |
| 2322 | case OMPD_distribute: |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 2323 | case OMPD_distribute_simd: |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2324 | case OMPD_ordered: |
| 2325 | case OMPD_atomic: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2326 | case OMPD_target_data: { |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2327 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2328 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2329 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2330 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2331 | Params); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2332 | break; |
| 2333 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2334 | case OMPD_task: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2335 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2336 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2337 | QualType KmpInt32PtrTy = |
| 2338 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2339 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 2340 | FunctionProtoType::ExtProtoInfo EPI; |
| 2341 | EPI.Variadic = true; |
| 2342 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2343 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 2344 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2345 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2346 | std::make_pair(".privates.", VoidPtrTy), |
| 2347 | std::make_pair( |
| 2348 | ".copy_fn.", |
| 2349 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 2350 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2351 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2352 | }; |
| 2353 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2354 | Params); |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 2355 | // Mark this captured region as inlined, because we don't use outlined |
| 2356 | // function directly. |
| 2357 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2358 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2359 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | } |
| Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 2362 | case OMPD_taskloop: |
| 2363 | case OMPD_taskloop_simd: { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2364 | QualType KmpInt32Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2365 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
| 2366 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2367 | QualType KmpUInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2368 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
| 2369 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2370 | QualType KmpInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2371 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
| 2372 | .withConst(); |
| 2373 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2374 | QualType KmpInt32PtrTy = |
| 2375 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2376 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2377 | FunctionProtoType::ExtProtoInfo EPI; |
| 2378 | EPI.Variadic = true; |
| 2379 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2380 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2381 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2382 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2383 | std::make_pair(".privates.", VoidPtrTy), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2384 | std::make_pair( |
| 2385 | ".copy_fn.", |
| 2386 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 2387 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2388 | std::make_pair(".lb.", KmpUInt64Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2389 | std::make_pair(".ub.", KmpUInt64Ty), |
| 2390 | std::make_pair(".st.", KmpInt64Ty), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2391 | std::make_pair(".liter.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2392 | std::make_pair(".reductions.", VoidPtrTy), |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2393 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2394 | }; |
| 2395 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2396 | Params); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2397 | // Mark this captured region as inlined, because we don't use outlined |
| 2398 | // function directly. |
| 2399 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2400 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2401 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2402 | break; |
| 2403 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2404 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 2405 | case OMPD_distribute_parallel_for: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2406 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2407 | QualType KmpInt32PtrTy = |
| 2408 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2409 | Sema::CapturedParamNameType Params[] = { |
| 2410 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2411 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2412 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2413 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2414 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2415 | }; |
| 2416 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2417 | Params); |
| 2418 | break; |
| 2419 | } |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 2420 | case OMPD_target_teams_distribute_parallel_for: |
| 2421 | case OMPD_target_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2422 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2423 | QualType KmpInt32PtrTy = |
| 2424 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2425 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2426 | |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2427 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2428 | FunctionProtoType::ExtProtoInfo EPI; |
| 2429 | EPI.Variadic = true; |
| 2430 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2431 | Sema::CapturedParamNameType Params[] = { |
| 2432 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2433 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2434 | std::make_pair(".privates.", VoidPtrTy), |
| 2435 | std::make_pair( |
| 2436 | ".copy_fn.", |
| 2437 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2438 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2439 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2440 | }; |
| 2441 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2442 | Params); |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 2443 | // Mark this captured region as inlined, because we don't use outlined |
| 2444 | // function directly. |
| 2445 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2446 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2447 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2448 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 2449 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2450 | }; |
| 2451 | // Start a captured region for 'target' with no implicit parameters. |
| 2452 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2453 | ParamsTarget); |
| 2454 | |
| 2455 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 2456 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2457 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2458 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2459 | }; |
| 2460 | // Start a captured region for 'target' with no implicit parameters. |
| 2461 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2462 | ParamsTeams); |
| 2463 | |
| 2464 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 2465 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2466 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2467 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2468 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2469 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2470 | }; |
| 2471 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2472 | // the same implicit parameters. |
| 2473 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2474 | ParamsParallel); |
| 2475 | break; |
| 2476 | } |
| 2477 | |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 2478 | case OMPD_teams_distribute_parallel_for: |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 2479 | case OMPD_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2480 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 2481 | QualType KmpInt32PtrTy = |
| 2482 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2483 | |
| 2484 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 2485 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2486 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2487 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2488 | }; |
| 2489 | // Start a captured region for 'target' with no implicit parameters. |
| 2490 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2491 | ParamsTeams); |
| 2492 | |
| 2493 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 2494 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2495 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2496 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2497 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 2498 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2499 | }; |
| 2500 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2501 | // the same implicit parameters. |
| 2502 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2503 | ParamsParallel); |
| 2504 | break; |
| 2505 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2506 | case OMPD_target_update: |
| 2507 | case OMPD_target_enter_data: |
| 2508 | case OMPD_target_exit_data: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2509 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2510 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2511 | QualType KmpInt32PtrTy = |
| 2512 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2513 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2514 | FunctionProtoType::ExtProtoInfo EPI; |
| 2515 | EPI.Variadic = true; |
| 2516 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2517 | Sema::CapturedParamNameType Params[] = { |
| 2518 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2519 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2520 | std::make_pair(".privates.", VoidPtrTy), |
| 2521 | std::make_pair( |
| 2522 | ".copy_fn.", |
| 2523 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2524 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2525 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2526 | }; |
| 2527 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2528 | Params); |
| 2529 | // Mark this captured region as inlined, because we don't use outlined |
| 2530 | // function directly. |
| 2531 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2532 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2533 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2534 | break; |
| 2535 | } |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2536 | case OMPD_threadprivate: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 2537 | case OMPD_taskyield: |
| 2538 | case OMPD_barrier: |
| 2539 | case OMPD_taskwait: |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2540 | case OMPD_cancellation_point: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2541 | case OMPD_cancel: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 2542 | case OMPD_flush: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2543 | case OMPD_declare_reduction: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2544 | case OMPD_declare_simd: |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2545 | case OMPD_declare_target: |
| 2546 | case OMPD_end_declare_target: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2547 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2548 | case OMPD_unknown: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2549 | llvm_unreachable("Unknown OpenMP directive"); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2553 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 2554 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 2555 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 2556 | return CaptureRegions.size(); |
| 2557 | } |
| 2558 | |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2559 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2560 | Expr *CaptureExpr, bool WithInit, |
| 2561 | bool AsExpression) { |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2562 | assert(CaptureExpr); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2563 | ASTContext &C = S.getASTContext(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2564 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2565 | QualType Ty = Init->getType(); |
| 2566 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2567 | if (S.getLangOpts().CPlusPlus) { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2568 | Ty = C.getLValueReferenceType(Ty); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2569 | } else { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2570 | Ty = C.getPointerType(Ty); |
| 2571 | ExprResult Res = |
| 2572 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 2573 | if (!Res.isUsable()) |
| 2574 | return nullptr; |
| 2575 | Init = Res.get(); |
| 2576 | } |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2577 | WithInit = true; |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2578 | } |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 2579 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2580 | CaptureExpr->getBeginLoc()); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2581 | if (!WithInit) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2582 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C)); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2583 | S.CurContext->addHiddenDecl(CED); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 2584 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2585 | return CED; |
| 2586 | } |
| 2587 | |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2588 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 2589 | bool WithInit) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 2590 | OMPCapturedExprDecl *CD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2591 | if (VarDecl *VD = S.isOpenMPCapturedDecl(D)) |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 2592 | CD = cast<OMPCapturedExprDecl>(VD); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2593 | else |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2594 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 2595 | /*AsExpression=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2596 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 2597 | CaptureExpr->getExprLoc()); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2600 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2601 | CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2602 | if (!Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2603 | OMPCapturedExprDecl *CD = buildCaptureDecl( |
| 2604 | S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr, |
| 2605 | /*WithInit=*/true, /*AsExpression=*/true); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2606 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 2607 | CaptureExpr->getExprLoc()); |
| 2608 | } |
| 2609 | ExprResult Res = Ref; |
| 2610 | if (!S.getLangOpts().CPlusPlus && |
| 2611 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2612 | Ref->getType()->isPointerType()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2613 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2614 | if (!Res.isUsable()) |
| 2615 | return ExprError(); |
| 2616 | } |
| 2617 | return S.DefaultLvalueConversion(Res.get()); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2620 | namespace { |
| 2621 | // OpenMP directives parsed in this section are represented as a |
| 2622 | // CapturedStatement with an associated statement. If a syntax error |
| 2623 | // is detected during the parsing of the associated statement, the |
| 2624 | // compiler must abort processing and close the CapturedStatement. |
| 2625 | // |
| 2626 | // Combined directives such as 'target parallel' have more than one |
| 2627 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 2628 | // of all the nested CapturedStatements when an error is found. |
| 2629 | class CaptureRegionUnwinderRAII { |
| 2630 | private: |
| 2631 | Sema &S; |
| 2632 | bool &ErrorFound; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2633 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2634 | |
| 2635 | public: |
| 2636 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 2637 | OpenMPDirectiveKind DKind) |
| 2638 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 2639 | ~CaptureRegionUnwinderRAII() { |
| 2640 | if (ErrorFound) { |
| 2641 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 2642 | while (--ThisCaptureLevel >= 0) |
| 2643 | S.ActOnCapturedRegionError(); |
| 2644 | } |
| 2645 | } |
| 2646 | }; |
| 2647 | } // namespace |
| 2648 | |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2649 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 2650 | ArrayRef<OMPClause *> Clauses) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2651 | bool ErrorFound = false; |
| 2652 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 2653 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2654 | if (!S.isUsable()) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2655 | ErrorFound = true; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2656 | return StmtError(); |
| 2657 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2658 | |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 2659 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 2660 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2661 | OMPOrderedClause *OC = nullptr; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2662 | OMPScheduleClause *SC = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2663 | SmallVector<const OMPLinearClause *, 4> LCs; |
| 2664 | SmallVector<const OMPClauseWithPreInit *, 4> PICs; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 2665 | // This is required for proper codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2666 | for (OMPClause *Clause : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 2667 | if (isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) && |
| 2668 | Clause->getClauseKind() == OMPC_in_reduction) { |
| 2669 | // Capture taskgroup task_reduction descriptors inside the tasking regions |
| 2670 | // with the corresponding in_reduction items. |
| 2671 | auto *IRC = cast<OMPInReductionClause>(Clause); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2672 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 2673 | if (E) |
| 2674 | MarkDeclarationsReferencedInExpr(E); |
| 2675 | } |
| Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 2676 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 2677 | Clause->getClauseKind() == OMPC_copyprivate || |
| 2678 | (getLangOpts().OpenMPUseTLS && |
| 2679 | getASTContext().getTargetInfo().isTLSSupported() && |
| 2680 | Clause->getClauseKind() == OMPC_copyin)) { |
| 2681 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 2682 | // Mark all variables in private list clauses as used in inner region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2683 | for (Stmt *VarRef : Clause->children()) { |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2684 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 2685 | MarkDeclarationsReferencedInExpr(E); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2686 | } |
| 2687 | } |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 2688 | DSAStack->setForceVarCapturing(/*V=*/false); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 2689 | } else if (CaptureRegions.size() > 1 || |
| 2690 | CaptureRegions.back() != OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2691 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 2692 | PICs.push_back(C); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2693 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2694 | if (Expr *E = C->getPostUpdateExpr()) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2695 | MarkDeclarationsReferencedInExpr(E); |
| 2696 | } |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2697 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2698 | if (Clause->getClauseKind() == OMPC_schedule) |
| 2699 | SC = cast<OMPScheduleClause>(Clause); |
| 2700 | else if (Clause->getClauseKind() == OMPC_ordered) |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2701 | OC = cast<OMPOrderedClause>(Clause); |
| 2702 | else if (Clause->getClauseKind() == OMPC_linear) |
| 2703 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 2704 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2705 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 2706 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 2707 | // specified. |
| 2708 | if (SC && |
| 2709 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 2710 | SC->getSecondScheduleModifier() == |
| 2711 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 2712 | OC) { |
| 2713 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 2714 | ? SC->getFirstScheduleModifierLoc() |
| 2715 | : SC->getSecondScheduleModifierLoc(), |
| 2716 | diag::err_omp_schedule_nonmonotonic_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 2717 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2718 | ErrorFound = true; |
| 2719 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2720 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2721 | for (const OMPLinearClause *C : LCs) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2722 | Diag(C->getBeginLoc(), diag::err_omp_linear_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 2723 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2724 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2725 | ErrorFound = true; |
| 2726 | } |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 2727 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 2728 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 2729 | OC->getNumForLoops()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2730 | Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd) |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 2731 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 2732 | ErrorFound = true; |
| 2733 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2734 | if (ErrorFound) { |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2735 | return StmtError(); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2736 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2737 | StmtResult SR = S; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 2738 | for (OpenMPDirectiveKind ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2739 | // Mark all variables in private list clauses as used in inner region. |
| 2740 | // Required for proper codegen of combined directives. |
| 2741 | // TODO: add processing for other clauses. |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 2742 | if (ThisCaptureRegion != OMPD_unknown) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2743 | for (const clang::OMPClauseWithPreInit *C : PICs) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2744 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 2745 | // Find the particular capture region for the clause if the |
| 2746 | // directive is a combined one with multiple capture regions. |
| 2747 | // If the directive is not a combined one, the capture region |
| 2748 | // associated with the clause is OMPD_unknown and is generated |
| 2749 | // only once. |
| 2750 | if (CaptureRegion == ThisCaptureRegion || |
| 2751 | CaptureRegion == OMPD_unknown) { |
| 2752 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2753 | for (Decl *D : DS->decls()) |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2754 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2759 | SR = ActOnCapturedRegionEnd(SR.get()); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2760 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2761 | return SR; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 2764 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 2765 | OpenMPDirectiveKind CancelRegion, |
| 2766 | SourceLocation StartLoc) { |
| 2767 | // CancelRegion is only needed for cancel and cancellation_point. |
| 2768 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 2769 | return false; |
| 2770 | |
| 2771 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 2772 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 2773 | return false; |
| 2774 | |
| 2775 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 2776 | << getOpenMPDirectiveName(CancelRegion); |
| 2777 | return true; |
| 2778 | } |
| 2779 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2780 | static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2781 | OpenMPDirectiveKind CurrentRegion, |
| 2782 | const DeclarationNameInfo &CurrentName, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2783 | OpenMPDirectiveKind CancelRegion, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2784 | SourceLocation StartLoc) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2785 | if (Stack->getCurScope()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2786 | OpenMPDirectiveKind ParentRegion = Stack->getParentDirective(); |
| 2787 | OpenMPDirectiveKind OffendingRegion = ParentRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2788 | bool NestingProhibited = false; |
| 2789 | bool CloseNesting = true; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2790 | bool OrphanSeen = false; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2791 | enum { |
| 2792 | NoRecommend, |
| 2793 | ShouldBeInParallelRegion, |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2794 | ShouldBeInOrderedRegion, |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2795 | ShouldBeInTargetRegion, |
| 2796 | ShouldBeInTeamsRegion |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2797 | } Recommend = NoRecommend; |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2798 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2799 | // OpenMP [2.16, Nesting of Regions] |
| 2800 | // OpenMP constructs may not be nested inside a simd region. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2801 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2802 | // An ordered construct with the simd clause is the only OpenMP |
| 2803 | // construct that can appear in the simd region. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2804 | // Allowing a SIMD construct nested in another SIMD construct is an |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2805 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 2806 | // message. |
| 2807 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 2808 | ? diag::err_omp_prohibited_region_simd |
| 2809 | : diag::warn_omp_nesting_simd); |
| 2810 | return CurrentRegion != OMPD_simd; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2811 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2812 | if (ParentRegion == OMPD_atomic) { |
| 2813 | // OpenMP [2.16, Nesting of Regions] |
| 2814 | // OpenMP constructs may not be nested inside an atomic region. |
| 2815 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2816 | return true; |
| 2817 | } |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2818 | if (CurrentRegion == OMPD_section) { |
| 2819 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2820 | // Orphaned section directives are prohibited. That is, the section |
| 2821 | // directives must appear within the sections construct and must not be |
| 2822 | // encountered elsewhere in the sections region. |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2823 | if (ParentRegion != OMPD_sections && |
| 2824 | ParentRegion != OMPD_parallel_sections) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2825 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2826 | << (ParentRegion != OMPD_unknown) |
| 2827 | << getOpenMPDirectiveName(ParentRegion); |
| 2828 | return true; |
| 2829 | } |
| 2830 | return false; |
| 2831 | } |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2832 | // Allow some constructs (except teams) to be orphaned (they could be |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2833 | // used in functions, called from OpenMP regions with the required |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2834 | // preconditions). |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2835 | if (ParentRegion == OMPD_unknown && |
| 2836 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2837 | return false; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2838 | if (CurrentRegion == OMPD_cancellation_point || |
| 2839 | CurrentRegion == OMPD_cancel) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2840 | // OpenMP [2.16, Nesting of Regions] |
| 2841 | // A cancellation point construct for which construct-type-clause is |
| 2842 | // taskgroup must be nested inside a task construct. A cancellation |
| 2843 | // point construct for which construct-type-clause is not taskgroup must |
| 2844 | // be closely nested inside an OpenMP construct that matches the type |
| 2845 | // specified in construct-type-clause. |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2846 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2847 | // nested inside a task construct. A cancel construct for which |
| 2848 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2849 | // OpenMP construct that matches the type specified in |
| 2850 | // construct-type-clause. |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2851 | NestingProhibited = |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2852 | !((CancelRegion == OMPD_parallel && |
| 2853 | (ParentRegion == OMPD_parallel || |
| 2854 | ParentRegion == OMPD_target_parallel)) || |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2855 | (CancelRegion == OMPD_for && |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2856 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 2857 | ParentRegion == OMPD_target_parallel_for || |
| 2858 | ParentRegion == OMPD_distribute_parallel_for || |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 2859 | ParentRegion == OMPD_teams_distribute_parallel_for || |
| 2860 | ParentRegion == OMPD_target_teams_distribute_parallel_for)) || |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2861 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2862 | (CancelRegion == OMPD_sections && |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2863 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2864 | ParentRegion == OMPD_parallel_sections))); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2865 | } else if (CurrentRegion == OMPD_master) { |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2866 | // OpenMP [2.16, Nesting of Regions] |
| 2867 | // A master region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2868 | // atomic, or explicit task region. |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2869 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2870 | isOpenMPTaskingDirective(ParentRegion); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2871 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2872 | // OpenMP [2.16, Nesting of Regions] |
| 2873 | // A critical region may not be nested (closely or otherwise) inside a |
| 2874 | // critical region with the same name. Note that this restriction is not |
| 2875 | // sufficient to prevent deadlock. |
| 2876 | SourceLocation PreviousCriticalLoc; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2877 | bool DeadLock = Stack->hasDirective( |
| 2878 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2879 | const DeclarationNameInfo &DNI, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2880 | SourceLocation Loc) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2881 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2882 | PreviousCriticalLoc = Loc; |
| 2883 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2884 | } |
| 2885 | return false; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2886 | }, |
| 2887 | false /* skip top directive */); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2888 | if (DeadLock) { |
| 2889 | SemaRef.Diag(StartLoc, |
| 2890 | diag::err_omp_prohibited_region_critical_same_name) |
| 2891 | << CurrentName.getName(); |
| 2892 | if (PreviousCriticalLoc.isValid()) |
| 2893 | SemaRef.Diag(PreviousCriticalLoc, |
| 2894 | diag::note_omp_previous_critical_region); |
| 2895 | return true; |
| 2896 | } |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2897 | } else if (CurrentRegion == OMPD_barrier) { |
| 2898 | // OpenMP [2.16, Nesting of Regions] |
| 2899 | // A barrier region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2900 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2901 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2902 | isOpenMPTaskingDirective(ParentRegion) || |
| 2903 | ParentRegion == OMPD_master || |
| 2904 | ParentRegion == OMPD_critical || |
| 2905 | ParentRegion == OMPD_ordered; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2906 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2907 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2908 | !isOpenMPTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2909 | // OpenMP [2.16, Nesting of Regions] |
| 2910 | // A worksharing region may not be closely nested inside a worksharing, |
| 2911 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2912 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2913 | isOpenMPTaskingDirective(ParentRegion) || |
| 2914 | ParentRegion == OMPD_master || |
| 2915 | ParentRegion == OMPD_critical || |
| 2916 | ParentRegion == OMPD_ordered; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2917 | Recommend = ShouldBeInParallelRegion; |
| 2918 | } else if (CurrentRegion == OMPD_ordered) { |
| 2919 | // OpenMP [2.16, Nesting of Regions] |
| 2920 | // An ordered region may not be closely nested inside a critical, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2921 | // atomic, or explicit task region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2922 | // An ordered region must be closely nested inside a loop region (or |
| 2923 | // parallel loop region) with an ordered clause. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2924 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2925 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2926 | // that can appear in the simd region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2927 | NestingProhibited = ParentRegion == OMPD_critical || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2928 | isOpenMPTaskingDirective(ParentRegion) || |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2929 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2930 | Stack->isParentOrderedRegion()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2931 | Recommend = ShouldBeInOrderedRegion; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2932 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2933 | // OpenMP [2.16, Nesting of Regions] |
| 2934 | // If specified, a teams construct must be contained within a target |
| 2935 | // construct. |
| 2936 | NestingProhibited = ParentRegion != OMPD_target; |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2937 | OrphanSeen = ParentRegion == OMPD_unknown; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2938 | Recommend = ShouldBeInTargetRegion; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2939 | } |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2940 | if (!NestingProhibited && |
| 2941 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2942 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2943 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2944 | // OpenMP [2.16, Nesting of Regions] |
| 2945 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2946 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2947 | // constructs that can be closely nested in the teams region. |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2948 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2949 | !isOpenMPDistributeDirective(CurrentRegion); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2950 | Recommend = ShouldBeInParallelRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2951 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2952 | if (!NestingProhibited && |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2953 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2954 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2955 | // The region associated with the distribute construct must be strictly |
| 2956 | // nested inside a teams region |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2957 | NestingProhibited = |
| 2958 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2959 | Recommend = ShouldBeInTeamsRegion; |
| 2960 | } |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2961 | if (!NestingProhibited && |
| 2962 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2963 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2964 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2965 | // If a target, target update, target data, target enter data, or |
| 2966 | // target exit data construct is encountered during execution of a |
| 2967 | // target region, the behavior is unspecified. |
| 2968 | NestingProhibited = Stack->hasDirective( |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2969 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2970 | SourceLocation) { |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2971 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2972 | OffendingRegion = K; |
| 2973 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2974 | } |
| 2975 | return false; |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2976 | }, |
| 2977 | false /* don't skip top directive */); |
| 2978 | CloseNesting = false; |
| 2979 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2980 | if (NestingProhibited) { |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2981 | if (OrphanSeen) { |
| 2982 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2983 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2984 | } else { |
| 2985 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2986 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2987 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2988 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2989 | return true; |
| 2990 | } |
| 2991 | } |
| 2992 | return false; |
| 2993 | } |
| 2994 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2995 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2996 | ArrayRef<OMPClause *> Clauses, |
| 2997 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2998 | bool ErrorFound = false; |
| 2999 | unsigned NamedModifiersNumber = 0; |
| 3000 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 3001 | OMPD_unknown + 1); |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3002 | SmallVector<SourceLocation, 4> NameModifierLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3003 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3004 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 3005 | // At most one if clause without a directive-name-modifier can appear on |
| 3006 | // the directive. |
| 3007 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 3008 | if (FoundNameModifiers[CurNM]) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3009 | S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3010 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 3011 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 3012 | ErrorFound = true; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3013 | } else if (CurNM != OMPD_unknown) { |
| 3014 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3015 | ++NamedModifiersNumber; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3016 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3017 | FoundNameModifiers[CurNM] = IC; |
| 3018 | if (CurNM == OMPD_unknown) |
| 3019 | continue; |
| 3020 | // Check if the specified name modifier is allowed for the current |
| 3021 | // directive. |
| 3022 | // At most one if clause with the particular directive-name-modifier can |
| 3023 | // appear on the directive. |
| 3024 | bool MatchFound = false; |
| 3025 | for (auto NM : AllowedNameModifiers) { |
| 3026 | if (CurNM == NM) { |
| 3027 | MatchFound = true; |
| 3028 | break; |
| 3029 | } |
| 3030 | } |
| 3031 | if (!MatchFound) { |
| 3032 | S.Diag(IC->getNameModifierLoc(), |
| 3033 | diag::err_omp_wrong_if_directive_name_modifier) |
| 3034 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 3035 | ErrorFound = true; |
| 3036 | } |
| 3037 | } |
| 3038 | } |
| 3039 | // If any if clause on the directive includes a directive-name-modifier then |
| 3040 | // all if clauses on the directive must include a directive-name-modifier. |
| 3041 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3042 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3043 | S.Diag(FoundNameModifiers[OMPD_unknown]->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3044 | diag::err_omp_no_more_if_clause); |
| 3045 | } else { |
| 3046 | std::string Values; |
| 3047 | std::string Sep(", "); |
| 3048 | unsigned AllowedCnt = 0; |
| 3049 | unsigned TotalAllowedNum = |
| 3050 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3051 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3052 | ++Cnt) { |
| 3053 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3054 | if (!FoundNameModifiers[NM]) { |
| 3055 | Values += "'"; |
| 3056 | Values += getOpenMPDirectiveName(NM); |
| 3057 | Values += "'"; |
| 3058 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3059 | Values += " or "; |
| 3060 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3061 | Values += Sep; |
| 3062 | ++AllowedCnt; |
| 3063 | } |
| 3064 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3065 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3066 | diag::err_omp_unnamed_if_clause) |
| 3067 | << (TotalAllowedNum > 1) << Values; |
| 3068 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3069 | for (SourceLocation Loc : NameModifierLoc) { |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3070 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3071 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3072 | ErrorFound = true; |
| 3073 | } |
| 3074 | return ErrorFound; |
| 3075 | } |
| 3076 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3077 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3078 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3079 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3080 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3081 | StmtResult Res = StmtError(); |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 3082 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 3083 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 3084 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3085 | StartLoc)) |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3086 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3087 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3088 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3089 | VarsWithInheritedDSAType VarsWithInheritedDSA; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3090 | bool ErrorFound = false; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3091 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 3092 | if (AStmt && !CurContext->isDependentContext()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3093 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3094 | |
| 3095 | // Check default data sharing attributes for referenced variables. |
| 3096 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 3097 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 3098 | Stmt *S = AStmt; |
| 3099 | while (--ThisCaptureLevel >= 0) |
| 3100 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 3101 | DSAChecker.Visit(S); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3102 | if (DSAChecker.isErrorFound()) |
| 3103 | return StmtError(); |
| 3104 | // Generate list of implicitly defined firstprivate variables. |
| 3105 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3106 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3107 | SmallVector<Expr *, 4> ImplicitFirstprivates( |
| 3108 | DSAChecker.getImplicitFirstprivate().begin(), |
| 3109 | DSAChecker.getImplicitFirstprivate().end()); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3110 | SmallVector<Expr *, 4> ImplicitMaps(DSAChecker.getImplicitMap().begin(), |
| 3111 | DSAChecker.getImplicitMap().end()); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3112 | // Mark taskgroup task_reduction descriptors as implicitly firstprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3113 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3114 | if (auto *IRC = dyn_cast<OMPInReductionClause>(C)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3115 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3116 | if (E) |
| 3117 | ImplicitFirstprivates.emplace_back(E); |
| 3118 | } |
| 3119 | } |
| 3120 | if (!ImplicitFirstprivates.empty()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3121 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3122 | ImplicitFirstprivates, SourceLocation(), SourceLocation(), |
| 3123 | SourceLocation())) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3124 | ClausesWithImplicit.push_back(Implicit); |
| 3125 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3126 | ImplicitFirstprivates.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3127 | } else { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3128 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3129 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3130 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3131 | if (!ImplicitMaps.empty()) { |
| 3132 | if (OMPClause *Implicit = ActOnOpenMPMapClause( |
| 3133 | OMPC_MAP_unknown, OMPC_MAP_tofrom, /*IsMapTypeImplicit=*/true, |
| 3134 | SourceLocation(), SourceLocation(), ImplicitMaps, |
| 3135 | SourceLocation(), SourceLocation(), SourceLocation())) { |
| 3136 | ClausesWithImplicit.emplace_back(Implicit); |
| 3137 | ErrorFound |= |
| 3138 | cast<OMPMapClause>(Implicit)->varlist_size() != ImplicitMaps.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3139 | } else { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3140 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3141 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3142 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3143 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3144 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3145 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3146 | switch (Kind) { |
| 3147 | case OMPD_parallel: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3148 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3149 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3150 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3151 | break; |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3152 | case OMPD_simd: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3153 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3154 | VarsWithInheritedDSA); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3155 | break; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3156 | case OMPD_for: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3157 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3158 | VarsWithInheritedDSA); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3159 | break; |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3160 | case OMPD_for_simd: |
| 3161 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3162 | EndLoc, VarsWithInheritedDSA); |
| 3163 | break; |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3164 | case OMPD_sections: |
| 3165 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3166 | EndLoc); |
| 3167 | break; |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3168 | case OMPD_section: |
| 3169 | assert(ClausesWithImplicit.empty() && |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3170 | "No clauses are allowed for 'omp section' directive"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3171 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3172 | break; |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3173 | case OMPD_single: |
| 3174 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3175 | EndLoc); |
| 3176 | break; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3177 | case OMPD_master: |
| 3178 | assert(ClausesWithImplicit.empty() && |
| 3179 | "No clauses are allowed for 'omp master' directive"); |
| 3180 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3181 | break; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3182 | case OMPD_critical: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3183 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3184 | StartLoc, EndLoc); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3185 | break; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3186 | case OMPD_parallel_for: |
| 3187 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3188 | EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3189 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3190 | break; |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3191 | case OMPD_parallel_for_simd: |
| 3192 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3193 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3194 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3195 | break; |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3196 | case OMPD_parallel_sections: |
| 3197 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3198 | StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3199 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3200 | break; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3201 | case OMPD_task: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3202 | Res = |
| 3203 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3204 | AllowedNameModifiers.push_back(OMPD_task); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3205 | break; |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3206 | case OMPD_taskyield: |
| 3207 | assert(ClausesWithImplicit.empty() && |
| 3208 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3209 | assert(AStmt == nullptr && |
| 3210 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3211 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3212 | break; |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3213 | case OMPD_barrier: |
| 3214 | assert(ClausesWithImplicit.empty() && |
| 3215 | "No clauses are allowed for 'omp barrier' directive"); |
| 3216 | assert(AStmt == nullptr && |
| 3217 | "No associated statement allowed for 'omp barrier' directive"); |
| 3218 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3219 | break; |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3220 | case OMPD_taskwait: |
| 3221 | assert(ClausesWithImplicit.empty() && |
| 3222 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3223 | assert(AStmt == nullptr && |
| 3224 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3225 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3226 | break; |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3227 | case OMPD_taskgroup: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 3228 | Res = ActOnOpenMPTaskgroupDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3229 | EndLoc); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3230 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3231 | case OMPD_flush: |
| 3232 | assert(AStmt == nullptr && |
| 3233 | "No associated statement allowed for 'omp flush' directive"); |
| 3234 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3235 | break; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3236 | case OMPD_ordered: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3237 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3238 | EndLoc); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3239 | break; |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3240 | case OMPD_atomic: |
| 3241 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3242 | EndLoc); |
| 3243 | break; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3244 | case OMPD_teams: |
| 3245 | Res = |
| 3246 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3247 | break; |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3248 | case OMPD_target: |
| 3249 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3250 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3251 | AllowedNameModifiers.push_back(OMPD_target); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3252 | break; |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3253 | case OMPD_target_parallel: |
| 3254 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3255 | StartLoc, EndLoc); |
| 3256 | AllowedNameModifiers.push_back(OMPD_target); |
| 3257 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3258 | break; |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3259 | case OMPD_target_parallel_for: |
| 3260 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3261 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3262 | AllowedNameModifiers.push_back(OMPD_target); |
| 3263 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3264 | break; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3265 | case OMPD_cancellation_point: |
| 3266 | assert(ClausesWithImplicit.empty() && |
| 3267 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3268 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3269 | "cancellation point' directive"); |
| 3270 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3271 | break; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3272 | case OMPD_cancel: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3273 | assert(AStmt == nullptr && |
| 3274 | "No associated statement allowed for 'omp cancel' directive"); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3275 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3276 | CancelRegion); |
| 3277 | AllowedNameModifiers.push_back(OMPD_cancel); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3278 | break; |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3279 | case OMPD_target_data: |
| 3280 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3281 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3282 | AllowedNameModifiers.push_back(OMPD_target_data); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3283 | break; |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3284 | case OMPD_target_enter_data: |
| 3285 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3286 | EndLoc, AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3287 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3288 | break; |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3289 | case OMPD_target_exit_data: |
| 3290 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3291 | EndLoc, AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3292 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3293 | break; |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3294 | case OMPD_taskloop: |
| 3295 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3296 | EndLoc, VarsWithInheritedDSA); |
| 3297 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3298 | break; |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3299 | case OMPD_taskloop_simd: |
| 3300 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3301 | EndLoc, VarsWithInheritedDSA); |
| 3302 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3303 | break; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3304 | case OMPD_distribute: |
| 3305 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3306 | EndLoc, VarsWithInheritedDSA); |
| 3307 | break; |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3308 | case OMPD_target_update: |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3309 | Res = ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, |
| 3310 | EndLoc, AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3311 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 3312 | break; |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3313 | case OMPD_distribute_parallel_for: |
| 3314 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 3315 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3316 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3317 | break; |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3318 | case OMPD_distribute_parallel_for_simd: |
| 3319 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 3320 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3321 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3322 | break; |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3323 | case OMPD_distribute_simd: |
| 3324 | Res = ActOnOpenMPDistributeSimdDirective( |
| 3325 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3326 | break; |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3327 | case OMPD_target_parallel_for_simd: |
| 3328 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 3329 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3330 | AllowedNameModifiers.push_back(OMPD_target); |
| 3331 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3332 | break; |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3333 | case OMPD_target_simd: |
| 3334 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3335 | EndLoc, VarsWithInheritedDSA); |
| 3336 | AllowedNameModifiers.push_back(OMPD_target); |
| 3337 | break; |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3338 | case OMPD_teams_distribute: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3339 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 3340 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3341 | break; |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 3342 | case OMPD_teams_distribute_simd: |
| 3343 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 3344 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3345 | break; |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 3346 | case OMPD_teams_distribute_parallel_for_simd: |
| 3347 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 3348 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3349 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3350 | break; |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 3351 | case OMPD_teams_distribute_parallel_for: |
| 3352 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 3353 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3354 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3355 | break; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3356 | case OMPD_target_teams: |
| 3357 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3358 | EndLoc); |
| 3359 | AllowedNameModifiers.push_back(OMPD_target); |
| 3360 | break; |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 3361 | case OMPD_target_teams_distribute: |
| 3362 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 3363 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3364 | AllowedNameModifiers.push_back(OMPD_target); |
| 3365 | break; |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 3366 | case OMPD_target_teams_distribute_parallel_for: |
| 3367 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 3368 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3369 | AllowedNameModifiers.push_back(OMPD_target); |
| 3370 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3371 | break; |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 3372 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 3373 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 3374 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3375 | AllowedNameModifiers.push_back(OMPD_target); |
| 3376 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3377 | break; |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 3378 | case OMPD_target_teams_distribute_simd: |
| 3379 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 3380 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3381 | AllowedNameModifiers.push_back(OMPD_target); |
| 3382 | break; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3383 | case OMPD_declare_target: |
| 3384 | case OMPD_end_declare_target: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3385 | case OMPD_threadprivate: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3386 | case OMPD_declare_reduction: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3387 | case OMPD_declare_simd: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3388 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3389 | case OMPD_unknown: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3390 | llvm_unreachable("Unknown OpenMP directive"); |
| 3391 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3392 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3393 | for (const auto &P : VarsWithInheritedDSA) { |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3394 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3395 | << P.first << P.second->getSourceRange(); |
| 3396 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3397 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3398 | |
| 3399 | if (!AllowedNameModifiers.empty()) |
| 3400 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3401 | ErrorFound; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3402 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3403 | if (ErrorFound) |
| 3404 | return StmtError(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3405 | return Res; |
| 3406 | } |
| 3407 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3408 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3409 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3410 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3411 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3412 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3413 | assert(Aligneds.size() == Alignments.size()); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3414 | assert(Linears.size() == LinModifiers.size()); |
| 3415 | assert(Linears.size() == Steps.size()); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3416 | if (!DG || DG.get().isNull()) |
| 3417 | return DeclGroupPtrTy(); |
| 3418 | |
| 3419 | if (!DG.get().isSingleDecl()) { |
| Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3420 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3421 | return DG; |
| 3422 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3423 | Decl *ADecl = DG.get().getSingleDecl(); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3424 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3425 | ADecl = FTD->getTemplatedDecl(); |
| 3426 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3427 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3428 | if (!FD) { |
| 3429 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3430 | return DeclGroupPtrTy(); |
| 3431 | } |
| 3432 | |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3433 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3434 | // The parameter of the simdlen clause must be a constant positive integer |
| 3435 | // expression. |
| 3436 | ExprResult SL; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3437 | if (Simdlen) |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3438 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3439 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3440 | // The special this pointer can be used as if was one of the arguments to the |
| 3441 | // function in any of the linear, aligned, or uniform clauses. |
| 3442 | // The uniform clause declares one or more arguments to have an invariant |
| 3443 | // value for all concurrent invocations of the function in the execution of a |
| 3444 | // single SIMD loop. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3445 | llvm::DenseMap<const Decl *, const Expr *> UniformedArgs; |
| 3446 | const Expr *UniformedLinearThis = nullptr; |
| 3447 | for (const Expr *E : Uniforms) { |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3448 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3449 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3450 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3451 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3452 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3453 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 3454 | UniformedArgs.try_emplace(PVD->getCanonicalDecl(), E); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3455 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3456 | } |
| 3457 | if (isa<CXXThisExpr>(E)) { |
| 3458 | UniformedLinearThis = E; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3459 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3460 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3461 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3462 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3463 | } |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3464 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3465 | // The aligned clause declares that the object to which each list item points |
| 3466 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3467 | // the aligned clause. |
| 3468 | // The special this pointer can be used as if was one of the arguments to the |
| 3469 | // function in any of the linear, aligned, or uniform clauses. |
| 3470 | // The type of list items appearing in the aligned clause must be array, |
| 3471 | // pointer, reference to array, or reference to pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3472 | llvm::DenseMap<const Decl *, const Expr *> AlignedArgs; |
| 3473 | const Expr *AlignedThis = nullptr; |
| 3474 | for (const Expr *E : Aligneds) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3475 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3476 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3477 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3478 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3479 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3480 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3481 | ->getCanonicalDecl() == CanonPVD) { |
| 3482 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3483 | // A list-item cannot appear in more than one aligned clause. |
| 3484 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3485 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3486 | << 1 << E->getSourceRange(); |
| 3487 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3488 | diag::note_omp_explicit_dsa) |
| 3489 | << getOpenMPClauseName(OMPC_aligned); |
| 3490 | continue; |
| 3491 | } |
| 3492 | AlignedArgs[CanonPVD] = E; |
| 3493 | QualType QTy = PVD->getType() |
| 3494 | .getNonReferenceType() |
| 3495 | .getUnqualifiedType() |
| 3496 | .getCanonicalType(); |
| 3497 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3498 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3499 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3500 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3501 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3502 | } |
| 3503 | continue; |
| 3504 | } |
| 3505 | } |
| 3506 | if (isa<CXXThisExpr>(E)) { |
| 3507 | if (AlignedThis) { |
| 3508 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3509 | << 2 << E->getSourceRange(); |
| 3510 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3511 | << getOpenMPClauseName(OMPC_aligned); |
| 3512 | } |
| 3513 | AlignedThis = E; |
| 3514 | continue; |
| 3515 | } |
| 3516 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3517 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3518 | } |
| 3519 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3520 | // positive integer expression. If no optional parameter is specified, |
| 3521 | // implementation-defined default alignments for SIMD instructions on the |
| 3522 | // target platforms are assumed. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3523 | SmallVector<const Expr *, 4> NewAligns; |
| 3524 | for (Expr *E : Alignments) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3525 | ExprResult Align; |
| 3526 | if (E) |
| 3527 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3528 | NewAligns.push_back(Align.get()); |
| 3529 | } |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3530 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3531 | // The linear clause declares one or more list items to be private to a SIMD |
| 3532 | // lane and to have a linear relationship with respect to the iteration space |
| 3533 | // of a loop. |
| 3534 | // The special this pointer can be used as if was one of the arguments to the |
| 3535 | // function in any of the linear, aligned, or uniform clauses. |
| 3536 | // When a linear-step expression is specified in a linear clause it must be |
| 3537 | // either a constant integer expression or an integer-typed parameter that is |
| 3538 | // specified in a uniform clause on the directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3539 | llvm::DenseMap<const Decl *, const Expr *> LinearArgs; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3540 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3541 | auto MI = LinModifiers.begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3542 | for (const Expr *E : Linears) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3543 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3544 | ++MI; |
| 3545 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3546 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3547 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3548 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3549 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3550 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3551 | ->getCanonicalDecl() == CanonPVD) { |
| 3552 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3553 | // A list-item cannot appear in more than one linear clause. |
| 3554 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3555 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3556 | << getOpenMPClauseName(OMPC_linear) |
| 3557 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3558 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3559 | diag::note_omp_explicit_dsa) |
| 3560 | << getOpenMPClauseName(OMPC_linear); |
| 3561 | continue; |
| 3562 | } |
| 3563 | // Each argument can appear in at most one uniform or linear clause. |
| 3564 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3565 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3566 | << getOpenMPClauseName(OMPC_linear) |
| 3567 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3568 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3569 | diag::note_omp_explicit_dsa) |
| 3570 | << getOpenMPClauseName(OMPC_uniform); |
| 3571 | continue; |
| 3572 | } |
| 3573 | LinearArgs[CanonPVD] = E; |
| 3574 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3575 | E->isInstantiationDependent() || |
| 3576 | E->containsUnexpandedParameterPack()) |
| 3577 | continue; |
| 3578 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3579 | PVD->getOriginalType()); |
| 3580 | continue; |
| 3581 | } |
| 3582 | } |
| 3583 | if (isa<CXXThisExpr>(E)) { |
| 3584 | if (UniformedLinearThis) { |
| 3585 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3586 | << getOpenMPClauseName(OMPC_linear) |
| 3587 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3588 | << E->getSourceRange(); |
| 3589 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3590 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3591 | : OMPC_linear); |
| 3592 | continue; |
| 3593 | } |
| 3594 | UniformedLinearThis = E; |
| 3595 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3596 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3597 | continue; |
| 3598 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3599 | E->getType()); |
| 3600 | continue; |
| 3601 | } |
| 3602 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3603 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3604 | } |
| 3605 | Expr *Step = nullptr; |
| 3606 | Expr *NewStep = nullptr; |
| 3607 | SmallVector<Expr *, 4> NewSteps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3608 | for (Expr *E : Steps) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3609 | // Skip the same step expression, it was checked already. |
| 3610 | if (Step == E || !E) { |
| 3611 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3612 | continue; |
| 3613 | } |
| 3614 | Step = E; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3615 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3616 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3617 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3618 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3619 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3620 | << Step->getSourceRange(); |
| 3621 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3622 | E->isInstantiationDependent() || |
| 3623 | E->containsUnexpandedParameterPack() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3624 | CanonPVD->getType()->hasIntegerRepresentation()) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3625 | NewSteps.push_back(Step); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3626 | } else { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3627 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3628 | << Step->getSourceRange(); |
| 3629 | } |
| 3630 | continue; |
| 3631 | } |
| 3632 | NewStep = Step; |
| 3633 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3634 | !Step->isInstantiationDependent() && |
| 3635 | !Step->containsUnexpandedParameterPack()) { |
| 3636 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3637 | .get(); |
| 3638 | if (NewStep) |
| 3639 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3640 | } |
| 3641 | NewSteps.push_back(NewStep); |
| 3642 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3643 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3644 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3645 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3646 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3647 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3648 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3649 | NewSteps.data(), NewSteps.size(), SR); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3650 | ADecl->addAttr(NewAttr); |
| 3651 | return ConvertDeclToDeclGroup(ADecl); |
| 3652 | } |
| 3653 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3654 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3655 | Stmt *AStmt, |
| 3656 | SourceLocation StartLoc, |
| 3657 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3658 | if (!AStmt) |
| 3659 | return StmtError(); |
| 3660 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3661 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3662 | // 1.2.2 OpenMP Language Terminology |
| 3663 | // Structured block - An executable statement with a single entry at the |
| 3664 | // top and a single exit at the bottom. |
| 3665 | // The point of exit cannot be a branch out of the structured block. |
| 3666 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3667 | CS->getCapturedDecl()->setNothrow(); |
| 3668 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 3669 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3670 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3671 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3672 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3675 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3676 | /// Helper class for checking canonical form of the OpenMP loops and |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3677 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3678 | /// for IR generation. |
| 3679 | class OpenMPIterationSpaceChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3680 | /// Reference to Sema. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3681 | Sema &SemaRef; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3682 | /// A location for diagnostics (when there is no some better location). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3683 | SourceLocation DefaultLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3684 | /// A location for diagnostics (when increment is not compatible). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3685 | SourceLocation ConditionLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3686 | /// A source location for referring to loop init later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3687 | SourceRange InitSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3688 | /// A source location for referring to condition later. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3689 | SourceRange ConditionSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3690 | /// A source location for referring to increment later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3691 | SourceRange IncrementSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3692 | /// Loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3693 | ValueDecl *LCDecl = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3694 | /// Reference to loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3695 | Expr *LCRef = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3696 | /// Lower bound (initializer for the var). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3697 | Expr *LB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3698 | /// Upper bound. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3699 | Expr *UB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3700 | /// Loop step (increment). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3701 | Expr *Step = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3702 | /// This flag is true when condition is one of: |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3703 | /// Var < UB |
| 3704 | /// Var <= UB |
| 3705 | /// UB > Var |
| 3706 | /// UB >= Var |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3707 | bool TestIsLessOp = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3708 | /// This flag is true when condition is strict ( < or > ). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3709 | bool TestIsStrictOp = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3710 | /// This flag is true when step is subtracted on each iteration. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3711 | bool SubtractStep = false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3712 | |
| 3713 | public: |
| 3714 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3715 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3716 | /// Check init-expr for canonical loop form and save loop counter |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3717 | /// variable - #Var and its initialization value - #LB. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3718 | bool checkAndSetInit(Stmt *S, bool EmitDiags = true); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3719 | /// Check test-expr for canonical form, save upper-bound (#UB), flags |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3720 | /// for less/greater and for strict/non-strict comparison. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3721 | bool checkAndSetCond(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3722 | /// Check incr-expr for canonical loop form and return true if it |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3723 | /// does not conform, otherwise save loop step (#Step). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3724 | bool checkAndSetInc(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3725 | /// Return the loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3726 | ValueDecl *getLoopDecl() const { return LCDecl; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3727 | /// Return the reference expression to loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3728 | Expr *getLoopDeclRefExpr() const { return LCRef; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3729 | /// Source range of the loop init. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3730 | SourceRange getInitSrcRange() const { return InitSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3731 | /// Source range of the loop condition. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3732 | SourceRange getConditionSrcRange() const { return ConditionSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3733 | /// Source range of the loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3734 | SourceRange getIncrementSrcRange() const { return IncrementSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3735 | /// True if the step should be subtracted. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3736 | bool shouldSubtractStep() const { return SubtractStep; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3737 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3738 | Expr *buildNumIterations( |
| 3739 | Scope *S, const bool LimitedType, |
| 3740 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3741 | /// Build the precondition expression for the loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3742 | Expr * |
| 3743 | buildPreCond(Scope *S, Expr *Cond, |
| 3744 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3745 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3746 | DeclRefExpr * |
| 3747 | buildCounterVar(llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 3748 | DSAStackTy &DSA) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3749 | /// Build reference expression to the private counter be used for |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3750 | /// codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3751 | Expr *buildPrivateCounterVar() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3752 | /// Build initialization of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3753 | Expr *buildCounterInit() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3754 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3755 | Expr *buildCounterStep() const; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 3756 | /// Build loop data with counter value for depend clauses in ordered |
| 3757 | /// directives. |
| 3758 | Expr * |
| 3759 | buildOrderedLoopData(Scope *S, Expr *Counter, |
| 3760 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 3761 | SourceLocation Loc, Expr *Inc = nullptr, |
| 3762 | OverloadedOperatorKind OOK = OO_Amp); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3763 | /// Return true if any expression is dependent. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3764 | bool dependent() const; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3765 | |
| 3766 | private: |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3767 | /// Check the right-hand side of an assignment in the increment |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3768 | /// expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3769 | bool checkAndSetIncRHS(Expr *RHS); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3770 | /// Helper to set loop counter variable and its initializer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3771 | bool setLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3772 | /// Helper to set upper bound. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3773 | bool setUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
| Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3774 | SourceLocation SL); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3775 | /// Helper to set loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3776 | bool setStep(Expr *NewStep, bool Subtract); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3777 | }; |
| 3778 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3779 | bool OpenMPIterationSpaceChecker::dependent() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3780 | if (!LCDecl) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3781 | assert(!LB && !UB && !Step); |
| 3782 | return false; |
| 3783 | } |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3784 | return LCDecl->getType()->isDependentType() || |
| 3785 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 3786 | (Step && Step->isValueDependent()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3789 | bool OpenMPIterationSpaceChecker::setLCDeclAndLB(ValueDecl *NewLCDecl, |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3790 | Expr *NewLCRefExpr, |
| 3791 | Expr *NewLB) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3792 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3793 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
| Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3794 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3795 | if (!NewLCDecl || !NewLB) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3796 | return true; |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3797 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 3798 | LCRef = NewLCRefExpr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3799 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3800 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3801 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3802 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3803 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3804 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3805 | LB = NewLB; |
| 3806 | return false; |
| 3807 | } |
| 3808 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3809 | bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3810 | SourceRange SR, SourceLocation SL) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3811 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3812 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 3813 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3814 | if (!NewUB) |
| 3815 | return true; |
| 3816 | UB = NewUB; |
| 3817 | TestIsLessOp = LessOp; |
| 3818 | TestIsStrictOp = StrictOp; |
| 3819 | ConditionSrcRange = SR; |
| 3820 | ConditionLoc = SL; |
| 3821 | return false; |
| 3822 | } |
| 3823 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3824 | bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3825 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3826 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3827 | if (!NewStep) |
| 3828 | return true; |
| 3829 | if (!NewStep->isValueDependent()) { |
| 3830 | // Check that the step is integer expression. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3831 | SourceLocation StepLoc = NewStep->getBeginLoc(); |
| Alexey Bataev | 5372fb8 | 2017-08-31 23:06:52 +0000 | [diff] [blame] | 3832 | ExprResult Val = SemaRef.PerformOpenMPImplicitIntegerConversion( |
| 3833 | StepLoc, getExprAsWritten(NewStep)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3834 | if (Val.isInvalid()) |
| 3835 | return true; |
| 3836 | NewStep = Val.get(); |
| 3837 | |
| 3838 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3839 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3840 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3841 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3842 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3843 | // the loop. |
| 3844 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3845 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3846 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3847 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3848 | // the loop. |
| 3849 | llvm::APSInt Result; |
| 3850 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3851 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3852 | bool IsConstNeg = |
| 3853 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3854 | bool IsConstPos = |
| 3855 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3856 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3857 | if (UB && (IsConstZero || |
| 3858 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3859 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3860 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3861 | diag::err_omp_loop_incr_not_compatible) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3862 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3863 | SemaRef.Diag(ConditionLoc, |
| 3864 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3865 | << TestIsLessOp << ConditionSrcRange; |
| 3866 | return true; |
| 3867 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3868 | if (TestIsLessOp == Subtract) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3869 | NewStep = |
| 3870 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3871 | .get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3872 | Subtract = !Subtract; |
| 3873 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | Step = NewStep; |
| 3877 | SubtractStep = Subtract; |
| 3878 | return false; |
| 3879 | } |
| 3880 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3881 | bool OpenMPIterationSpaceChecker::checkAndSetInit(Stmt *S, bool EmitDiags) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3882 | // Check init-expr for canonical loop form and save loop counter |
| 3883 | // variable - #Var and its initialization value - #LB. |
| 3884 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3885 | // var = lb |
| 3886 | // integer-type var = lb |
| 3887 | // random-access-iterator-type var = lb |
| 3888 | // pointer-type var = lb |
| 3889 | // |
| 3890 | if (!S) { |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3891 | if (EmitDiags) { |
| 3892 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3893 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3894 | return true; |
| 3895 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3896 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3897 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3898 | S = ExprTemp->getSubExpr(); |
| 3899 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3900 | InitSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3901 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3902 | S = E->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3903 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3904 | if (BO->getOpcode() == BO_Assign) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3905 | Expr *LHS = BO->getLHS()->IgnoreParens(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3906 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3907 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3908 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3909 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3910 | return setLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3911 | } |
| 3912 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3913 | if (ME->isArrow() && |
| 3914 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3915 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3916 | } |
| 3917 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3918 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3919 | if (DS->isSingleDecl()) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3920 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3921 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3922 | // Accept non-canonical init form here but emit ext. warning. |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3923 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3924 | SemaRef.Diag(S->getBeginLoc(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3925 | diag::ext_omp_loop_not_canonical_init) |
| 3926 | << S->getSourceRange(); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 3927 | return setLCDeclAndLB( |
| 3928 | Var, |
| 3929 | buildDeclRefExpr(SemaRef, Var, |
| 3930 | Var->getType().getNonReferenceType(), |
| 3931 | DS->getBeginLoc()), |
| 3932 | Var->getInit()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3936 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3937 | if (CE->getOperator() == OO_Equal) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3938 | Expr *LHS = CE->getArg(0); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3939 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3940 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3941 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3942 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3943 | return setLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3944 | } |
| 3945 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3946 | if (ME->isArrow() && |
| 3947 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3948 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3949 | } |
| 3950 | } |
| 3951 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3952 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3953 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3954 | return false; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3955 | if (EmitDiags) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3956 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_init) |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3957 | << S->getSourceRange(); |
| 3958 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3959 | return true; |
| 3960 | } |
| 3961 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3962 | /// Ignore parenthesizes, implicit casts, copy constructor and return the |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3963 | /// variable (which may be the loop variable) if possible. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3964 | static const ValueDecl *getInitLCDecl(const Expr *E) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3965 | if (!E) |
| Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3966 | return nullptr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3967 | E = getExprAsWritten(E); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3968 | if (const auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3969 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3970 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3971 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3972 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3973 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3974 | if (const auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3975 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3976 | return getCanonicalDecl(VD); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3977 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3978 | if (const auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3979 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3980 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3981 | return nullptr; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3982 | } |
| 3983 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3984 | bool OpenMPIterationSpaceChecker::checkAndSetCond(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3985 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3986 | // less/greater and for strict/non-strict comparison. |
| 3987 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3988 | // var relational-op b |
| 3989 | // b relational-op var |
| 3990 | // |
| 3991 | if (!S) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3992 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3993 | return true; |
| 3994 | } |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3995 | S = getExprAsWritten(S); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3996 | SourceLocation CondLoc = S->getBeginLoc(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3997 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3998 | if (BO->isRelationalOp()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3999 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4000 | return setUB(BO->getRHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4001 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 4002 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4003 | BO->getSourceRange(), BO->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4004 | if (getInitLCDecl(BO->getRHS()) == LCDecl) |
| 4005 | return setUB(BO->getLHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4006 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 4007 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4008 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 4009 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4010 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4011 | if (CE->getNumArgs() == 2) { |
| 4012 | auto Op = CE->getOperator(); |
| 4013 | switch (Op) { |
| 4014 | case OO_Greater: |
| 4015 | case OO_GreaterEqual: |
| 4016 | case OO_Less: |
| 4017 | case OO_LessEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4018 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4019 | return setUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4020 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4021 | CE->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4022 | if (getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 4023 | return setUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4024 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4025 | CE->getOperatorLoc()); |
| 4026 | break; |
| 4027 | default: |
| 4028 | break; |
| 4029 | } |
| 4030 | } |
| 4031 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4032 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4033 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4034 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4035 | << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4036 | return true; |
| 4037 | } |
| 4038 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4039 | bool OpenMPIterationSpaceChecker::checkAndSetIncRHS(Expr *RHS) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4040 | // RHS of canonical loop form increment can be: |
| 4041 | // var + incr |
| 4042 | // incr + var |
| 4043 | // var - incr |
| 4044 | // |
| 4045 | RHS = RHS->IgnoreParenImpCasts(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4046 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4047 | if (BO->isAdditiveOp()) { |
| 4048 | bool IsAdd = BO->getOpcode() == BO_Add; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4049 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4050 | return setStep(BO->getRHS(), !IsAdd); |
| 4051 | if (IsAdd && getInitLCDecl(BO->getRHS()) == LCDecl) |
| 4052 | return setStep(BO->getLHS(), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4053 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4054 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4055 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 4056 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4057 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4058 | return setStep(CE->getArg(1), !IsAdd); |
| 4059 | if (IsAdd && getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 4060 | return setStep(CE->getArg(0), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4061 | } |
| 4062 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4063 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4064 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4065 | SemaRef.Diag(RHS->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4066 | << RHS->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4067 | return true; |
| 4068 | } |
| 4069 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4070 | bool OpenMPIterationSpaceChecker::checkAndSetInc(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4071 | // Check incr-expr for canonical loop form and return true if it |
| 4072 | // does not conform. |
| 4073 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4074 | // ++var |
| 4075 | // var++ |
| 4076 | // --var |
| 4077 | // var-- |
| 4078 | // var += incr |
| 4079 | // var -= incr |
| 4080 | // var = var + incr |
| 4081 | // var = incr + var |
| 4082 | // var = var - incr |
| 4083 | // |
| 4084 | if (!S) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4085 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4086 | return true; |
| 4087 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4088 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4089 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4090 | S = ExprTemp->getSubExpr(); |
| 4091 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4092 | IncrementSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4093 | S = S->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4094 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4095 | if (UO->isIncrementDecrementOp() && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4096 | getInitLCDecl(UO->getSubExpr()) == LCDecl) |
| 4097 | return setStep(SemaRef |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4098 | .ActOnIntegerConstant(UO->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4099 | (UO->isDecrementOp() ? -1 : 1)) |
| 4100 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4101 | /*Subtract=*/false); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4102 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4103 | switch (BO->getOpcode()) { |
| 4104 | case BO_AddAssign: |
| 4105 | case BO_SubAssign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4106 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4107 | return setStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4108 | break; |
| 4109 | case BO_Assign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4110 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4111 | return checkAndSetIncRHS(BO->getRHS()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4112 | break; |
| 4113 | default: |
| 4114 | break; |
| 4115 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4116 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4117 | switch (CE->getOperator()) { |
| 4118 | case OO_PlusPlus: |
| 4119 | case OO_MinusMinus: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4120 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4121 | return setStep(SemaRef |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4122 | .ActOnIntegerConstant( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4123 | CE->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4124 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 4125 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4126 | /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4127 | break; |
| 4128 | case OO_PlusEqual: |
| 4129 | case OO_MinusEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4130 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4131 | return setStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | case OO_Equal: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4134 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4135 | return checkAndSetIncRHS(CE->getArg(1)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4136 | break; |
| 4137 | default: |
| 4138 | break; |
| 4139 | } |
| 4140 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4141 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4142 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4143 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4144 | << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4145 | return true; |
| 4146 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4147 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4148 | static ExprResult |
| 4149 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4150 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 4151 | if (SemaRef.CurContext->isDependentContext()) |
| 4152 | return ExprResult(Capture); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4153 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 4154 | return SemaRef.PerformImplicitConversion( |
| 4155 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4156 | /*AllowExplicit=*/true); |
| 4157 | auto I = Captures.find(Capture); |
| 4158 | if (I != Captures.end()) |
| 4159 | return buildCapture(SemaRef, Capture, I->second); |
| 4160 | DeclRefExpr *Ref = nullptr; |
| 4161 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4162 | Captures[Capture] = Ref; |
| 4163 | return Res; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4166 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4167 | Expr *OpenMPIterationSpaceChecker::buildNumIterations( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4168 | Scope *S, const bool LimitedType, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4169 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4170 | ExprResult Diff; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4171 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4172 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4173 | SemaRef.getLangOpts().CPlusPlus) { |
| 4174 | // Upper - Lower |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4175 | Expr *UBExpr = TestIsLessOp ? UB : LB; |
| 4176 | Expr *LBExpr = TestIsLessOp ? LB : UB; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4177 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4178 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4179 | if (!Upper || !Lower) |
| 4180 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4181 | |
| 4182 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4183 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4184 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4185 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4186 | // and lower bound, and to tell what is passed to 'operator-'. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4187 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4188 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4189 | return nullptr; |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | if (!Diff.isUsable()) |
| 4194 | return nullptr; |
| 4195 | |
| 4196 | // Upper - Lower [- 1] |
| 4197 | if (TestIsStrictOp) |
| 4198 | Diff = SemaRef.BuildBinOp( |
| 4199 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4200 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4201 | if (!Diff.isUsable()) |
| 4202 | return nullptr; |
| 4203 | |
| 4204 | // Upper - Lower [- 1] + Step |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4205 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4206 | if (!NewStep.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4207 | return nullptr; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4208 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4209 | if (!Diff.isUsable()) |
| 4210 | return nullptr; |
| 4211 | |
| 4212 | // Parentheses (for dumping/debugging purposes only). |
| 4213 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4214 | if (!Diff.isUsable()) |
| 4215 | return nullptr; |
| 4216 | |
| 4217 | // (Upper - Lower [- 1] + Step) / Step |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4218 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4219 | if (!Diff.isUsable()) |
| 4220 | return nullptr; |
| 4221 | |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4222 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4223 | QualType Type = Diff.get()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4224 | ASTContext &C = SemaRef.Context; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4225 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4226 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4227 | if (!Type->isIntegerType() || UseVarType) { |
| 4228 | unsigned NewSize = |
| 4229 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4230 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4231 | : Type->hasSignedIntegerRepresentation(); |
| 4232 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4233 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4234 | Diff = SemaRef.PerformImplicitConversion( |
| 4235 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4236 | if (!Diff.isUsable()) |
| 4237 | return nullptr; |
| 4238 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4239 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4240 | if (LimitedType) { |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4241 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4242 | if (NewSize != C.getTypeSize(Type)) { |
| 4243 | if (NewSize < C.getTypeSize(Type)) { |
| 4244 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4245 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4246 | << InitSrcRange << ConditionSrcRange; |
| 4247 | } |
| 4248 | QualType NewType = C.getIntTypeForBitwidth( |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4249 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4250 | C.getTypeSize(Type) < NewSize); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4251 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4252 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4253 | Sema::AA_Converting, true); |
| 4254 | if (!Diff.isUsable()) |
| 4255 | return nullptr; |
| 4256 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4257 | } |
| 4258 | } |
| 4259 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4260 | return Diff.get(); |
| 4261 | } |
| 4262 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4263 | Expr *OpenMPIterationSpaceChecker::buildPreCond( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4264 | Scope *S, Expr *Cond, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4265 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4266 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4267 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4268 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4269 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4270 | ExprResult NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4271 | ExprResult NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4272 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4273 | return nullptr; |
| 4274 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4275 | ExprResult CondExpr = |
| 4276 | SemaRef.BuildBinOp(S, DefaultLoc, |
| 4277 | TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 4278 | : (TestIsStrictOp ? BO_GT : BO_GE), |
| 4279 | NewLB.get(), NewUB.get()); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4280 | if (CondExpr.isUsable()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4281 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4282 | SemaRef.Context.BoolTy)) |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4283 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4284 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4285 | /*AllowExplicit=*/true); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4286 | } |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4287 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4288 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 4289 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4290 | } |
| 4291 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4292 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4293 | DeclRefExpr *OpenMPIterationSpaceChecker::buildCounterVar( |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4294 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 4295 | DSAStackTy &DSA) const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4296 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4297 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4298 | VD = SemaRef.isOpenMPCapturedDecl(LCDecl); |
| 4299 | DeclRefExpr *Ref = buildDeclRefExpr( |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4300 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4301 | const DSAStackTy::DSAVarData Data = |
| 4302 | DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4303 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4304 | // as captured again. |
| 4305 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4306 | Captures.insert(std::make_pair(LCRef, Ref)); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4307 | return Ref; |
| 4308 | } |
| 4309 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4310 | DefaultLoc); |
| 4311 | } |
| 4312 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4313 | Expr *OpenMPIterationSpaceChecker::buildPrivateCounterVar() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4314 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4315 | QualType Type = LCDecl->getType().getNonReferenceType(); |
| 4316 | VarDecl *PrivateVar = buildVarDecl( |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 4317 | SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4318 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr, |
| 4319 | isa<VarDecl>(LCDecl) |
| 4320 | ? buildDeclRefExpr(SemaRef, cast<VarDecl>(LCDecl), Type, DefaultLoc) |
| 4321 | : nullptr); |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4322 | if (PrivateVar->isInvalidDecl()) |
| 4323 | return nullptr; |
| 4324 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4325 | } |
| 4326 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4329 | /// Build initialization of the counter to be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4330 | Expr *OpenMPIterationSpaceChecker::buildCounterInit() const { return LB; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4331 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4332 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4333 | Expr *OpenMPIterationSpaceChecker::buildCounterStep() const { return Step; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4334 | |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4335 | Expr *OpenMPIterationSpaceChecker::buildOrderedLoopData( |
| 4336 | Scope *S, Expr *Counter, |
| 4337 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, SourceLocation Loc, |
| 4338 | Expr *Inc, OverloadedOperatorKind OOK) { |
| 4339 | Expr *Cnt = SemaRef.DefaultLvalueConversion(Counter).get(); |
| 4340 | if (!Cnt) |
| 4341 | return nullptr; |
| 4342 | if (Inc) { |
| 4343 | assert((OOK == OO_Plus || OOK == OO_Minus) && |
| 4344 | "Expected only + or - operations for depend clauses."); |
| 4345 | BinaryOperatorKind BOK = (OOK == OO_Plus) ? BO_Add : BO_Sub; |
| 4346 | Cnt = SemaRef.BuildBinOp(S, Loc, BOK, Cnt, Inc).get(); |
| 4347 | if (!Cnt) |
| 4348 | return nullptr; |
| 4349 | } |
| 4350 | ExprResult Diff; |
| 4351 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| 4352 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| 4353 | SemaRef.getLangOpts().CPlusPlus) { |
| 4354 | // Upper - Lower |
| 4355 | Expr *Upper = |
| 4356 | TestIsLessOp ? Cnt : tryBuildCapture(SemaRef, UB, Captures).get(); |
| 4357 | Expr *Lower = |
| 4358 | TestIsLessOp ? tryBuildCapture(SemaRef, LB, Captures).get() : Cnt; |
| 4359 | if (!Upper || !Lower) |
| 4360 | return nullptr; |
| 4361 | |
| 4362 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4363 | |
| 4364 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| 4365 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4366 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4367 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| 4368 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4369 | return nullptr; |
| 4370 | } |
| 4371 | } |
| 4372 | |
| 4373 | if (!Diff.isUsable()) |
| 4374 | return nullptr; |
| 4375 | |
| 4376 | // Parentheses (for dumping/debugging purposes only). |
| 4377 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4378 | if (!Diff.isUsable()) |
| 4379 | return nullptr; |
| 4380 | |
| 4381 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4382 | if (!NewStep.isUsable()) |
| 4383 | return nullptr; |
| 4384 | // (Upper - Lower) / Step |
| 4385 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| 4386 | if (!Diff.isUsable()) |
| 4387 | return nullptr; |
| 4388 | |
| 4389 | return Diff.get(); |
| 4390 | } |
| 4391 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4392 | /// Iteration space of a single for loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4393 | struct LoopIterationSpace final { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4394 | /// Condition of the loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4395 | Expr *PreCond = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4396 | /// This expression calculates the number of iterations in the loop. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4397 | /// It is always possible to calculate it before starting the loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4398 | Expr *NumIterations = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4399 | /// The loop counter variable. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4400 | Expr *CounterVar = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4401 | /// Private loop counter variable. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4402 | Expr *PrivateCounterVar = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4403 | /// This is initializer for the initial value of #CounterVar. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4404 | Expr *CounterInit = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4405 | /// This is step for the #CounterVar used to generate its update: |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4406 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4407 | Expr *CounterStep = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4408 | /// Should step be subtracted? |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4409 | bool Subtract = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4410 | /// Source range of the loop init. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4411 | SourceRange InitSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4412 | /// Source range of the loop condition. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4413 | SourceRange CondSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4414 | /// Source range of the loop increment. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4415 | SourceRange IncSrcRange; |
| 4416 | }; |
| 4417 | |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4418 | } // namespace |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4419 | |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4420 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4421 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4422 | assert(Init && "Expected loop in canonical form."); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4423 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4424 | if (AssociatedLoops > 0 && |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4425 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 4426 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4427 | if (!ISC.checkAndSetInit(Init, /*EmitDiags=*/false)) { |
| 4428 | if (ValueDecl *D = ISC.getLoopDecl()) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4429 | auto *VD = dyn_cast<VarDecl>(D); |
| 4430 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4431 | if (VarDecl *Private = isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4432 | VD = Private; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4433 | } else { |
| 4434 | DeclRefExpr *Ref = buildCapture(*this, D, ISC.getLoopDeclRefExpr(), |
| 4435 | /*WithInit=*/false); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4436 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4437 | } |
| 4438 | } |
| 4439 | DSAStack->addLoopControlVariable(D, VD); |
| 4440 | } |
| 4441 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4442 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4443 | } |
| 4444 | } |
| 4445 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4446 | /// Called on a for stmt to check and extract its iteration space |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4447 | /// for further processing (such as collapsing). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4448 | static bool checkOpenMPIterationSpace( |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4449 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4450 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4451 | unsigned TotalNestedLoopCount, Expr *CollapseLoopCountExpr, |
| 4452 | Expr *OrderedLoopCountExpr, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4453 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4454 | LoopIterationSpace &ResultIterSpace, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4455 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4456 | // OpenMP [2.6, Canonical Loop Form] |
| 4457 | // for (init-expr; test-expr; incr-expr) structured-block |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4458 | auto *For = dyn_cast_or_null<ForStmt>(S); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4459 | if (!For) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4460 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4461 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4462 | << getOpenMPDirectiveName(DKind) << TotalNestedLoopCount |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4463 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4464 | if (TotalNestedLoopCount > 1) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4465 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4466 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4467 | diag::note_omp_collapse_ordered_expr) |
| 4468 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4469 | << OrderedLoopCountExpr->getSourceRange(); |
| 4470 | else if (CollapseLoopCountExpr) |
| 4471 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4472 | diag::note_omp_collapse_ordered_expr) |
| 4473 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4474 | else |
| 4475 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4476 | diag::note_omp_collapse_ordered_expr) |
| 4477 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4478 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4479 | return true; |
| 4480 | } |
| 4481 | assert(For->getBody()); |
| 4482 | |
| 4483 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4484 | |
| 4485 | // Check init. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4486 | Stmt *Init = For->getInit(); |
| 4487 | if (ISC.checkAndSetInit(Init)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4488 | return true; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4489 | |
| 4490 | bool HasErrors = false; |
| 4491 | |
| 4492 | // Check loop variable's type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4493 | if (ValueDecl *LCDecl = ISC.getLoopDecl()) { |
| 4494 | Expr *LoopDeclRefExpr = ISC.getLoopDeclRefExpr(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4495 | |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4496 | // OpenMP [2.6, Canonical Loop Form] |
| 4497 | // Var is one of the following: |
| 4498 | // A variable of signed or unsigned integer type. |
| 4499 | // For C++, a variable of a random access iterator type. |
| 4500 | // For C, a variable of a pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4501 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4502 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4503 | !VarType->isPointerType() && |
| 4504 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4505 | SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_variable_type) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4506 | << SemaRef.getLangOpts().CPlusPlus; |
| 4507 | HasErrors = true; |
| 4508 | } |
| 4509 | |
| 4510 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4511 | // a Construct |
| 4512 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4513 | // parallel for construct is (are) private. |
| 4514 | // The loop iteration variable in the associated for-loop of a simd |
| 4515 | // construct with just one associated for-loop is linear with a |
| 4516 | // constant-linear-step that is the increment of the associated for-loop. |
| 4517 | // Exclude loop var from the list of variables with implicitly defined data |
| 4518 | // sharing attributes. |
| 4519 | VarsWithImplicitDSA.erase(LCDecl); |
| 4520 | |
| 4521 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4522 | // in a Construct, C/C++]. |
| 4523 | // The loop iteration variable in the associated for-loop of a simd |
| 4524 | // construct with just one associated for-loop may be listed in a linear |
| 4525 | // clause with a constant-linear-step that is the increment of the |
| 4526 | // associated for-loop. |
| 4527 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4528 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4529 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4530 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4531 | // declared in the loop and it is predetermined as a private. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4532 | OpenMPClauseKind PredeterminedCKind = |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4533 | isOpenMPSimdDirective(DKind) |
| 4534 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4535 | : OMPC_private; |
| 4536 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4537 | DVar.CKind != PredeterminedCKind) || |
| 4538 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4539 | isOpenMPDistributeDirective(DKind)) && |
| 4540 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4541 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4542 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4543 | SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4544 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4545 | << getOpenMPClauseName(PredeterminedCKind); |
| 4546 | if (DVar.RefExpr == nullptr) |
| 4547 | DVar.CKind = PredeterminedCKind; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4548 | reportOriginalDsa(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4549 | HasErrors = true; |
| 4550 | } else if (LoopDeclRefExpr != nullptr) { |
| 4551 | // Make the loop iteration variable private (for worksharing constructs), |
| 4552 | // linear (for simd directives with the only one associated loop) or |
| 4553 | // lastprivate (for simd directives with several collapsed or ordered |
| 4554 | // loops). |
| 4555 | if (DVar.CKind == OMPC_unknown) |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 4556 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 4557 | [](OpenMPDirectiveKind) -> bool { return true; }, |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4558 | /*FromParent=*/false); |
| 4559 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4560 | } |
| 4561 | |
| 4562 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4563 | |
| 4564 | // Check test-expr. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4565 | HasErrors |= ISC.checkAndSetCond(For->getCond()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4566 | |
| 4567 | // Check incr-expr. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4568 | HasErrors |= ISC.checkAndSetInc(For->getInc()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4571 | if (ISC.dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4572 | return HasErrors; |
| 4573 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4574 | // Build the loop's iteration space representation. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4575 | ResultIterSpace.PreCond = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4576 | ISC.buildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
| 4577 | ResultIterSpace.NumIterations = ISC.buildNumIterations( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4578 | DSA.getCurScope(), |
| 4579 | (isOpenMPWorksharingDirective(DKind) || |
| 4580 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4581 | Captures); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4582 | ResultIterSpace.CounterVar = ISC.buildCounterVar(Captures, DSA); |
| 4583 | ResultIterSpace.PrivateCounterVar = ISC.buildPrivateCounterVar(); |
| 4584 | ResultIterSpace.CounterInit = ISC.buildCounterInit(); |
| 4585 | ResultIterSpace.CounterStep = ISC.buildCounterStep(); |
| 4586 | ResultIterSpace.InitSrcRange = ISC.getInitSrcRange(); |
| 4587 | ResultIterSpace.CondSrcRange = ISC.getConditionSrcRange(); |
| 4588 | ResultIterSpace.IncSrcRange = ISC.getIncrementSrcRange(); |
| 4589 | ResultIterSpace.Subtract = ISC.shouldSubtractStep(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4590 | |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4591 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4592 | ResultIterSpace.NumIterations == nullptr || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4593 | ResultIterSpace.CounterVar == nullptr || |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4594 | ResultIterSpace.PrivateCounterVar == nullptr || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4595 | ResultIterSpace.CounterInit == nullptr || |
| 4596 | ResultIterSpace.CounterStep == nullptr); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4597 | if (!HasErrors && DSA.isOrderedRegion()) { |
| 4598 | if (DSA.getOrderedRegionParam().second->getNumForLoops()) { |
| 4599 | if (CurrentNestedLoopCount < |
| 4600 | DSA.getOrderedRegionParam().second->getLoopNumIterations().size()) { |
| 4601 | DSA.getOrderedRegionParam().second->setLoopNumIterations( |
| 4602 | CurrentNestedLoopCount, ResultIterSpace.NumIterations); |
| 4603 | DSA.getOrderedRegionParam().second->setLoopCounter( |
| 4604 | CurrentNestedLoopCount, ResultIterSpace.CounterVar); |
| 4605 | } |
| 4606 | } |
| 4607 | for (auto &Pair : DSA.getDoacrossDependClauses()) { |
| 4608 | if (CurrentNestedLoopCount >= Pair.first->getNumLoops()) { |
| 4609 | // Erroneous case - clause has some problems. |
| 4610 | continue; |
| 4611 | } |
| 4612 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_sink && |
| 4613 | Pair.second.size() <= CurrentNestedLoopCount) { |
| 4614 | // Erroneous case - clause has some problems. |
| 4615 | Pair.first->setLoopData(CurrentNestedLoopCount, nullptr); |
| 4616 | continue; |
| 4617 | } |
| 4618 | Expr *CntValue; |
| 4619 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4620 | CntValue = ISC.buildOrderedLoopData( |
| 4621 | DSA.getCurScope(), ResultIterSpace.CounterVar, Captures, |
| 4622 | Pair.first->getDependencyLoc()); |
| 4623 | else |
| 4624 | CntValue = ISC.buildOrderedLoopData( |
| 4625 | DSA.getCurScope(), ResultIterSpace.CounterVar, Captures, |
| 4626 | Pair.first->getDependencyLoc(), |
| 4627 | Pair.second[CurrentNestedLoopCount].first, |
| 4628 | Pair.second[CurrentNestedLoopCount].second); |
| 4629 | Pair.first->setLoopData(CurrentNestedLoopCount, CntValue); |
| 4630 | } |
| 4631 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4632 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4633 | return HasErrors; |
| 4634 | } |
| 4635 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4636 | /// Build 'VarRef = Start. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4637 | static ExprResult |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4638 | buildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4639 | ExprResult Start, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4640 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4641 | // Build 'VarRef = Start. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4642 | ExprResult NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4643 | if (!NewStart.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4644 | return ExprError(); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4645 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4646 | VarRef.get()->getType())) { |
| 4647 | NewStart = SemaRef.PerformImplicitConversion( |
| 4648 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4649 | /*AllowExplicit=*/true); |
| 4650 | if (!NewStart.isUsable()) |
| 4651 | return ExprError(); |
| 4652 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4653 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4654 | ExprResult Init = |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4655 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4656 | return Init; |
| 4657 | } |
| 4658 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4659 | /// Build 'VarRef = Start + Iter * Step'. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4660 | static ExprResult buildCounterUpdate( |
| 4661 | Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4662 | ExprResult Start, ExprResult Iter, ExprResult Step, bool Subtract, |
| 4663 | llvm::MapVector<const Expr *, DeclRefExpr *> *Captures = nullptr) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4664 | // Add parentheses (for debugging purposes only). |
| 4665 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4666 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4667 | !Step.isUsable()) |
| 4668 | return ExprError(); |
| 4669 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4670 | ExprResult NewStep = Step; |
| 4671 | if (Captures) |
| 4672 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4673 | if (NewStep.isInvalid()) |
| 4674 | return ExprError(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4675 | ExprResult Update = |
| 4676 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4677 | if (!Update.isUsable()) |
| 4678 | return ExprError(); |
| 4679 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4680 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4681 | // 'VarRef = Start (+|-) Iter * Step'. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4682 | ExprResult NewStart = Start; |
| 4683 | if (Captures) |
| 4684 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4685 | if (NewStart.isInvalid()) |
| 4686 | return ExprError(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4687 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4688 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4689 | ExprResult SavedUpdate = Update; |
| 4690 | ExprResult UpdateVal; |
| 4691 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4692 | NewStart.get()->getType()->isOverloadableType() || |
| 4693 | Update.get()->getType()->isOverloadableType()) { |
| 4694 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4695 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4696 | Update = |
| 4697 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4698 | if (Update.isUsable()) { |
| 4699 | UpdateVal = |
| 4700 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4701 | VarRef.get(), SavedUpdate.get()); |
| 4702 | if (UpdateVal.isUsable()) { |
| 4703 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4704 | UpdateVal.get()); |
| 4705 | } |
| 4706 | } |
| 4707 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4708 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4709 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4710 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4711 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4712 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4713 | NewStart.get(), SavedUpdate.get()); |
| 4714 | if (!Update.isUsable()) |
| 4715 | return ExprError(); |
| 4716 | |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4717 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4718 | VarRef.get()->getType())) { |
| 4719 | Update = SemaRef.PerformImplicitConversion( |
| 4720 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4721 | if (!Update.isUsable()) |
| 4722 | return ExprError(); |
| 4723 | } |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4724 | |
| 4725 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4726 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4727 | return Update; |
| 4728 | } |
| 4729 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4730 | /// 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] | 4731 | /// bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4732 | static ExprResult widenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4733 | if (E == nullptr) |
| 4734 | return ExprError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4735 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4736 | QualType OldType = E->getType(); |
| 4737 | unsigned HasBits = C.getTypeSize(OldType); |
| 4738 | if (HasBits >= Bits) |
| 4739 | return ExprResult(E); |
| 4740 | // OK to convert to signed, because new type has more bits than old. |
| 4741 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4742 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4743 | true); |
| 4744 | } |
| 4745 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4746 | /// 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] | 4747 | /// into \a Bits bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4748 | static bool fitsInto(unsigned Bits, bool Signed, const Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4749 | if (E == nullptr) |
| 4750 | return false; |
| 4751 | llvm::APSInt Result; |
| 4752 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4753 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4754 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4757 | /// Build preinits statement for the given declarations. |
| 4758 | static Stmt *buildPreInits(ASTContext &Context, |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 4759 | MutableArrayRef<Decl *> PreInits) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4760 | if (!PreInits.empty()) { |
| 4761 | return new (Context) DeclStmt( |
| 4762 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4763 | SourceLocation(), SourceLocation()); |
| 4764 | } |
| 4765 | return nullptr; |
| 4766 | } |
| 4767 | |
| 4768 | /// Build preinits statement for the given declarations. |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 4769 | static Stmt * |
| 4770 | buildPreInits(ASTContext &Context, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4771 | const llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4772 | if (!Captures.empty()) { |
| 4773 | SmallVector<Decl *, 16> PreInits; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4774 | for (const auto &Pair : Captures) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4775 | PreInits.push_back(Pair.second->getDecl()); |
| 4776 | return buildPreInits(Context, PreInits); |
| 4777 | } |
| 4778 | return nullptr; |
| 4779 | } |
| 4780 | |
| 4781 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4782 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4783 | Expr *PostUpdate = nullptr; |
| 4784 | if (!PostUpdates.empty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4785 | for (Expr *E : PostUpdates) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4786 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4787 | E->getExprLoc(), |
| 4788 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4789 | E->getExprLoc(), E) |
| 4790 | .get(); |
| 4791 | PostUpdate = PostUpdate |
| 4792 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4793 | PostUpdate, ConvE) |
| 4794 | .get() |
| 4795 | : ConvE; |
| 4796 | } |
| 4797 | } |
| 4798 | return PostUpdate; |
| 4799 | } |
| 4800 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4801 | /// 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] | 4802 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4803 | /// number of collapsed loops otherwise. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4804 | static unsigned |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4805 | checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4806 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4807 | DSAStackTy &DSA, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4808 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4809 | OMPLoopDirective::HelperExprs &Built) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4810 | unsigned NestedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4811 | if (CollapseLoopCountExpr) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4812 | // Found 'collapse' clause - calculate collapse number. |
| 4813 | llvm::APSInt Result; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4814 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4815 | NestedLoopCount = Result.getLimitedValue(); |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4816 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4817 | unsigned OrderedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4818 | if (OrderedLoopCountExpr) { |
| 4819 | // Found 'ordered' clause - calculate collapse number. |
| 4820 | llvm::APSInt Result; |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4821 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4822 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4823 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4824 | diag::err_omp_wrong_ordered_loop_count) |
| 4825 | << OrderedLoopCountExpr->getSourceRange(); |
| 4826 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4827 | diag::note_collapse_loop_count) |
| 4828 | << CollapseLoopCountExpr->getSourceRange(); |
| 4829 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4830 | OrderedLoopCount = Result.getLimitedValue(); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4831 | } |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4832 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4833 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4834 | // 'for simd', etc.). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4835 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4836 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4837 | IterSpaces.resize(std::max(OrderedLoopCount, NestedLoopCount)); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4838 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4839 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4840 | if (checkOpenMPIterationSpace( |
| 4841 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 4842 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| 4843 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces[Cnt], |
| 4844 | Captures)) |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4845 | return 0; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4846 | // 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] | 4847 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4848 | // All loops associated with the construct must be perfectly nested; that |
| 4849 | // is, there must be no intervening code nor any OpenMP directive between |
| 4850 | // any two loops. |
| 4851 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4852 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4853 | for (unsigned Cnt = NestedLoopCount; Cnt < OrderedLoopCount; ++Cnt) { |
| 4854 | if (checkOpenMPIterationSpace( |
| 4855 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 4856 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| 4857 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces[Cnt], |
| 4858 | Captures)) |
| 4859 | return 0; |
| 4860 | if (Cnt > 0 && IterSpaces[Cnt].CounterVar) { |
| 4861 | // Handle initialization of captured loop iterator variables. |
| 4862 | auto *DRE = cast<DeclRefExpr>(IterSpaces[Cnt].CounterVar); |
| 4863 | if (isa<OMPCapturedExprDecl>(DRE->getDecl())) { |
| 4864 | Captures[DRE] = DRE; |
| 4865 | } |
| 4866 | } |
| 4867 | // Move on to the next nested for loop, or to the loop body. |
| 4868 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4869 | // All loops associated with the construct must be perfectly nested; that |
| 4870 | // is, there must be no intervening code nor any OpenMP directive between |
| 4871 | // any two loops. |
| 4872 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
| 4873 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4874 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4875 | Built.clear(/* size */ NestedLoopCount); |
| 4876 | |
| 4877 | if (SemaRef.CurContext->isDependentContext()) |
| 4878 | return NestedLoopCount; |
| 4879 | |
| 4880 | // An example of what is generated for the following code: |
| 4881 | // |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4882 | // #pragma omp simd collapse(2) ordered(2) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4883 | // for (i = 0; i < NI; ++i) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4884 | // for (k = 0; k < NK; ++k) |
| 4885 | // for (j = J0; j < NJ; j+=2) { |
| 4886 | // <loop body> |
| 4887 | // } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4888 | // |
| 4889 | // We generate the code below. |
| 4890 | // Note: the loop body may be outlined in CodeGen. |
| 4891 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4892 | // iterations and operator+= to calculate counter value. |
| 4893 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4894 | // or i64 is currently supported). |
| 4895 | // |
| 4896 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4897 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4898 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4899 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4900 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4901 | // <loop body (using local i and j)> |
| 4902 | // } |
| 4903 | // i = NI; // assign final values of counters |
| 4904 | // j = NJ; |
| 4905 | // |
| 4906 | |
| 4907 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4908 | // the iteration counts of the collapsed for loops. |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4909 | // Precondition tests if there is at least one iteration (all conditions are |
| 4910 | // true). |
| 4911 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4912 | Expr *N0 = IterSpaces[0].NumIterations; |
| 4913 | ExprResult LastIteration32 = |
| 4914 | widenIterationCount(/*Bits=*/32, |
| 4915 | SemaRef |
| 4916 | .PerformImplicitConversion( |
| 4917 | N0->IgnoreImpCasts(), N0->getType(), |
| 4918 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4919 | .get(), |
| 4920 | SemaRef); |
| 4921 | ExprResult LastIteration64 = widenIterationCount( |
| 4922 | /*Bits=*/64, |
| 4923 | SemaRef |
| 4924 | .PerformImplicitConversion(N0->IgnoreImpCasts(), N0->getType(), |
| 4925 | Sema::AA_Converting, |
| 4926 | /*AllowExplicit=*/true) |
| 4927 | .get(), |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4928 | SemaRef); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4929 | |
| 4930 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4931 | return NestedLoopCount; |
| 4932 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4933 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4934 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4935 | |
| 4936 | Scope *CurScope = DSA.getCurScope(); |
| 4937 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4938 | if (PreCond.isUsable()) { |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4939 | PreCond = |
| 4940 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 4941 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4942 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4943 | Expr *N = IterSpaces[Cnt].NumIterations; |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4944 | SourceLocation Loc = N->getExprLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4945 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4946 | if (LastIteration32.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4947 | LastIteration32 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4948 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4949 | SemaRef |
| 4950 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4951 | Sema::AA_Converting, |
| 4952 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4953 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4954 | if (LastIteration64.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4955 | LastIteration64 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4956 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4957 | SemaRef |
| 4958 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4959 | Sema::AA_Converting, |
| 4960 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4961 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | // Choose either the 32-bit or 64-bit version. |
| 4965 | ExprResult LastIteration = LastIteration64; |
| 4966 | if (LastIteration32.isUsable() && |
| 4967 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4968 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4969 | fitsInto( |
| 4970 | /*Bits=*/32, |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4971 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4972 | LastIteration64.get(), SemaRef))) |
| 4973 | LastIteration = LastIteration32; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4974 | QualType VType = LastIteration.get()->getType(); |
| 4975 | QualType RealVType = VType; |
| 4976 | QualType StrideVType = VType; |
| 4977 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 4978 | VType = |
| 4979 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 4980 | StrideVType = |
| 4981 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 4982 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4983 | |
| 4984 | if (!LastIteration.isUsable()) |
| 4985 | return 0; |
| 4986 | |
| 4987 | // Save the number of iterations. |
| 4988 | ExprResult NumIterations = LastIteration; |
| 4989 | { |
| 4990 | LastIteration = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4991 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4992 | LastIteration.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4993 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4994 | if (!LastIteration.isUsable()) |
| 4995 | return 0; |
| 4996 | } |
| 4997 | |
| 4998 | // Calculate the last iteration number beforehand instead of doing this on |
| 4999 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 5000 | llvm::APSInt Result; |
| 5001 | bool IsConstant = |
| 5002 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5003 | ExprResult CalcLastIteration; |
| 5004 | if (!IsConstant) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5005 | ExprResult SaveRef = |
| 5006 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5007 | LastIteration = SaveRef; |
| 5008 | |
| 5009 | // Prepare SaveRef + 1. |
| 5010 | NumIterations = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5011 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5012 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5013 | if (!NumIterations.isUsable()) |
| 5014 | return 0; |
| 5015 | } |
| 5016 | |
| 5017 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 5018 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5019 | // Build variables passed into runtime, necessary for worksharing directives. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5020 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5021 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5022 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5023 | // Lower bound variable, initialized with zero. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5024 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 5025 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5026 | SemaRef.AddInitializerToDecl(LBDecl, |
| 5027 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5028 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5029 | |
| 5030 | // Upper bound variable, initialized with last iteration number. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5031 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 5032 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5033 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5034 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5035 | |
| 5036 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 5037 | // This will be used to implement clause 'lastprivate'. |
| 5038 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5039 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 5040 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5041 | SemaRef.AddInitializerToDecl(ILDecl, |
| 5042 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5043 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5044 | |
| 5045 | // Stride variable returned by runtime (we initialize it to 1 by default). |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5046 | VarDecl *STDecl = |
| 5047 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 5048 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5049 | SemaRef.AddInitializerToDecl(STDecl, |
| 5050 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 5051 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5052 | |
| 5053 | // Build expression: UB = min(UB, LastIteration) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5054 | // It is necessary for CodeGen of directives with static scheduling. |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5055 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 5056 | UB.get(), LastIteration.get()); |
| 5057 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| Alexey Bataev | 86ec3fe | 2018-07-25 14:40:26 +0000 | [diff] [blame] | 5058 | LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(), |
| 5059 | LastIteration.get(), UB.get()); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5060 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 5061 | CondOp.get()); |
| 5062 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5063 | |
| 5064 | // If we have a combined directive that combines 'distribute', 'for' or |
| 5065 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 5066 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 5067 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 5068 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5069 | // Lower bound variable, initialized with zero. |
| 5070 | VarDecl *CombLBDecl = |
| 5071 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 5072 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 5073 | SemaRef.AddInitializerToDecl( |
| 5074 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5075 | /*DirectInit*/ false); |
| 5076 | |
| 5077 | // Upper bound variable, initialized with last iteration number. |
| 5078 | VarDecl *CombUBDecl = |
| 5079 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 5080 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 5081 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 5082 | /*DirectInit*/ false); |
| 5083 | |
| 5084 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 5085 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 5086 | ExprResult CombCondOp = |
| 5087 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 5088 | LastIteration.get(), CombUB.get()); |
| 5089 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 5090 | CombCondOp.get()); |
| 5091 | CombEUB = SemaRef.ActOnFinishFullExpr(CombEUB.get()); |
| 5092 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5093 | const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5094 | // We expect to have at least 2 more parameters than the 'parallel' |
| 5095 | // directive does - the lower and upper bounds of the previous schedule. |
| 5096 | assert(CD->getNumParams() >= 4 && |
| 5097 | "Unexpected number of parameters in loop combined directive"); |
| 5098 | |
| 5099 | // Set the proper type for the bounds given what we learned from the |
| 5100 | // enclosed loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5101 | ImplicitParamDecl *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 5102 | ImplicitParamDecl *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5103 | |
| 5104 | // Previous lower and upper bounds are obtained from the region |
| 5105 | // parameters. |
| 5106 | PrevLB = |
| 5107 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 5108 | PrevUB = |
| 5109 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 5110 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | // Build the iteration variable and its initialization before loop. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5114 | ExprResult IV; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5115 | ExprResult Init, CombInit; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5116 | { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5117 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 5118 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5119 | Expr *RHS = |
| 5120 | (isOpenMPWorksharingDirective(DKind) || |
| 5121 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 5122 | ? LB.get() |
| 5123 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5124 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 5125 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5126 | |
| 5127 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5128 | Expr *CombRHS = |
| 5129 | (isOpenMPWorksharingDirective(DKind) || |
| 5130 | isOpenMPTaskLoopDirective(DKind) || |
| 5131 | isOpenMPDistributeDirective(DKind)) |
| 5132 | ? CombLB.get() |
| 5133 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 5134 | CombInit = |
| 5135 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| 5136 | CombInit = SemaRef.ActOnFinishFullExpr(CombInit.get()); |
| 5137 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5140 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5141 | SourceLocation CondLoc = AStmt->getBeginLoc(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5142 | ExprResult Cond = |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5143 | (isOpenMPWorksharingDirective(DKind) || |
| 5144 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5145 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 5146 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5147 | NumIterations.get()); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5148 | ExprResult CombCond; |
| 5149 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5150 | CombCond = |
| 5151 | SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), CombUB.get()); |
| 5152 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5153 | // Loop increment (IV = IV + 1) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5154 | SourceLocation IncLoc = AStmt->getBeginLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5155 | ExprResult Inc = |
| 5156 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 5157 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 5158 | if (!Inc.isUsable()) |
| 5159 | return 0; |
| 5160 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5161 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 5162 | if (!Inc.isUsable()) |
| 5163 | return 0; |
| 5164 | |
| 5165 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 5166 | // Used for directives with static scheduling. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5167 | // In combined construct, add combined version that use CombLB and CombUB |
| 5168 | // base variables for the update |
| 5169 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5170 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5171 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5172 | // LB + ST |
| 5173 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 5174 | if (!NextLB.isUsable()) |
| 5175 | return 0; |
| 5176 | // LB = LB + ST |
| 5177 | NextLB = |
| 5178 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 5179 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 5180 | if (!NextLB.isUsable()) |
| 5181 | return 0; |
| 5182 | // UB + ST |
| 5183 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 5184 | if (!NextUB.isUsable()) |
| 5185 | return 0; |
| 5186 | // UB = UB + ST |
| 5187 | NextUB = |
| 5188 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 5189 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 5190 | if (!NextUB.isUsable()) |
| 5191 | return 0; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5192 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5193 | CombNextLB = |
| 5194 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 5195 | if (!NextLB.isUsable()) |
| 5196 | return 0; |
| 5197 | // LB = LB + ST |
| 5198 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 5199 | CombNextLB.get()); |
| 5200 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get()); |
| 5201 | if (!CombNextLB.isUsable()) |
| 5202 | return 0; |
| 5203 | // UB + ST |
| 5204 | CombNextUB = |
| 5205 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 5206 | if (!CombNextUB.isUsable()) |
| 5207 | return 0; |
| 5208 | // UB = UB + ST |
| 5209 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 5210 | CombNextUB.get()); |
| 5211 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get()); |
| 5212 | if (!CombNextUB.isUsable()) |
| 5213 | return 0; |
| 5214 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5215 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5216 | |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5217 | // Create increment expression for distribute loop when combined in a same |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5218 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 5219 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 5220 | // in combination with 'distribute', like in 'distribute parallel for' |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5221 | SourceLocation DistIncLoc = AStmt->getBeginLoc(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5222 | ExprResult DistCond, DistInc, PrevEUB; |
| 5223 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5224 | DistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()); |
| 5225 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 5226 | |
| 5227 | DistInc = |
| 5228 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 5229 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 5230 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 5231 | DistInc.get()); |
| 5232 | DistInc = SemaRef.ActOnFinishFullExpr(DistInc.get()); |
| 5233 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 5234 | |
| 5235 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 5236 | // construct |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5237 | SourceLocation DistEUBLoc = AStmt->getBeginLoc(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5238 | ExprResult IsUBGreater = |
| 5239 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 5240 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 5241 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 5242 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 5243 | CondOp.get()); |
| 5244 | PrevEUB = SemaRef.ActOnFinishFullExpr(PrevEUB.get()); |
| 5245 | } |
| 5246 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5247 | // Build updates and final values of the loop counters. |
| 5248 | bool HasErrors = false; |
| 5249 | Built.Counters.resize(NestedLoopCount); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5250 | Built.Inits.resize(NestedLoopCount); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5251 | Built.Updates.resize(NestedLoopCount); |
| 5252 | Built.Finals.resize(NestedLoopCount); |
| 5253 | { |
| 5254 | ExprResult Div; |
| 5255 | // Go from inner nested loop to outer. |
| 5256 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5257 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 5258 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 5259 | // Build: Iter = (IV / Div) % IS.NumIters |
| 5260 | // where Div is product of previous iterations' IS.NumIters. |
| 5261 | ExprResult Iter; |
| 5262 | if (Div.isUsable()) { |
| 5263 | Iter = |
| 5264 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 5265 | } else { |
| 5266 | Iter = IV; |
| 5267 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 5268 | "unusable div expected on first iteration only"); |
| 5269 | } |
| 5270 | |
| 5271 | if (Cnt != 0 && Iter.isUsable()) |
| 5272 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 5273 | IS.NumIterations); |
| 5274 | if (!Iter.isUsable()) { |
| 5275 | HasErrors = true; |
| 5276 | break; |
| 5277 | } |
| 5278 | |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5279 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5280 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5281 | DeclRefExpr *CounterVar = buildDeclRefExpr( |
| 5282 | SemaRef, VD, IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 5283 | /*RefersToCapture=*/true); |
| 5284 | ExprResult Init = buildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5285 | IS.CounterInit, Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5286 | if (!Init.isUsable()) { |
| 5287 | HasErrors = true; |
| 5288 | break; |
| 5289 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5290 | ExprResult Update = buildCounterUpdate( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5291 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 5292 | IS.CounterStep, IS.Subtract, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5293 | if (!Update.isUsable()) { |
| 5294 | HasErrors = true; |
| 5295 | break; |
| 5296 | } |
| 5297 | |
| 5298 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5299 | ExprResult Final = buildCounterUpdate( |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5300 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5301 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5302 | if (!Final.isUsable()) { |
| 5303 | HasErrors = true; |
| 5304 | break; |
| 5305 | } |
| 5306 | |
| 5307 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 5308 | if (Cnt != 0) { |
| 5309 | if (Div.isUnset()) |
| 5310 | Div = IS.NumIterations; |
| 5311 | else |
| 5312 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 5313 | IS.NumIterations); |
| 5314 | |
| 5315 | // Add parentheses (for debugging purposes only). |
| 5316 | if (Div.isUsable()) |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5317 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5318 | if (!Div.isUsable()) { |
| 5319 | HasErrors = true; |
| 5320 | break; |
| 5321 | } |
| 5322 | } |
| 5323 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5324 | HasErrors = true; |
| 5325 | break; |
| 5326 | } |
| 5327 | // Save results |
| 5328 | Built.Counters[Cnt] = IS.CounterVar; |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5329 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5330 | Built.Inits[Cnt] = Init.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5331 | Built.Updates[Cnt] = Update.get(); |
| 5332 | Built.Finals[Cnt] = Final.get(); |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | if (HasErrors) |
| 5337 | return 0; |
| 5338 | |
| 5339 | // Save results |
| 5340 | Built.IterationVarRef = IV.get(); |
| 5341 | Built.LastIteration = LastIteration.get(); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5342 | Built.NumIterations = NumIterations.get(); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5343 | Built.CalcLastIteration = |
| 5344 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5345 | Built.PreCond = PreCond.get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5346 | Built.PreInits = buildPreInits(C, Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5347 | Built.Cond = Cond.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5348 | Built.Init = Init.get(); |
| 5349 | Built.Inc = Inc.get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5350 | Built.LB = LB.get(); |
| 5351 | Built.UB = UB.get(); |
| 5352 | Built.IL = IL.get(); |
| 5353 | Built.ST = ST.get(); |
| 5354 | Built.EUB = EUB.get(); |
| 5355 | Built.NLB = NextLB.get(); |
| 5356 | Built.NUB = NextUB.get(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5357 | Built.PrevLB = PrevLB.get(); |
| 5358 | Built.PrevUB = PrevUB.get(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5359 | Built.DistInc = DistInc.get(); |
| 5360 | Built.PrevEUB = PrevEUB.get(); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5361 | Built.DistCombinedFields.LB = CombLB.get(); |
| 5362 | Built.DistCombinedFields.UB = CombUB.get(); |
| 5363 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 5364 | Built.DistCombinedFields.Init = CombInit.get(); |
| 5365 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 5366 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 5367 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5368 | |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5369 | return NestedLoopCount; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5370 | } |
| 5371 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5372 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5373 | auto CollapseClauses = |
| 5374 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 5375 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 5376 | return (*CollapseClauses.begin())->getNumForLoops(); |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5377 | return nullptr; |
| 5378 | } |
| 5379 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5380 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5381 | auto OrderedClauses = |
| 5382 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 5383 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 5384 | return (*OrderedClauses.begin())->getNumForLoops(); |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5385 | return nullptr; |
| 5386 | } |
| 5387 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5388 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 5389 | const ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5390 | const OMPSafelenClause *Safelen = nullptr; |
| 5391 | const OMPSimdlenClause *Simdlen = nullptr; |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5392 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5393 | for (const OMPClause *Clause : Clauses) { |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5394 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5395 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5396 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5397 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5398 | if (Safelen && Simdlen) |
| 5399 | break; |
| 5400 | } |
| 5401 | |
| 5402 | if (Simdlen && Safelen) { |
| 5403 | llvm::APSInt SimdlenRes, SafelenRes; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5404 | const Expr *SimdlenLength = Simdlen->getSimdlen(); |
| 5405 | const Expr *SafelenLength = Safelen->getSafelen(); |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5406 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 5407 | SimdlenLength->isInstantiationDependent() || |
| 5408 | SimdlenLength->containsUnexpandedParameterPack()) |
| 5409 | return false; |
| 5410 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 5411 | SafelenLength->isInstantiationDependent() || |
| 5412 | SafelenLength->containsUnexpandedParameterPack()) |
| 5413 | return false; |
| 5414 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 5415 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 5416 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 5417 | // If both simdlen and safelen clauses are specified, the value of the |
| 5418 | // simdlen parameter must be less than or equal to the value of the safelen |
| 5419 | // parameter. |
| 5420 | if (SimdlenRes > SafelenRes) { |
| 5421 | S.Diag(SimdlenLength->getExprLoc(), |
| 5422 | diag::err_omp_wrong_simdlen_safelen_values) |
| 5423 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 5424 | return true; |
| 5425 | } |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5426 | } |
| 5427 | return false; |
| 5428 | } |
| 5429 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5430 | StmtResult |
| 5431 | Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 5432 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 5433 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5434 | if (!AStmt) |
| 5435 | return StmtError(); |
| 5436 | |
| 5437 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5438 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5439 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5440 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5441 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5442 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5443 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5444 | if (NestedLoopCount == 0) |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5445 | return StmtError(); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5446 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5447 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5448 | "omp simd loop exprs were not built"); |
| 5449 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5450 | if (!CurContext->isDependentContext()) { |
| 5451 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5452 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5453 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5454 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5455 | B.NumIterations, *this, CurScope, |
| 5456 | DSAStack)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5457 | return StmtError(); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5461 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5462 | return StmtError(); |
| 5463 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5464 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5465 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5466 | Clauses, AStmt, B); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5469 | StmtResult |
| 5470 | Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 5471 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 5472 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5473 | if (!AStmt) |
| 5474 | return StmtError(); |
| 5475 | |
| 5476 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5477 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5478 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5479 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5480 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5481 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5482 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5483 | if (NestedLoopCount == 0) |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5484 | return StmtError(); |
| 5485 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5486 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5487 | "omp for loop exprs were not built"); |
| 5488 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5489 | if (!CurContext->isDependentContext()) { |
| 5490 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5491 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5492 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5493 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5494 | B.NumIterations, *this, CurScope, |
| 5495 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5496 | return StmtError(); |
| 5497 | } |
| 5498 | } |
| 5499 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5500 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5501 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5502 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5503 | } |
| 5504 | |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5505 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5506 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5507 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5508 | if (!AStmt) |
| 5509 | return StmtError(); |
| 5510 | |
| 5511 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5512 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5513 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5514 | // define the nested loops number. |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5515 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5516 | checkOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5517 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5518 | VarsWithImplicitDSA, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5519 | if (NestedLoopCount == 0) |
| 5520 | return StmtError(); |
| 5521 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5522 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5523 | "omp for simd loop exprs were not built"); |
| 5524 | |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5525 | if (!CurContext->isDependentContext()) { |
| 5526 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5527 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5528 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5529 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5530 | B.NumIterations, *this, CurScope, |
| 5531 | DSAStack)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5532 | return StmtError(); |
| 5533 | } |
| 5534 | } |
| 5535 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5536 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5537 | return StmtError(); |
| 5538 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5539 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5540 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5541 | Clauses, AStmt, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5544 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5545 | Stmt *AStmt, |
| 5546 | SourceLocation StartLoc, |
| 5547 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5548 | if (!AStmt) |
| 5549 | return StmtError(); |
| 5550 | |
| 5551 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5552 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5553 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5554 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5555 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5556 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5557 | if (S.begin() == S.end()) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5558 | return StmtError(); |
| 5559 | // All associated statements must be '#pragma omp section' except for |
| 5560 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5561 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5562 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5563 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5564 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5565 | diag::err_omp_sections_substmt_not_section); |
| 5566 | return StmtError(); |
| 5567 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5568 | cast<OMPSectionDirective>(SectionStmt) |
| 5569 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5570 | } |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5571 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5572 | Diag(AStmt->getBeginLoc(), diag::err_omp_sections_not_compound_stmt); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5573 | return StmtError(); |
| 5574 | } |
| 5575 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5576 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5577 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5578 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5579 | DSAStack->isCancelRegion()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5582 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 5583 | SourceLocation StartLoc, |
| 5584 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5585 | if (!AStmt) |
| 5586 | return StmtError(); |
| 5587 | |
| 5588 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5589 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5590 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5591 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5592 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5593 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 5594 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5597 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 5598 | Stmt *AStmt, |
| 5599 | SourceLocation StartLoc, |
| 5600 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5601 | if (!AStmt) |
| 5602 | return StmtError(); |
| 5603 | |
| 5604 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5605 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5606 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5607 | |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5608 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 5609 | // The copyprivate clause must not be used with the nowait clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5610 | const OMPClause *Nowait = nullptr; |
| 5611 | const OMPClause *Copyprivate = nullptr; |
| 5612 | for (const OMPClause *Clause : Clauses) { |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5613 | if (Clause->getClauseKind() == OMPC_nowait) |
| 5614 | Nowait = Clause; |
| 5615 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 5616 | Copyprivate = Clause; |
| 5617 | if (Copyprivate && Nowait) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5618 | Diag(Copyprivate->getBeginLoc(), |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5619 | diag::err_omp_single_copyprivate_with_nowait); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5620 | Diag(Nowait->getBeginLoc(), diag::note_omp_nowait_clause_here); |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5621 | return StmtError(); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5625 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5626 | } |
| 5627 | |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5628 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 5629 | SourceLocation StartLoc, |
| 5630 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5631 | if (!AStmt) |
| 5632 | return StmtError(); |
| 5633 | |
| 5634 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5635 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5636 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5637 | |
| 5638 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5639 | } |
| 5640 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5641 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 5642 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 5643 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5644 | if (!AStmt) |
| 5645 | return StmtError(); |
| 5646 | |
| 5647 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5648 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5649 | bool ErrorFound = false; |
| 5650 | llvm::APSInt Hint; |
| 5651 | SourceLocation HintLoc; |
| 5652 | bool DependentHint = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5653 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5654 | if (C->getClauseKind() == OMPC_hint) { |
| 5655 | if (!DirName.getName()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5656 | Diag(C->getBeginLoc(), diag::err_omp_hint_clause_no_name); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5657 | ErrorFound = true; |
| 5658 | } |
| 5659 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 5660 | if (E->isTypeDependent() || E->isValueDependent() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5661 | E->isInstantiationDependent()) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5662 | DependentHint = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5663 | } else { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5664 | Hint = E->EvaluateKnownConstInt(Context); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5665 | HintLoc = C->getBeginLoc(); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5666 | } |
| 5667 | } |
| 5668 | } |
| 5669 | if (ErrorFound) |
| 5670 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5671 | const auto Pair = DSAStack->getCriticalWithHint(DirName); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5672 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 5673 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 5674 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5675 | if (HintLoc.isValid()) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5676 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 5677 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5678 | else |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5679 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5680 | if (const auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5681 | Diag(C->getBeginLoc(), diag::note_omp_critical_hint_here) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5682 | << 1 |
| 5683 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5684 | /*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5685 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5686 | Diag(Pair.first->getBeginLoc(), diag::note_omp_critical_no_hint) << 1; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5687 | } |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5691 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5692 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5693 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5694 | Clauses, AStmt); |
| 5695 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5696 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5697 | return Dir; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5700 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5701 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5702 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5703 | if (!AStmt) |
| 5704 | return StmtError(); |
| 5705 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5706 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5707 | // 1.2.2 OpenMP Language Terminology |
| 5708 | // Structured block - An executable statement with a single entry at the |
| 5709 | // top and a single exit at the bottom. |
| 5710 | // The point of exit cannot be a branch out of the structured block. |
| 5711 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5712 | CS->getCapturedDecl()->setNothrow(); |
| 5713 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5714 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5715 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5716 | // define the nested loops number. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5717 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5718 | checkOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5719 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5720 | VarsWithImplicitDSA, B); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5721 | if (NestedLoopCount == 0) |
| 5722 | return StmtError(); |
| 5723 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5724 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5725 | "omp parallel for loop exprs were not built"); |
| 5726 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5727 | if (!CurContext->isDependentContext()) { |
| 5728 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5729 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5730 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5731 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5732 | B.NumIterations, *this, CurScope, |
| 5733 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5734 | return StmtError(); |
| 5735 | } |
| 5736 | } |
| 5737 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5738 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5739 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5740 | NestedLoopCount, Clauses, AStmt, B, |
| 5741 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5744 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5745 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5746 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5747 | if (!AStmt) |
| 5748 | return StmtError(); |
| 5749 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5750 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5751 | // 1.2.2 OpenMP Language Terminology |
| 5752 | // Structured block - An executable statement with a single entry at the |
| 5753 | // top and a single exit at the bottom. |
| 5754 | // The point of exit cannot be a branch out of the structured block. |
| 5755 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5756 | CS->getCapturedDecl()->setNothrow(); |
| 5757 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5758 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5759 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5760 | // define the nested loops number. |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5761 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5762 | checkOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5763 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5764 | VarsWithImplicitDSA, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5765 | if (NestedLoopCount == 0) |
| 5766 | return StmtError(); |
| 5767 | |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5768 | if (!CurContext->isDependentContext()) { |
| 5769 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5770 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5771 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5772 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5773 | B.NumIterations, *this, CurScope, |
| 5774 | DSAStack)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5775 | return StmtError(); |
| 5776 | } |
| 5777 | } |
| 5778 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5779 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5780 | return StmtError(); |
| 5781 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5782 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5783 | return OMPParallelForSimdDirective::Create( |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5784 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5785 | } |
| 5786 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5787 | StmtResult |
| 5788 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5789 | Stmt *AStmt, SourceLocation StartLoc, |
| 5790 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5791 | if (!AStmt) |
| 5792 | return StmtError(); |
| 5793 | |
| 5794 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5795 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5796 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5797 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5798 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5799 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5800 | if (S.begin() == S.end()) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5801 | return StmtError(); |
| 5802 | // All associated statements must be '#pragma omp section' except for |
| 5803 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5804 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5805 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5806 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5807 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5808 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5809 | return StmtError(); |
| 5810 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5811 | cast<OMPSectionDirective>(SectionStmt) |
| 5812 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5813 | } |
| 5814 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5815 | Diag(AStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5816 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5817 | return StmtError(); |
| 5818 | } |
| 5819 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5820 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5821 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5822 | return OMPParallelSectionsDirective::Create( |
| 5823 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5824 | } |
| 5825 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5826 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5827 | Stmt *AStmt, SourceLocation StartLoc, |
| 5828 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5829 | if (!AStmt) |
| 5830 | return StmtError(); |
| 5831 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5832 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5833 | // 1.2.2 OpenMP Language Terminology |
| 5834 | // Structured block - An executable statement with a single entry at the |
| 5835 | // top and a single exit at the bottom. |
| 5836 | // The point of exit cannot be a branch out of the structured block. |
| 5837 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5838 | CS->getCapturedDecl()->setNothrow(); |
| 5839 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5840 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5841 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5842 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5843 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5844 | } |
| 5845 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5846 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5847 | SourceLocation EndLoc) { |
| 5848 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5849 | } |
| 5850 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5851 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5852 | SourceLocation EndLoc) { |
| 5853 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5854 | } |
| 5855 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5856 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5857 | SourceLocation EndLoc) { |
| 5858 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5859 | } |
| 5860 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 5861 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
| 5862 | Stmt *AStmt, |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5863 | SourceLocation StartLoc, |
| 5864 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5865 | if (!AStmt) |
| 5866 | return StmtError(); |
| 5867 | |
| 5868 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5869 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5870 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5871 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 5872 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 5873 | AStmt, |
| 5874 | DSAStack->getTaskgroupReductionRef()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5875 | } |
| 5876 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5877 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5878 | SourceLocation StartLoc, |
| 5879 | SourceLocation EndLoc) { |
| 5880 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5881 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5882 | } |
| 5883 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5884 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5885 | Stmt *AStmt, |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5886 | SourceLocation StartLoc, |
| 5887 | SourceLocation EndLoc) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5888 | const OMPClause *DependFound = nullptr; |
| 5889 | const OMPClause *DependSourceClause = nullptr; |
| 5890 | const OMPClause *DependSinkClause = nullptr; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5891 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5892 | const OMPThreadsClause *TC = nullptr; |
| 5893 | const OMPSIMDClause *SC = nullptr; |
| 5894 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5895 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5896 | DependFound = C; |
| 5897 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5898 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5899 | Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5900 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5901 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5902 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5903 | } else { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5904 | DependSourceClause = C; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5905 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5906 | if (DependSinkClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5907 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5908 | << 0; |
| 5909 | ErrorFound = true; |
| 5910 | } |
| 5911 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5912 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5913 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5914 | << 1; |
| 5915 | ErrorFound = true; |
| 5916 | } |
| 5917 | DependSinkClause = C; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5918 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5919 | } else if (C->getClauseKind() == OMPC_threads) { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5920 | TC = cast<OMPThreadsClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5921 | } else if (C->getClauseKind() == OMPC_simd) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5922 | SC = cast<OMPSIMDClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5923 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5924 | } |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5925 | if (!ErrorFound && !SC && |
| 5926 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5927 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5928 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5929 | // that can appear in the simd region. |
| 5930 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5931 | ErrorFound = true; |
| 5932 | } else if (DependFound && (TC || SC)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5933 | Diag(DependFound->getBeginLoc(), diag::err_omp_depend_clause_thread_simd) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5934 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5935 | ErrorFound = true; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5936 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5937 | Diag(DependFound->getBeginLoc(), |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5938 | diag::err_omp_ordered_directive_without_param); |
| 5939 | ErrorFound = true; |
| 5940 | } else if (TC || Clauses.empty()) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5941 | if (const Expr *Param = DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5942 | SourceLocation ErrLoc = TC ? TC->getBeginLoc() : StartLoc; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5943 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5944 | << (TC != nullptr); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5945 | Diag(Param->getBeginLoc(), diag::note_omp_ordered_param); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5946 | ErrorFound = true; |
| 5947 | } |
| 5948 | } |
| 5949 | if ((!AStmt && !DependFound) || ErrorFound) |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5950 | return StmtError(); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5951 | |
| 5952 | if (AStmt) { |
| 5953 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5954 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5955 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5956 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5957 | |
| 5958 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5959 | } |
| 5960 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5961 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5962 | /// Helper class for checking expression in 'omp atomic [update]' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5963 | /// construct. |
| 5964 | class OpenMPAtomicUpdateChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5965 | /// Error results for atomic update expressions. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5966 | enum ExprAnalysisErrorCode { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5967 | /// A statement is not an expression statement. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5968 | NotAnExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5969 | /// Expression is not builtin binary or unary operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5970 | NotABinaryOrUnaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5971 | /// Unary operation is not post-/pre- increment/decrement operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5972 | NotAnUnaryIncDecExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5973 | /// An expression is not of scalar type. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5974 | NotAScalarType, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5975 | /// A binary operation is not an assignment operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5976 | NotAnAssignmentOp, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5977 | /// RHS part of the binary operation is not a binary expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5978 | NotABinaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5979 | /// RHS part is not additive/multiplicative/shift/biwise binary |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5980 | /// expression. |
| 5981 | NotABinaryOperator, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5982 | /// RHS binary operation does not have reference to the updated LHS |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5983 | /// part. |
| 5984 | NotAnUpdateExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5985 | /// No errors is found. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5986 | NoError |
| 5987 | }; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5988 | /// Reference to Sema. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5989 | Sema &SemaRef; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5990 | /// A location for note diagnostics (when error is found). |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5991 | SourceLocation NoteLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5992 | /// 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5993 | Expr *X; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5994 | /// 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5995 | Expr *E; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5996 | /// Helper expression of the form |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5997 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5998 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5999 | Expr *UpdateExpr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6000 | /// 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] | 6001 | /// important for non-associative operations. |
| 6002 | bool IsXLHSInRHSPart; |
| 6003 | BinaryOperatorKind Op; |
| 6004 | SourceLocation OpLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6005 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6006 | /// if it is a prefix unary operation. |
| 6007 | bool IsPostfixUpdate; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6008 | |
| 6009 | public: |
| 6010 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6011 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6012 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6013 | /// Check specified statement that it is suitable for 'atomic update' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6014 | /// constructs and extract 'x', 'expr' and Operation from the original |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6015 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 6016 | /// without error notification. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6017 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 6018 | /// \param NoteId Diagnostic note for the main error message. |
| 6019 | /// \return true if statement is not an update expression, false otherwise. |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6020 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6021 | /// Return the 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6022 | Expr *getX() const { return X; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6023 | /// Return the 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6024 | Expr *getExpr() const { return E; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6025 | /// Return the update expression used in calculation of the updated |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6026 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6027 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6028 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6029 | /// 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] | 6030 | /// false otherwise. |
| 6031 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 6032 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6033 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6034 | /// if it is a prefix unary operation. |
| 6035 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 6036 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6037 | private: |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6038 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 6039 | unsigned NoteId = 0); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6040 | }; |
| 6041 | } // namespace |
| 6042 | |
| 6043 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 6044 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 6045 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6046 | SourceLocation ErrorLoc, NoteLoc; |
| 6047 | SourceRange ErrorRange, NoteRange; |
| 6048 | // Allowed constructs are: |
| 6049 | // x = x binop expr; |
| 6050 | // x = expr binop x; |
| 6051 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 6052 | X = AtomicBinOp->getLHS(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6053 | if (const auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6054 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 6055 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 6056 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 6057 | AtomicInnerBinOp->isBitwiseOp()) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6058 | Op = AtomicInnerBinOp->getOpcode(); |
| 6059 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6060 | Expr *LHS = AtomicInnerBinOp->getLHS(); |
| 6061 | Expr *RHS = AtomicInnerBinOp->getRHS(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6062 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 6063 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 6064 | /*Canonical=*/true); |
| 6065 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 6066 | /*Canonical=*/true); |
| 6067 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 6068 | /*Canonical=*/true); |
| 6069 | if (XId == LHSId) { |
| 6070 | E = RHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6071 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6072 | } else if (XId == RHSId) { |
| 6073 | E = LHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6074 | IsXLHSInRHSPart = false; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6075 | } else { |
| 6076 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6077 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6078 | NoteLoc = X->getExprLoc(); |
| 6079 | NoteRange = X->getSourceRange(); |
| 6080 | ErrorFound = NotAnUpdateExpression; |
| 6081 | } |
| 6082 | } else { |
| 6083 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6084 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6085 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 6086 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6087 | ErrorFound = NotABinaryOperator; |
| 6088 | } |
| 6089 | } else { |
| 6090 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 6091 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 6092 | ErrorFound = NotABinaryExpression; |
| 6093 | } |
| 6094 | } else { |
| 6095 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6096 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6097 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 6098 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6099 | ErrorFound = NotAnAssignmentOp; |
| 6100 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6101 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6102 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6103 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6104 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6105 | } |
| 6106 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6107 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6108 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 6112 | unsigned NoteId) { |
| 6113 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6114 | SourceLocation ErrorLoc, NoteLoc; |
| 6115 | SourceRange ErrorRange, NoteRange; |
| 6116 | // Allowed constructs are: |
| 6117 | // x++; |
| 6118 | // x--; |
| 6119 | // ++x; |
| 6120 | // --x; |
| 6121 | // x binop= expr; |
| 6122 | // x = x binop expr; |
| 6123 | // x = expr binop x; |
| 6124 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 6125 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 6126 | if (AtomicBody->getType()->isScalarType() || |
| 6127 | AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6128 | if (const auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6129 | AtomicBody->IgnoreParenImpCasts())) { |
| 6130 | // Check for Compound Assignment Operation |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6131 | Op = BinaryOperator::getOpForCompoundAssignment( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6132 | AtomicCompAssignOp->getOpcode()); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6133 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6134 | E = AtomicCompAssignOp->getRHS(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6135 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6136 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6137 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 6138 | AtomicBody->IgnoreParenImpCasts())) { |
| 6139 | // Check for Binary Operation |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6140 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6141 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6142 | } else if (const auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6143 | AtomicBody->IgnoreParenImpCasts())) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6144 | // Check for Unary Operation |
| 6145 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6146 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6147 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 6148 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6149 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6150 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 6151 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6152 | } else { |
| 6153 | ErrorFound = NotAnUnaryIncDecExpression; |
| 6154 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 6155 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 6156 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6157 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6158 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6159 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6160 | ErrorFound = NotABinaryOrUnaryExpression; |
| 6161 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 6162 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 6163 | } |
| 6164 | } else { |
| 6165 | ErrorFound = NotAScalarType; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6166 | NoteLoc = ErrorLoc = AtomicBody->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6167 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6168 | } |
| 6169 | } else { |
| 6170 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6171 | NoteLoc = ErrorLoc = S->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6172 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6173 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6174 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6175 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6176 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6177 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6178 | } |
| 6179 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6180 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6181 | if (ErrorFound == NoError && E && X) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6182 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 6183 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 6184 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 6185 | auto *OVEX = new (SemaRef.getASTContext()) |
| 6186 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 6187 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 6188 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6189 | ExprResult Update = |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6190 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 6191 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 6192 | if (Update.isInvalid()) |
| 6193 | return true; |
| 6194 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 6195 | Sema::AA_Casting); |
| 6196 | if (Update.isInvalid()) |
| 6197 | return true; |
| 6198 | UpdateExpr = Update.get(); |
| 6199 | } |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6200 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6203 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 6204 | Stmt *AStmt, |
| 6205 | SourceLocation StartLoc, |
| 6206 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6207 | if (!AStmt) |
| 6208 | return StmtError(); |
| 6209 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6210 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6211 | // 1.2.2 OpenMP Language Terminology |
| 6212 | // Structured block - An executable statement with a single entry at the |
| 6213 | // top and a single exit at the bottom. |
| 6214 | // The point of exit cannot be a branch out of the structured block. |
| 6215 | // longjmp() and throw() must not violate the entry/exit criteria. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6216 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 6217 | SourceLocation AtomicKindLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6218 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6219 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6220 | C->getClauseKind() == OMPC_update || |
| 6221 | C->getClauseKind() == OMPC_capture) { |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6222 | if (AtomicKind != OMPC_unknown) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6223 | Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6224 | << SourceRange(C->getBeginLoc(), C->getEndLoc()); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6225 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 6226 | << getOpenMPClauseName(AtomicKind); |
| 6227 | } else { |
| 6228 | AtomicKind = C->getClauseKind(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6229 | AtomicKindLoc = C->getBeginLoc(); |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6230 | } |
| 6231 | } |
| 6232 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6233 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6234 | Stmt *Body = CS->getCapturedStmt(); |
| Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 6235 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 6236 | Body = EWC->getSubExpr(); |
| 6237 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6238 | Expr *X = nullptr; |
| 6239 | Expr *V = nullptr; |
| 6240 | Expr *E = nullptr; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6241 | Expr *UE = nullptr; |
| 6242 | bool IsXLHSInRHSPart = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6243 | bool IsPostfixUpdate = false; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6244 | // OpenMP [2.12.6, atomic Construct] |
| 6245 | // In the next expressions: |
| 6246 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 6247 | // * During the execution of an atomic region, multiple syntactic |
| 6248 | // occurrences of x must designate the same storage location. |
| 6249 | // * Neither of v and expr (as applicable) may access the storage location |
| 6250 | // designated by x. |
| 6251 | // * Neither of x and expr (as applicable) may access the storage location |
| 6252 | // designated by v. |
| 6253 | // * expr is an expression with scalar type. |
| 6254 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 6255 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 6256 | // * The expression x binop expr must be numerically equivalent to x binop |
| 6257 | // (expr). This requirement is satisfied if the operators in expr have |
| 6258 | // precedence greater than binop, or by using parentheses around expr or |
| 6259 | // subexpressions of expr. |
| 6260 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 6261 | // binop x. This requirement is satisfied if the operators in expr have |
| 6262 | // precedence equal to or greater than binop, or by using parentheses around |
| 6263 | // expr or subexpressions of expr. |
| 6264 | // * For forms that allow multiple occurrences of x, the number of times |
| 6265 | // that x is evaluated is unspecified. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6266 | if (AtomicKind == OMPC_read) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6267 | enum { |
| 6268 | NotAnExpression, |
| 6269 | NotAnAssignmentOp, |
| 6270 | NotAScalarType, |
| 6271 | NotAnLValue, |
| 6272 | NoError |
| 6273 | } ErrorFound = NoError; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6274 | SourceLocation ErrorLoc, NoteLoc; |
| 6275 | SourceRange ErrorRange, NoteRange; |
| 6276 | // If clause is read: |
| 6277 | // v = x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6278 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6279 | const auto *AtomicBinOp = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6280 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6281 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6282 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6283 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6284 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6285 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 6286 | if (!X->isLValue() || !V->isLValue()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6287 | const Expr *NotLValueExpr = X->isLValue() ? V : X; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6288 | ErrorFound = NotAnLValue; |
| 6289 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6290 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6291 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 6292 | NoteRange = NotLValueExpr->getSourceRange(); |
| 6293 | } |
| 6294 | } else if (!X->isInstantiationDependent() || |
| 6295 | !V->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6296 | const Expr *NotScalarExpr = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6297 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6298 | ? V |
| 6299 | : X; |
| 6300 | ErrorFound = NotAScalarType; |
| 6301 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6302 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6303 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6304 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6305 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6306 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6307 | ErrorFound = NotAnAssignmentOp; |
| 6308 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6309 | ErrorRange = AtomicBody->getSourceRange(); |
| 6310 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6311 | : AtomicBody->getExprLoc(); |
| 6312 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6313 | : AtomicBody->getSourceRange(); |
| 6314 | } |
| 6315 | } else { |
| 6316 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6317 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6318 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6319 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6320 | if (ErrorFound != NoError) { |
| 6321 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 6322 | << ErrorRange; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6323 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6324 | << NoteRange; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6325 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6326 | } |
| 6327 | if (CurContext->isDependentContext()) |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6328 | V = X = nullptr; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6329 | } else if (AtomicKind == OMPC_write) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6330 | enum { |
| 6331 | NotAnExpression, |
| 6332 | NotAnAssignmentOp, |
| 6333 | NotAScalarType, |
| 6334 | NotAnLValue, |
| 6335 | NoError |
| 6336 | } ErrorFound = NoError; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6337 | SourceLocation ErrorLoc, NoteLoc; |
| 6338 | SourceRange ErrorRange, NoteRange; |
| 6339 | // If clause is write: |
| 6340 | // x = expr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6341 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6342 | const auto *AtomicBinOp = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6343 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6344 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 6345 | X = AtomicBinOp->getLHS(); |
| 6346 | E = AtomicBinOp->getRHS(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6347 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6348 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 6349 | if (!X->isLValue()) { |
| 6350 | ErrorFound = NotAnLValue; |
| 6351 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6352 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6353 | NoteLoc = X->getExprLoc(); |
| 6354 | NoteRange = X->getSourceRange(); |
| 6355 | } |
| 6356 | } else if (!X->isInstantiationDependent() || |
| 6357 | !E->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6358 | const Expr *NotScalarExpr = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6359 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6360 | ? E |
| 6361 | : X; |
| 6362 | ErrorFound = NotAScalarType; |
| 6363 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6364 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6365 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6366 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6367 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6368 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6369 | ErrorFound = NotAnAssignmentOp; |
| 6370 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6371 | ErrorRange = AtomicBody->getSourceRange(); |
| 6372 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6373 | : AtomicBody->getExprLoc(); |
| 6374 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6375 | : AtomicBody->getSourceRange(); |
| 6376 | } |
| 6377 | } else { |
| 6378 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6379 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6380 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6381 | } |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6382 | if (ErrorFound != NoError) { |
| 6383 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 6384 | << ErrorRange; |
| 6385 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6386 | << NoteRange; |
| 6387 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6388 | } |
| 6389 | if (CurContext->isDependentContext()) |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6390 | E = X = nullptr; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6391 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6392 | // If clause is update: |
| 6393 | // x++; |
| 6394 | // x--; |
| 6395 | // ++x; |
| 6396 | // --x; |
| 6397 | // x binop= expr; |
| 6398 | // x = x binop expr; |
| 6399 | // x = expr binop x; |
| 6400 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6401 | if (Checker.checkStatement( |
| 6402 | Body, (AtomicKind == OMPC_update) |
| 6403 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6404 | : diag::err_omp_atomic_not_expression_statement, |
| 6405 | diag::note_omp_atomic_update)) |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6406 | return StmtError(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6407 | if (!CurContext->isDependentContext()) { |
| 6408 | E = Checker.getExpr(); |
| 6409 | X = Checker.getX(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6410 | UE = Checker.getUpdateExpr(); |
| 6411 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6412 | } |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6413 | } else if (AtomicKind == OMPC_capture) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6414 | enum { |
| 6415 | NotAnAssignmentOp, |
| 6416 | NotACompoundStatement, |
| 6417 | NotTwoSubstatements, |
| 6418 | NotASpecificExpression, |
| 6419 | NoError |
| 6420 | } ErrorFound = NoError; |
| 6421 | SourceLocation ErrorLoc, NoteLoc; |
| 6422 | SourceRange ErrorRange, NoteRange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6423 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6424 | // If clause is a capture: |
| 6425 | // v = x++; |
| 6426 | // v = x--; |
| 6427 | // v = ++x; |
| 6428 | // v = --x; |
| 6429 | // v = x binop= expr; |
| 6430 | // v = x = x binop expr; |
| 6431 | // v = x = expr binop x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6432 | const auto *AtomicBinOp = |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6433 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6434 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6435 | V = AtomicBinOp->getLHS(); |
| 6436 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6437 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6438 | if (Checker.checkStatement( |
| 6439 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6440 | diag::note_omp_atomic_update)) |
| 6441 | return StmtError(); |
| 6442 | E = Checker.getExpr(); |
| 6443 | X = Checker.getX(); |
| 6444 | UE = Checker.getUpdateExpr(); |
| 6445 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6446 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6447 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6448 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6449 | ErrorRange = AtomicBody->getSourceRange(); |
| 6450 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6451 | : AtomicBody->getExprLoc(); |
| 6452 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6453 | : AtomicBody->getSourceRange(); |
| 6454 | ErrorFound = NotAnAssignmentOp; |
| 6455 | } |
| 6456 | if (ErrorFound != NoError) { |
| 6457 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6458 | << ErrorRange; |
| 6459 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6460 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6461 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6462 | if (CurContext->isDependentContext()) |
| 6463 | UE = V = E = X = nullptr; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6464 | } else { |
| 6465 | // If clause is a capture: |
| 6466 | // { v = x; x = expr; } |
| 6467 | // { v = x; x++; } |
| 6468 | // { v = x; x--; } |
| 6469 | // { v = x; ++x; } |
| 6470 | // { v = x; --x; } |
| 6471 | // { v = x; x binop= expr; } |
| 6472 | // { v = x; x = x binop expr; } |
| 6473 | // { v = x; x = expr binop x; } |
| 6474 | // { x++; v = x; } |
| 6475 | // { x--; v = x; } |
| 6476 | // { ++x; v = x; } |
| 6477 | // { --x; v = x; } |
| 6478 | // { x binop= expr; v = x; } |
| 6479 | // { x = x binop expr; v = x; } |
| 6480 | // { x = expr binop x; v = x; } |
| 6481 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6482 | // Check that this is { expr1; expr2; } |
| 6483 | if (CS->size() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6484 | Stmt *First = CS->body_front(); |
| 6485 | Stmt *Second = CS->body_back(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6486 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6487 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6488 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6489 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6490 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6491 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6492 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6493 | BinaryOperator *BinOp = nullptr; |
| 6494 | if (IsUpdateExprFound) { |
| 6495 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6496 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6497 | } |
| 6498 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6499 | // { v = x; x++; } |
| 6500 | // { v = x; x--; } |
| 6501 | // { v = x; ++x; } |
| 6502 | // { v = x; --x; } |
| 6503 | // { v = x; x binop= expr; } |
| 6504 | // { v = x; x = x binop expr; } |
| 6505 | // { v = x; x = expr binop x; } |
| 6506 | // Check that the first expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6507 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6508 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6509 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6510 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6511 | IsUpdateExprFound = XId == PossibleXId; |
| 6512 | if (IsUpdateExprFound) { |
| 6513 | V = BinOp->getLHS(); |
| 6514 | X = Checker.getX(); |
| 6515 | E = Checker.getExpr(); |
| 6516 | UE = Checker.getUpdateExpr(); |
| 6517 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6518 | IsPostfixUpdate = true; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6519 | } |
| 6520 | } |
| 6521 | if (!IsUpdateExprFound) { |
| 6522 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6523 | BinOp = nullptr; |
| 6524 | if (IsUpdateExprFound) { |
| 6525 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6526 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6527 | } |
| 6528 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6529 | // { x++; v = x; } |
| 6530 | // { x--; v = x; } |
| 6531 | // { ++x; v = x; } |
| 6532 | // { --x; v = x; } |
| 6533 | // { x binop= expr; v = x; } |
| 6534 | // { x = x binop expr; v = x; } |
| 6535 | // { x = expr binop x; v = x; } |
| 6536 | // Check that the second expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6537 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6538 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6539 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6540 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6541 | IsUpdateExprFound = XId == PossibleXId; |
| 6542 | if (IsUpdateExprFound) { |
| 6543 | V = BinOp->getLHS(); |
| 6544 | X = Checker.getX(); |
| 6545 | E = Checker.getExpr(); |
| 6546 | UE = Checker.getUpdateExpr(); |
| 6547 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6548 | IsPostfixUpdate = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6549 | } |
| 6550 | } |
| 6551 | } |
| 6552 | if (!IsUpdateExprFound) { |
| 6553 | // { v = x; x = expr; } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6554 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 6555 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 6556 | if (!FirstExpr || !SecondExpr || |
| 6557 | !(FirstExpr->isInstantiationDependent() || |
| 6558 | SecondExpr->isInstantiationDependent())) { |
| 6559 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 6560 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6561 | ErrorFound = NotAnAssignmentOp; |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6562 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6563 | : First->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6564 | NoteRange = ErrorRange = FirstBinOp |
| 6565 | ? FirstBinOp->getSourceRange() |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6566 | : SourceRange(ErrorLoc, ErrorLoc); |
| 6567 | } else { |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6568 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 6569 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 6570 | ErrorFound = NotAnAssignmentOp; |
| 6571 | NoteLoc = ErrorLoc = SecondBinOp |
| 6572 | ? SecondBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6573 | : Second->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6574 | NoteRange = ErrorRange = |
| 6575 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 6576 | : SourceRange(ErrorLoc, ErrorLoc); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6577 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6578 | Expr *PossibleXRHSInFirst = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6579 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6580 | Expr *PossibleXLHSInSecond = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6581 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6582 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 6583 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 6584 | /*Canonical=*/true); |
| 6585 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 6586 | /*Canonical=*/true); |
| 6587 | IsUpdateExprFound = X1Id == X2Id; |
| 6588 | if (IsUpdateExprFound) { |
| 6589 | V = FirstBinOp->getLHS(); |
| 6590 | X = SecondBinOp->getLHS(); |
| 6591 | E = SecondBinOp->getRHS(); |
| 6592 | UE = nullptr; |
| 6593 | IsXLHSInRHSPart = false; |
| 6594 | IsPostfixUpdate = true; |
| 6595 | } else { |
| 6596 | ErrorFound = NotASpecificExpression; |
| 6597 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 6598 | ErrorRange = FirstBinOp->getSourceRange(); |
| 6599 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 6600 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 6601 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6602 | } |
| 6603 | } |
| 6604 | } |
| 6605 | } |
| 6606 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6607 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6608 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6609 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6610 | ErrorFound = NotTwoSubstatements; |
| 6611 | } |
| 6612 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6613 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6614 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6615 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6616 | ErrorFound = NotACompoundStatement; |
| 6617 | } |
| 6618 | if (ErrorFound != NoError) { |
| 6619 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 6620 | << ErrorRange; |
| 6621 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6622 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6623 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6624 | if (CurContext->isDependentContext()) |
| 6625 | UE = V = E = X = nullptr; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6626 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6627 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6628 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6629 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6630 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6631 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6632 | X, V, E, UE, IsXLHSInRHSPart, |
| 6633 | IsPostfixUpdate); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6634 | } |
| 6635 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6636 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 6637 | Stmt *AStmt, |
| 6638 | SourceLocation StartLoc, |
| 6639 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6640 | if (!AStmt) |
| 6641 | return StmtError(); |
| 6642 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6643 | auto *CS = cast<CapturedStmt>(AStmt); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 6644 | // 1.2.2 OpenMP Language Terminology |
| 6645 | // Structured block - An executable statement with a single entry at the |
| 6646 | // top and a single exit at the bottom. |
| 6647 | // The point of exit cannot be a branch out of the structured block. |
| 6648 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6649 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 6650 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target); |
| 6651 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6652 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6653 | // 1.2.2 OpenMP Language Terminology |
| 6654 | // Structured block - An executable statement with a single entry at the |
| 6655 | // top and a single exit at the bottom. |
| 6656 | // The point of exit cannot be a branch out of the structured block. |
| 6657 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6658 | CS->getCapturedDecl()->setNothrow(); |
| 6659 | } |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6660 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6661 | // OpenMP [2.16, Nesting of Regions] |
| 6662 | // If specified, a teams construct must be contained within a target |
| 6663 | // construct. That target construct must contain no statements or directives |
| 6664 | // outside of the teams construct. |
| 6665 | if (DSAStack->hasInnerTeamsRegion()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6666 | const Stmt *S = CS->IgnoreContainers(/*IgnoreCaptured=*/true); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6667 | bool OMPTeamsFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6668 | if (const auto *CS = dyn_cast<CompoundStmt>(S)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6669 | auto I = CS->body_begin(); |
| 6670 | while (I != CS->body_end()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6671 | const auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6672 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 6673 | OMPTeamsFound = false; |
| 6674 | break; |
| 6675 | } |
| 6676 | ++I; |
| 6677 | } |
| 6678 | assert(I != CS->body_end() && "Not found statement"); |
| 6679 | S = *I; |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 6680 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6681 | const auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 6682 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6683 | } |
| 6684 | if (!OMPTeamsFound) { |
| 6685 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 6686 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 6687 | diag::note_omp_nested_teams_construct_here); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6688 | Diag(S->getBeginLoc(), diag::note_omp_nested_statement_here) |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6689 | << isa<OMPExecutableDirective>(S); |
| 6690 | return StmtError(); |
| 6691 | } |
| 6692 | } |
| 6693 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6694 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6695 | |
| 6696 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6697 | } |
| 6698 | |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6699 | StmtResult |
| 6700 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6701 | Stmt *AStmt, SourceLocation StartLoc, |
| 6702 | SourceLocation EndLoc) { |
| 6703 | if (!AStmt) |
| 6704 | return StmtError(); |
| 6705 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6706 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6707 | // 1.2.2 OpenMP Language Terminology |
| 6708 | // Structured block - An executable statement with a single entry at the |
| 6709 | // top and a single exit at the bottom. |
| 6710 | // The point of exit cannot be a branch out of the structured block. |
| 6711 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6712 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 6713 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel); |
| 6714 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6715 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6716 | // 1.2.2 OpenMP Language Terminology |
| 6717 | // Structured block - An executable statement with a single entry at the |
| 6718 | // top and a single exit at the bottom. |
| 6719 | // The point of exit cannot be a branch out of the structured block. |
| 6720 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6721 | CS->getCapturedDecl()->setNothrow(); |
| 6722 | } |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6723 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6724 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6725 | |
| 6726 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6727 | AStmt); |
| 6728 | } |
| 6729 | |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6730 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6731 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6732 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6733 | if (!AStmt) |
| 6734 | return StmtError(); |
| 6735 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6736 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6737 | // 1.2.2 OpenMP Language Terminology |
| 6738 | // Structured block - An executable statement with a single entry at the |
| 6739 | // top and a single exit at the bottom. |
| 6740 | // The point of exit cannot be a branch out of the structured block. |
| 6741 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6742 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 6743 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 6744 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6745 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6746 | // 1.2.2 OpenMP Language Terminology |
| 6747 | // Structured block - An executable statement with a single entry at the |
| 6748 | // top and a single exit at the bottom. |
| 6749 | // The point of exit cannot be a branch out of the structured block. |
| 6750 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6751 | CS->getCapturedDecl()->setNothrow(); |
| 6752 | } |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6753 | |
| 6754 | OMPLoopDirective::HelperExprs B; |
| 6755 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6756 | // define the nested loops number. |
| 6757 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6758 | checkOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 6759 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6760 | VarsWithImplicitDSA, B); |
| 6761 | if (NestedLoopCount == 0) |
| 6762 | return StmtError(); |
| 6763 | |
| 6764 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6765 | "omp target parallel for loop exprs were not built"); |
| 6766 | |
| 6767 | if (!CurContext->isDependentContext()) { |
| 6768 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6769 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6770 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6771 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6772 | B.NumIterations, *this, CurScope, |
| 6773 | DSAStack)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6774 | return StmtError(); |
| 6775 | } |
| 6776 | } |
| 6777 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6778 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6779 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6780 | NestedLoopCount, Clauses, AStmt, |
| 6781 | B, DSAStack->isCancelRegion()); |
| 6782 | } |
| 6783 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6784 | /// Check for existence of a map clause in the list of clauses. |
| 6785 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, |
| 6786 | const OpenMPClauseKind K) { |
| 6787 | return llvm::any_of( |
| 6788 | Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; }); |
| 6789 | } |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6790 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6791 | template <typename... Params> |
| 6792 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, const OpenMPClauseKind K, |
| 6793 | const Params... ClauseTypes) { |
| 6794 | return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6795 | } |
| 6796 | |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6797 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6798 | Stmt *AStmt, |
| 6799 | SourceLocation StartLoc, |
| 6800 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6801 | if (!AStmt) |
| 6802 | return StmtError(); |
| 6803 | |
| 6804 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6805 | |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6806 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6807 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6808 | if (!hasClauses(Clauses, OMPC_map, OMPC_use_device_ptr)) { |
| 6809 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6810 | << "'map' or 'use_device_ptr'" |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6811 | << getOpenMPDirectiveName(OMPD_target_data); |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6812 | return StmtError(); |
| 6813 | } |
| 6814 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6815 | setFunctionHasBranchProtectedScope(); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6816 | |
| 6817 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6818 | AStmt); |
| 6819 | } |
| 6820 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6821 | StmtResult |
| 6822 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6823 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6824 | SourceLocation EndLoc, Stmt *AStmt) { |
| 6825 | if (!AStmt) |
| 6826 | return StmtError(); |
| 6827 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6828 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6829 | // 1.2.2 OpenMP Language Terminology |
| 6830 | // Structured block - An executable statement with a single entry at the |
| 6831 | // top and a single exit at the bottom. |
| 6832 | // The point of exit cannot be a branch out of the structured block. |
| 6833 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6834 | CS->getCapturedDecl()->setNothrow(); |
| 6835 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_enter_data); |
| 6836 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6837 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6838 | // 1.2.2 OpenMP Language Terminology |
| 6839 | // Structured block - An executable statement with a single entry at the |
| 6840 | // top and a single exit at the bottom. |
| 6841 | // The point of exit cannot be a branch out of the structured block. |
| 6842 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6843 | CS->getCapturedDecl()->setNothrow(); |
| 6844 | } |
| 6845 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6846 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6847 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6848 | if (!hasClauses(Clauses, OMPC_map)) { |
| 6849 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6850 | << "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6851 | return StmtError(); |
| 6852 | } |
| 6853 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6854 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6855 | AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6856 | } |
| 6857 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6858 | StmtResult |
| 6859 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6860 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6861 | SourceLocation EndLoc, Stmt *AStmt) { |
| 6862 | if (!AStmt) |
| 6863 | return StmtError(); |
| 6864 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6865 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6866 | // 1.2.2 OpenMP Language Terminology |
| 6867 | // Structured block - An executable statement with a single entry at the |
| 6868 | // top and a single exit at the bottom. |
| 6869 | // The point of exit cannot be a branch out of the structured block. |
| 6870 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6871 | CS->getCapturedDecl()->setNothrow(); |
| 6872 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_exit_data); |
| 6873 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6874 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6875 | // 1.2.2 OpenMP Language Terminology |
| 6876 | // Structured block - An executable statement with a single entry at the |
| 6877 | // top and a single exit at the bottom. |
| 6878 | // The point of exit cannot be a branch out of the structured block. |
| 6879 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6880 | CS->getCapturedDecl()->setNothrow(); |
| 6881 | } |
| 6882 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6883 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6884 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6885 | if (!hasClauses(Clauses, OMPC_map)) { |
| 6886 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6887 | << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6888 | return StmtError(); |
| 6889 | } |
| 6890 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6891 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6892 | AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6893 | } |
| 6894 | |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6895 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 6896 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6897 | SourceLocation EndLoc, |
| 6898 | Stmt *AStmt) { |
| 6899 | if (!AStmt) |
| 6900 | return StmtError(); |
| 6901 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6902 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6903 | // 1.2.2 OpenMP Language Terminology |
| 6904 | // Structured block - An executable statement with a single entry at the |
| 6905 | // top and a single exit at the bottom. |
| 6906 | // The point of exit cannot be a branch out of the structured block. |
| 6907 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6908 | CS->getCapturedDecl()->setNothrow(); |
| 6909 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_update); |
| 6910 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 6911 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 6912 | // 1.2.2 OpenMP Language Terminology |
| 6913 | // Structured block - An executable statement with a single entry at the |
| 6914 | // top and a single exit at the bottom. |
| 6915 | // The point of exit cannot be a branch out of the structured block. |
| 6916 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6917 | CS->getCapturedDecl()->setNothrow(); |
| 6918 | } |
| 6919 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6920 | if (!hasClauses(Clauses, OMPC_to, OMPC_from)) { |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6921 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 6922 | return StmtError(); |
| 6923 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 6924 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6925 | AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6926 | } |
| 6927 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6928 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6929 | Stmt *AStmt, SourceLocation StartLoc, |
| 6930 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6931 | if (!AStmt) |
| 6932 | return StmtError(); |
| 6933 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6934 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6935 | // 1.2.2 OpenMP Language Terminology |
| 6936 | // Structured block - An executable statement with a single entry at the |
| 6937 | // top and a single exit at the bottom. |
| 6938 | // The point of exit cannot be a branch out of the structured block. |
| 6939 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6940 | CS->getCapturedDecl()->setNothrow(); |
| 6941 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6942 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6943 | |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 6944 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 6945 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6946 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6947 | } |
| 6948 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6949 | StmtResult |
| 6950 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6951 | SourceLocation EndLoc, |
| 6952 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6953 | if (DSAStack->isParentNowaitRegion()) { |
| 6954 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6955 | return StmtError(); |
| 6956 | } |
| 6957 | if (DSAStack->isParentOrderedRegion()) { |
| 6958 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6959 | return StmtError(); |
| 6960 | } |
| 6961 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6962 | CancelRegion); |
| 6963 | } |
| 6964 | |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6965 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6966 | SourceLocation StartLoc, |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6967 | SourceLocation EndLoc, |
| 6968 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6969 | if (DSAStack->isParentNowaitRegion()) { |
| 6970 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6971 | return StmtError(); |
| 6972 | } |
| 6973 | if (DSAStack->isParentOrderedRegion()) { |
| 6974 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6975 | return StmtError(); |
| 6976 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6977 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6978 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6979 | CancelRegion); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6980 | } |
| 6981 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6982 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6983 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6984 | const OMPClause *PrevClause = nullptr; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6985 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6986 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6987 | if (C->getClauseKind() == OMPC_grainsize || |
| 6988 | C->getClauseKind() == OMPC_num_tasks) { |
| 6989 | if (!PrevClause) |
| 6990 | PrevClause = C; |
| 6991 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6992 | S.Diag(C->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6993 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6994 | << getOpenMPClauseName(C->getClauseKind()) |
| 6995 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6996 | S.Diag(PrevClause->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6997 | diag::note_omp_previous_grainsize_num_tasks) |
| 6998 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6999 | ErrorFound = true; |
| 7000 | } |
| 7001 | } |
| 7002 | } |
| 7003 | return ErrorFound; |
| 7004 | } |
| 7005 | |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7006 | static bool checkReductionClauseWithNogroup(Sema &S, |
| 7007 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7008 | const OMPClause *ReductionClause = nullptr; |
| 7009 | const OMPClause *NogroupClause = nullptr; |
| 7010 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7011 | if (C->getClauseKind() == OMPC_reduction) { |
| 7012 | ReductionClause = C; |
| 7013 | if (NogroupClause) |
| 7014 | break; |
| 7015 | continue; |
| 7016 | } |
| 7017 | if (C->getClauseKind() == OMPC_nogroup) { |
| 7018 | NogroupClause = C; |
| 7019 | if (ReductionClause) |
| 7020 | break; |
| 7021 | continue; |
| 7022 | } |
| 7023 | } |
| 7024 | if (ReductionClause && NogroupClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7025 | S.Diag(ReductionClause->getBeginLoc(), diag::err_omp_reduction_with_nogroup) |
| 7026 | << SourceRange(NogroupClause->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7027 | NogroupClause->getEndLoc()); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7028 | return true; |
| 7029 | } |
| 7030 | return false; |
| 7031 | } |
| 7032 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7033 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 7034 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7035 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7036 | if (!AStmt) |
| 7037 | return StmtError(); |
| 7038 | |
| 7039 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7040 | OMPLoopDirective::HelperExprs B; |
| 7041 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7042 | // define the nested loops number. |
| 7043 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7044 | checkOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7045 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7046 | VarsWithImplicitDSA, B); |
| 7047 | if (NestedLoopCount == 0) |
| 7048 | return StmtError(); |
| 7049 | |
| 7050 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7051 | "omp for loop exprs were not built"); |
| 7052 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7053 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7054 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7055 | // not appear on the same taskloop directive. |
| 7056 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7057 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7058 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7059 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 7060 | // clause must not be specified. |
| 7061 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 7062 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7063 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7064 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7065 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 7066 | NestedLoopCount, Clauses, AStmt, B); |
| 7067 | } |
| 7068 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7069 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 7070 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7071 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7072 | if (!AStmt) |
| 7073 | return StmtError(); |
| 7074 | |
| 7075 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7076 | OMPLoopDirective::HelperExprs B; |
| 7077 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7078 | // define the nested loops number. |
| 7079 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7080 | checkOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7081 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 7082 | VarsWithImplicitDSA, B); |
| 7083 | if (NestedLoopCount == 0) |
| 7084 | return StmtError(); |
| 7085 | |
| 7086 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7087 | "omp for loop exprs were not built"); |
| 7088 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7089 | if (!CurContext->isDependentContext()) { |
| 7090 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7091 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7092 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7093 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7094 | B.NumIterations, *this, CurScope, |
| 7095 | DSAStack)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7096 | return StmtError(); |
| 7097 | } |
| 7098 | } |
| 7099 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7100 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7101 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7102 | // not appear on the same taskloop directive. |
| 7103 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7104 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7105 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7106 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 7107 | // clause must not be specified. |
| 7108 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 7109 | return StmtError(); |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7110 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7111 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7112 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7113 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7114 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7115 | NestedLoopCount, Clauses, AStmt, B); |
| 7116 | } |
| 7117 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7118 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 7119 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7120 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7121 | if (!AStmt) |
| 7122 | return StmtError(); |
| 7123 | |
| 7124 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7125 | OMPLoopDirective::HelperExprs B; |
| 7126 | // In presence of clause 'collapse' with number of loops, it will |
| 7127 | // define the nested loops number. |
| 7128 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7129 | checkOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7130 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7131 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7132 | if (NestedLoopCount == 0) |
| 7133 | return StmtError(); |
| 7134 | |
| 7135 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7136 | "omp for loop exprs were not built"); |
| 7137 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7138 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7139 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 7140 | NestedLoopCount, Clauses, AStmt, B); |
| 7141 | } |
| 7142 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7143 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 7144 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7145 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7146 | if (!AStmt) |
| 7147 | return StmtError(); |
| 7148 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7149 | auto *CS = cast<CapturedStmt>(AStmt); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7150 | // 1.2.2 OpenMP Language Terminology |
| 7151 | // Structured block - An executable statement with a single entry at the |
| 7152 | // top and a single exit at the bottom. |
| 7153 | // The point of exit cannot be a branch out of the structured block. |
| 7154 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7155 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 7156 | for (int ThisCaptureLevel = |
| 7157 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for); |
| 7158 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7159 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7160 | // 1.2.2 OpenMP Language Terminology |
| 7161 | // Structured block - An executable statement with a single entry at the |
| 7162 | // top and a single exit at the bottom. |
| 7163 | // The point of exit cannot be a branch out of the structured block. |
| 7164 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7165 | CS->getCapturedDecl()->setNothrow(); |
| 7166 | } |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7167 | |
| 7168 | OMPLoopDirective::HelperExprs B; |
| 7169 | // In presence of clause 'collapse' with number of loops, it will |
| 7170 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7171 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7172 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 7173 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7174 | VarsWithImplicitDSA, B); |
| 7175 | if (NestedLoopCount == 0) |
| 7176 | return StmtError(); |
| 7177 | |
| 7178 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7179 | "omp for loop exprs were not built"); |
| 7180 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7181 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7182 | return OMPDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 7183 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 7184 | DSAStack->isCancelRegion()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7185 | } |
| 7186 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7187 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 7188 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7189 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7190 | if (!AStmt) |
| 7191 | return StmtError(); |
| 7192 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7193 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7194 | // 1.2.2 OpenMP Language Terminology |
| 7195 | // Structured block - An executable statement with a single entry at the |
| 7196 | // top and a single exit at the bottom. |
| 7197 | // The point of exit cannot be a branch out of the structured block. |
| 7198 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7199 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 7200 | for (int ThisCaptureLevel = |
| 7201 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for_simd); |
| 7202 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7203 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7204 | // 1.2.2 OpenMP Language Terminology |
| 7205 | // Structured block - An executable statement with a single entry at the |
| 7206 | // top and a single exit at the bottom. |
| 7207 | // The point of exit cannot be a branch out of the structured block. |
| 7208 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7209 | CS->getCapturedDecl()->setNothrow(); |
| 7210 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7211 | |
| 7212 | OMPLoopDirective::HelperExprs B; |
| 7213 | // In presence of clause 'collapse' with number of loops, it will |
| 7214 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7215 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7216 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 7217 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7218 | VarsWithImplicitDSA, B); |
| 7219 | if (NestedLoopCount == 0) |
| 7220 | return StmtError(); |
| 7221 | |
| 7222 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7223 | "omp for loop exprs were not built"); |
| 7224 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7225 | if (!CurContext->isDependentContext()) { |
| 7226 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7227 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7228 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7229 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7230 | B.NumIterations, *this, CurScope, |
| 7231 | DSAStack)) |
| 7232 | return StmtError(); |
| 7233 | } |
| 7234 | } |
| 7235 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7236 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7237 | return StmtError(); |
| 7238 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7239 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7240 | return OMPDistributeParallelForSimdDirective::Create( |
| 7241 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7242 | } |
| 7243 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7244 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 7245 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7246 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7247 | if (!AStmt) |
| 7248 | return StmtError(); |
| 7249 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7250 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7251 | // 1.2.2 OpenMP Language Terminology |
| 7252 | // Structured block - An executable statement with a single entry at the |
| 7253 | // top and a single exit at the bottom. |
| 7254 | // The point of exit cannot be a branch out of the structured block. |
| 7255 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7256 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 7257 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_distribute_simd); |
| 7258 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7259 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7260 | // 1.2.2 OpenMP Language Terminology |
| 7261 | // Structured block - An executable statement with a single entry at the |
| 7262 | // top and a single exit at the bottom. |
| 7263 | // The point of exit cannot be a branch out of the structured block. |
| 7264 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7265 | CS->getCapturedDecl()->setNothrow(); |
| 7266 | } |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7267 | |
| 7268 | OMPLoopDirective::HelperExprs B; |
| 7269 | // In presence of clause 'collapse' with number of loops, it will |
| 7270 | // define the nested loops number. |
| 7271 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7272 | checkOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 7273 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 7274 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7275 | if (NestedLoopCount == 0) |
| 7276 | return StmtError(); |
| 7277 | |
| 7278 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7279 | "omp for loop exprs were not built"); |
| 7280 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7281 | if (!CurContext->isDependentContext()) { |
| 7282 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7283 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7284 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7285 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7286 | B.NumIterations, *this, CurScope, |
| 7287 | DSAStack)) |
| 7288 | return StmtError(); |
| 7289 | } |
| 7290 | } |
| 7291 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7292 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7293 | return StmtError(); |
| 7294 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7295 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7296 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7297 | NestedLoopCount, Clauses, AStmt, B); |
| 7298 | } |
| 7299 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7300 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 7301 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7302 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7303 | if (!AStmt) |
| 7304 | return StmtError(); |
| 7305 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7306 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7307 | // 1.2.2 OpenMP Language Terminology |
| 7308 | // Structured block - An executable statement with a single entry at the |
| 7309 | // top and a single exit at the bottom. |
| 7310 | // The point of exit cannot be a branch out of the structured block. |
| 7311 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7312 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 7313 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 7314 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7315 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7316 | // 1.2.2 OpenMP Language Terminology |
| 7317 | // Structured block - An executable statement with a single entry at the |
| 7318 | // top and a single exit at the bottom. |
| 7319 | // The point of exit cannot be a branch out of the structured block. |
| 7320 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7321 | CS->getCapturedDecl()->setNothrow(); |
| 7322 | } |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7323 | |
| 7324 | OMPLoopDirective::HelperExprs B; |
| 7325 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7326 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7327 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7328 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 7329 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7330 | VarsWithImplicitDSA, B); |
| 7331 | if (NestedLoopCount == 0) |
| 7332 | return StmtError(); |
| 7333 | |
| 7334 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7335 | "omp target parallel for simd loop exprs were not built"); |
| 7336 | |
| 7337 | if (!CurContext->isDependentContext()) { |
| 7338 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7339 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7340 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7341 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7342 | B.NumIterations, *this, CurScope, |
| 7343 | DSAStack)) |
| 7344 | return StmtError(); |
| 7345 | } |
| 7346 | } |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7347 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7348 | return StmtError(); |
| 7349 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7350 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7351 | return OMPTargetParallelForSimdDirective::Create( |
| 7352 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7353 | } |
| 7354 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7355 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 7356 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7357 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7358 | if (!AStmt) |
| 7359 | return StmtError(); |
| 7360 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7361 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7362 | // 1.2.2 OpenMP Language Terminology |
| 7363 | // Structured block - An executable statement with a single entry at the |
| 7364 | // top and a single exit at the bottom. |
| 7365 | // The point of exit cannot be a branch out of the structured block. |
| 7366 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7367 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 7368 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_simd); |
| 7369 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7370 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7371 | // 1.2.2 OpenMP Language Terminology |
| 7372 | // Structured block - An executable statement with a single entry at the |
| 7373 | // top and a single exit at the bottom. |
| 7374 | // The point of exit cannot be a branch out of the structured block. |
| 7375 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7376 | CS->getCapturedDecl()->setNothrow(); |
| 7377 | } |
| 7378 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7379 | OMPLoopDirective::HelperExprs B; |
| 7380 | // In presence of clause 'collapse' with number of loops, it will define the |
| 7381 | // nested loops number. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7382 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7383 | checkOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 7384 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7385 | VarsWithImplicitDSA, B); |
| 7386 | if (NestedLoopCount == 0) |
| 7387 | return StmtError(); |
| 7388 | |
| 7389 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7390 | "omp target simd loop exprs were not built"); |
| 7391 | |
| 7392 | if (!CurContext->isDependentContext()) { |
| 7393 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7394 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7395 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7396 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7397 | B.NumIterations, *this, CurScope, |
| 7398 | DSAStack)) |
| 7399 | return StmtError(); |
| 7400 | } |
| 7401 | } |
| 7402 | |
| 7403 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7404 | return StmtError(); |
| 7405 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7406 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7407 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7408 | NestedLoopCount, Clauses, AStmt, B); |
| 7409 | } |
| 7410 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7411 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 7412 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7413 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7414 | if (!AStmt) |
| 7415 | return StmtError(); |
| 7416 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7417 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7418 | // 1.2.2 OpenMP Language Terminology |
| 7419 | // Structured block - An executable statement with a single entry at the |
| 7420 | // top and a single exit at the bottom. |
| 7421 | // The point of exit cannot be a branch out of the structured block. |
| 7422 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7423 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 7424 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_teams_distribute); |
| 7425 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7426 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7427 | // 1.2.2 OpenMP Language Terminology |
| 7428 | // Structured block - An executable statement with a single entry at the |
| 7429 | // top and a single exit at the bottom. |
| 7430 | // The point of exit cannot be a branch out of the structured block. |
| 7431 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7432 | CS->getCapturedDecl()->setNothrow(); |
| 7433 | } |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7434 | |
| 7435 | OMPLoopDirective::HelperExprs B; |
| 7436 | // In presence of clause 'collapse' with number of loops, it will |
| 7437 | // define the nested loops number. |
| 7438 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7439 | checkOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 7440 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 7441 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7442 | if (NestedLoopCount == 0) |
| 7443 | return StmtError(); |
| 7444 | |
| 7445 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7446 | "omp teams distribute loop exprs were not built"); |
| 7447 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7448 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7449 | |
| 7450 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7451 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7452 | return OMPTeamsDistributeDirective::Create( |
| 7453 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7456 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 7457 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7458 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7459 | if (!AStmt) |
| 7460 | return StmtError(); |
| 7461 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7462 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7463 | // 1.2.2 OpenMP Language Terminology |
| 7464 | // Structured block - An executable statement with a single entry at the |
| 7465 | // top and a single exit at the bottom. |
| 7466 | // The point of exit cannot be a branch out of the structured block. |
| 7467 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7468 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 7469 | for (int ThisCaptureLevel = |
| 7470 | getOpenMPCaptureLevels(OMPD_teams_distribute_simd); |
| 7471 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7472 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7473 | // 1.2.2 OpenMP Language Terminology |
| 7474 | // Structured block - An executable statement with a single entry at the |
| 7475 | // top and a single exit at the bottom. |
| 7476 | // The point of exit cannot be a branch out of the structured block. |
| 7477 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7478 | CS->getCapturedDecl()->setNothrow(); |
| 7479 | } |
| 7480 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7481 | |
| 7482 | OMPLoopDirective::HelperExprs B; |
| 7483 | // In presence of clause 'collapse' with number of loops, it will |
| 7484 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7485 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 7486 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 7487 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 7488 | VarsWithImplicitDSA, B); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7489 | |
| 7490 | if (NestedLoopCount == 0) |
| 7491 | return StmtError(); |
| 7492 | |
| 7493 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7494 | "omp teams distribute simd loop exprs were not built"); |
| 7495 | |
| 7496 | if (!CurContext->isDependentContext()) { |
| 7497 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7498 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7499 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7500 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7501 | B.NumIterations, *this, CurScope, |
| 7502 | DSAStack)) |
| 7503 | return StmtError(); |
| 7504 | } |
| 7505 | } |
| 7506 | |
| 7507 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7508 | return StmtError(); |
| 7509 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7510 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7511 | |
| 7512 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7513 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7514 | return OMPTeamsDistributeSimdDirective::Create( |
| 7515 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7516 | } |
| 7517 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7518 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 7519 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7520 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7521 | if (!AStmt) |
| 7522 | return StmtError(); |
| 7523 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7524 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7525 | // 1.2.2 OpenMP Language Terminology |
| 7526 | // Structured block - An executable statement with a single entry at the |
| 7527 | // top and a single exit at the bottom. |
| 7528 | // The point of exit cannot be a branch out of the structured block. |
| 7529 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7530 | CS->getCapturedDecl()->setNothrow(); |
| 7531 | |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 7532 | for (int ThisCaptureLevel = |
| 7533 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for_simd); |
| 7534 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7535 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7536 | // 1.2.2 OpenMP Language Terminology |
| 7537 | // Structured block - An executable statement with a single entry at the |
| 7538 | // top and a single exit at the bottom. |
| 7539 | // The point of exit cannot be a branch out of the structured block. |
| 7540 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7541 | CS->getCapturedDecl()->setNothrow(); |
| 7542 | } |
| 7543 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7544 | OMPLoopDirective::HelperExprs B; |
| 7545 | // In presence of clause 'collapse' with number of loops, it will |
| 7546 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7547 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7548 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 7549 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7550 | VarsWithImplicitDSA, B); |
| 7551 | |
| 7552 | if (NestedLoopCount == 0) |
| 7553 | return StmtError(); |
| 7554 | |
| 7555 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7556 | "omp for loop exprs were not built"); |
| 7557 | |
| 7558 | if (!CurContext->isDependentContext()) { |
| 7559 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7560 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7561 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7562 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7563 | B.NumIterations, *this, CurScope, |
| 7564 | DSAStack)) |
| 7565 | return StmtError(); |
| 7566 | } |
| 7567 | } |
| 7568 | |
| 7569 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7570 | return StmtError(); |
| 7571 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7572 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7573 | |
| 7574 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7575 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7576 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 7577 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7578 | } |
| 7579 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7580 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 7581 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7582 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7583 | if (!AStmt) |
| 7584 | return StmtError(); |
| 7585 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7586 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7587 | // 1.2.2 OpenMP Language Terminology |
| 7588 | // Structured block - An executable statement with a single entry at the |
| 7589 | // top and a single exit at the bottom. |
| 7590 | // The point of exit cannot be a branch out of the structured block. |
| 7591 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7592 | CS->getCapturedDecl()->setNothrow(); |
| 7593 | |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 7594 | for (int ThisCaptureLevel = |
| 7595 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for); |
| 7596 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7597 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7598 | // 1.2.2 OpenMP Language Terminology |
| 7599 | // Structured block - An executable statement with a single entry at the |
| 7600 | // top and a single exit at the bottom. |
| 7601 | // The point of exit cannot be a branch out of the structured block. |
| 7602 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7603 | CS->getCapturedDecl()->setNothrow(); |
| 7604 | } |
| 7605 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7606 | OMPLoopDirective::HelperExprs B; |
| 7607 | // In presence of clause 'collapse' with number of loops, it will |
| 7608 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7609 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7610 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 7611 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7612 | VarsWithImplicitDSA, B); |
| 7613 | |
| 7614 | if (NestedLoopCount == 0) |
| 7615 | return StmtError(); |
| 7616 | |
| 7617 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7618 | "omp for loop exprs were not built"); |
| 7619 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7620 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7621 | |
| 7622 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7623 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7624 | return OMPTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 7625 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 7626 | DSAStack->isCancelRegion()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 7627 | } |
| 7628 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7629 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 7630 | Stmt *AStmt, |
| 7631 | SourceLocation StartLoc, |
| 7632 | SourceLocation EndLoc) { |
| 7633 | if (!AStmt) |
| 7634 | return StmtError(); |
| 7635 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7636 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7637 | // 1.2.2 OpenMP Language Terminology |
| 7638 | // Structured block - An executable statement with a single entry at the |
| 7639 | // top and a single exit at the bottom. |
| 7640 | // The point of exit cannot be a branch out of the structured block. |
| 7641 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7642 | CS->getCapturedDecl()->setNothrow(); |
| 7643 | |
| Alexey Bataev | f9fc42e | 2017-11-22 14:25:55 +0000 | [diff] [blame] | 7644 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_teams); |
| 7645 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7646 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7647 | // 1.2.2 OpenMP Language Terminology |
| 7648 | // Structured block - An executable statement with a single entry at the |
| 7649 | // top and a single exit at the bottom. |
| 7650 | // The point of exit cannot be a branch out of the structured block. |
| 7651 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7652 | CS->getCapturedDecl()->setNothrow(); |
| 7653 | } |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7654 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7655 | |
| 7656 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7657 | AStmt); |
| 7658 | } |
| 7659 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7660 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 7661 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7662 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7663 | if (!AStmt) |
| 7664 | return StmtError(); |
| 7665 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7666 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7667 | // 1.2.2 OpenMP Language Terminology |
| 7668 | // Structured block - An executable statement with a single entry at the |
| 7669 | // top and a single exit at the bottom. |
| 7670 | // The point of exit cannot be a branch out of the structured block. |
| 7671 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7672 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 7673 | for (int ThisCaptureLevel = |
| 7674 | getOpenMPCaptureLevels(OMPD_target_teams_distribute); |
| 7675 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7676 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7677 | // 1.2.2 OpenMP Language Terminology |
| 7678 | // Structured block - An executable statement with a single entry at the |
| 7679 | // top and a single exit at the bottom. |
| 7680 | // The point of exit cannot be a branch out of the structured block. |
| 7681 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7682 | CS->getCapturedDecl()->setNothrow(); |
| 7683 | } |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7684 | |
| 7685 | OMPLoopDirective::HelperExprs B; |
| 7686 | // In presence of clause 'collapse' with number of loops, it will |
| 7687 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7688 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 7689 | OMPD_target_teams_distribute, getCollapseNumberExpr(Clauses), |
| 7690 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7691 | VarsWithImplicitDSA, B); |
| 7692 | if (NestedLoopCount == 0) |
| 7693 | return StmtError(); |
| 7694 | |
| 7695 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7696 | "omp target teams distribute loop exprs were not built"); |
| 7697 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7698 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 7699 | return OMPTargetTeamsDistributeDirective::Create( |
| 7700 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7701 | } |
| 7702 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7703 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 7704 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7705 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7706 | if (!AStmt) |
| 7707 | return StmtError(); |
| 7708 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7709 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7710 | // 1.2.2 OpenMP Language Terminology |
| 7711 | // Structured block - An executable statement with a single entry at the |
| 7712 | // top and a single exit at the bottom. |
| 7713 | // The point of exit cannot be a branch out of the structured block. |
| 7714 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7715 | CS->getCapturedDecl()->setNothrow(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 7716 | for (int ThisCaptureLevel = |
| 7717 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_parallel_for); |
| 7718 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7719 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7720 | // 1.2.2 OpenMP Language Terminology |
| 7721 | // Structured block - An executable statement with a single entry at the |
| 7722 | // top and a single exit at the bottom. |
| 7723 | // The point of exit cannot be a branch out of the structured block. |
| 7724 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7725 | CS->getCapturedDecl()->setNothrow(); |
| 7726 | } |
| 7727 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7728 | OMPLoopDirective::HelperExprs B; |
| 7729 | // In presence of clause 'collapse' with number of loops, it will |
| 7730 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7731 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 7732 | OMPD_target_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 7733 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7734 | VarsWithImplicitDSA, B); |
| 7735 | if (NestedLoopCount == 0) |
| 7736 | return StmtError(); |
| 7737 | |
| 7738 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7739 | "omp target teams distribute parallel for loop exprs were not built"); |
| 7740 | |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 7741 | if (!CurContext->isDependentContext()) { |
| 7742 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7743 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 7744 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7745 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7746 | B.NumIterations, *this, CurScope, |
| 7747 | DSAStack)) |
| 7748 | return StmtError(); |
| 7749 | } |
| 7750 | } |
| 7751 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7752 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7753 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 7754 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 7755 | DSAStack->isCancelRegion()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7756 | } |
| 7757 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7758 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 7759 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7760 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7761 | if (!AStmt) |
| 7762 | return StmtError(); |
| 7763 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7764 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7765 | // 1.2.2 OpenMP Language Terminology |
| 7766 | // Structured block - An executable statement with a single entry at the |
| 7767 | // top and a single exit at the bottom. |
| 7768 | // The point of exit cannot be a branch out of the structured block. |
| 7769 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7770 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 7771 | for (int ThisCaptureLevel = getOpenMPCaptureLevels( |
| 7772 | OMPD_target_teams_distribute_parallel_for_simd); |
| 7773 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7774 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7775 | // 1.2.2 OpenMP Language Terminology |
| 7776 | // Structured block - An executable statement with a single entry at the |
| 7777 | // top and a single exit at the bottom. |
| 7778 | // The point of exit cannot be a branch out of the structured block. |
| 7779 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7780 | CS->getCapturedDecl()->setNothrow(); |
| 7781 | } |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7782 | |
| 7783 | OMPLoopDirective::HelperExprs B; |
| 7784 | // In presence of clause 'collapse' with number of loops, it will |
| 7785 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7786 | unsigned NestedLoopCount = |
| 7787 | checkOpenMPLoop(OMPD_target_teams_distribute_parallel_for_simd, |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 7788 | getCollapseNumberExpr(Clauses), |
| 7789 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 7790 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7791 | if (NestedLoopCount == 0) |
| 7792 | return StmtError(); |
| 7793 | |
| 7794 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7795 | "omp target teams distribute parallel for simd loop exprs were not " |
| 7796 | "built"); |
| 7797 | |
| 7798 | if (!CurContext->isDependentContext()) { |
| 7799 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7800 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7801 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7802 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7803 | B.NumIterations, *this, CurScope, |
| 7804 | DSAStack)) |
| 7805 | return StmtError(); |
| 7806 | } |
| 7807 | } |
| 7808 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7809 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7810 | return StmtError(); |
| 7811 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7812 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7813 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 7814 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7815 | } |
| 7816 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7817 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 7818 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7819 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7820 | if (!AStmt) |
| 7821 | return StmtError(); |
| 7822 | |
| 7823 | auto *CS = cast<CapturedStmt>(AStmt); |
| 7824 | // 1.2.2 OpenMP Language Terminology |
| 7825 | // Structured block - An executable statement with a single entry at the |
| 7826 | // top and a single exit at the bottom. |
| 7827 | // The point of exit cannot be a branch out of the structured block. |
| 7828 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7829 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 7830 | for (int ThisCaptureLevel = |
| 7831 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_simd); |
| 7832 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7833 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7834 | // 1.2.2 OpenMP Language Terminology |
| 7835 | // Structured block - An executable statement with a single entry at the |
| 7836 | // top and a single exit at the bottom. |
| 7837 | // The point of exit cannot be a branch out of the structured block. |
| 7838 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7839 | CS->getCapturedDecl()->setNothrow(); |
| 7840 | } |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7841 | |
| 7842 | OMPLoopDirective::HelperExprs B; |
| 7843 | // In presence of clause 'collapse' with number of loops, it will |
| 7844 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7845 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7846 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 7847 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7848 | VarsWithImplicitDSA, B); |
| 7849 | if (NestedLoopCount == 0) |
| 7850 | return StmtError(); |
| 7851 | |
| 7852 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7853 | "omp target teams distribute simd loop exprs were not built"); |
| 7854 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7855 | if (!CurContext->isDependentContext()) { |
| 7856 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7857 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7858 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7859 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7860 | B.NumIterations, *this, CurScope, |
| 7861 | DSAStack)) |
| 7862 | return StmtError(); |
| 7863 | } |
| 7864 | } |
| 7865 | |
| 7866 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7867 | return StmtError(); |
| 7868 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7869 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7870 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 7871 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7872 | } |
| 7873 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7874 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7875 | SourceLocation StartLoc, |
| 7876 | SourceLocation LParenLoc, |
| 7877 | SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7878 | OMPClause *Res = nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7879 | switch (Kind) { |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7880 | case OMPC_final: |
| 7881 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7882 | break; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7883 | case OMPC_num_threads: |
| 7884 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7885 | break; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7886 | case OMPC_safelen: |
| 7887 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7888 | break; |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7889 | case OMPC_simdlen: |
| 7890 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7891 | break; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7892 | case OMPC_collapse: |
| 7893 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7894 | break; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7895 | case OMPC_ordered: |
| 7896 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 7897 | break; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7898 | case OMPC_device: |
| 7899 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7900 | break; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7901 | case OMPC_num_teams: |
| 7902 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7903 | break; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7904 | case OMPC_thread_limit: |
| 7905 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7906 | break; |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7907 | case OMPC_priority: |
| 7908 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7909 | break; |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7910 | case OMPC_grainsize: |
| 7911 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7912 | break; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7913 | case OMPC_num_tasks: |
| 7914 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7915 | break; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7916 | case OMPC_hint: |
| 7917 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7918 | break; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7919 | case OMPC_if: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7920 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7921 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7922 | case OMPC_schedule: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7923 | case OMPC_private: |
| 7924 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7925 | case OMPC_lastprivate: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7926 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7927 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 7928 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 7929 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7930 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7931 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7932 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7933 | case OMPC_copyprivate: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7934 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7935 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7936 | case OMPC_mergeable: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7937 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7938 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7939 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7940 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7941 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7942 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7943 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7944 | case OMPC_depend: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7945 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7946 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7947 | case OMPC_map: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7948 | case OMPC_nogroup: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7949 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7950 | case OMPC_defaultmap: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7951 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7952 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7953 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7954 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7955 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7956 | case OMPC_is_device_ptr: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7957 | llvm_unreachable("Clause is not allowed."); |
| 7958 | } |
| 7959 | return Res; |
| 7960 | } |
| 7961 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7962 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 7963 | // for the 'target' and 'parallel' respectively. This function returns |
| 7964 | // the region in which to capture expressions associated with a clause. |
| 7965 | // A return value of OMPD_unknown signifies that the expression should not |
| 7966 | // be captured. |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7967 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| 7968 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 7969 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7970 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7971 | switch (CKind) { |
| 7972 | case OMPC_if: |
| 7973 | switch (DKind) { |
| 7974 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 7975 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 7976 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7977 | // If this clause applies to the nested 'parallel' region, capture within |
| 7978 | // the 'target' region, otherwise do not capture. |
| 7979 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 7980 | CaptureRegion = OMPD_target; |
| 7981 | break; |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 7982 | case OMPD_target_teams_distribute_parallel_for: |
| 7983 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 7984 | // If this clause applies to the nested 'parallel' region, capture within |
| 7985 | // the 'teams' region, otherwise do not capture. |
| 7986 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 7987 | CaptureRegion = OMPD_teams; |
| 7988 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 7989 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 7990 | case OMPD_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 7991 | CaptureRegion = OMPD_teams; |
| 7992 | break; |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 7993 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 7994 | case OMPD_target_enter_data: |
| 7995 | case OMPD_target_exit_data: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 7996 | CaptureRegion = OMPD_task; |
| 7997 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7998 | case OMPD_cancel: |
| 7999 | case OMPD_parallel: |
| 8000 | case OMPD_parallel_sections: |
| 8001 | case OMPD_parallel_for: |
| 8002 | case OMPD_parallel_for_simd: |
| 8003 | case OMPD_target: |
| 8004 | case OMPD_target_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8005 | case OMPD_target_teams: |
| 8006 | case OMPD_target_teams_distribute: |
| 8007 | case OMPD_target_teams_distribute_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8008 | case OMPD_distribute_parallel_for: |
| 8009 | case OMPD_distribute_parallel_for_simd: |
| 8010 | case OMPD_task: |
| 8011 | case OMPD_taskloop: |
| 8012 | case OMPD_taskloop_simd: |
| 8013 | case OMPD_target_data: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8014 | // Do not capture if-clause expressions. |
| 8015 | break; |
| 8016 | case OMPD_threadprivate: |
| 8017 | case OMPD_taskyield: |
| 8018 | case OMPD_barrier: |
| 8019 | case OMPD_taskwait: |
| 8020 | case OMPD_cancellation_point: |
| 8021 | case OMPD_flush: |
| 8022 | case OMPD_declare_reduction: |
| 8023 | case OMPD_declare_simd: |
| 8024 | case OMPD_declare_target: |
| 8025 | case OMPD_end_declare_target: |
| 8026 | case OMPD_teams: |
| 8027 | case OMPD_simd: |
| 8028 | case OMPD_for: |
| 8029 | case OMPD_for_simd: |
| 8030 | case OMPD_sections: |
| 8031 | case OMPD_section: |
| 8032 | case OMPD_single: |
| 8033 | case OMPD_master: |
| 8034 | case OMPD_critical: |
| 8035 | case OMPD_taskgroup: |
| 8036 | case OMPD_distribute: |
| 8037 | case OMPD_ordered: |
| 8038 | case OMPD_atomic: |
| 8039 | case OMPD_distribute_simd: |
| 8040 | case OMPD_teams_distribute: |
| 8041 | case OMPD_teams_distribute_simd: |
| 8042 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 8043 | case OMPD_unknown: |
| 8044 | llvm_unreachable("Unknown OpenMP directive"); |
| 8045 | } |
| 8046 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8047 | case OMPC_num_threads: |
| 8048 | switch (DKind) { |
| 8049 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8050 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 8051 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8052 | CaptureRegion = OMPD_target; |
| 8053 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8054 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8055 | case OMPD_teams_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8056 | case OMPD_target_teams_distribute_parallel_for: |
| 8057 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8058 | CaptureRegion = OMPD_teams; |
| 8059 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8060 | case OMPD_parallel: |
| 8061 | case OMPD_parallel_sections: |
| 8062 | case OMPD_parallel_for: |
| 8063 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8064 | case OMPD_distribute_parallel_for: |
| 8065 | case OMPD_distribute_parallel_for_simd: |
| 8066 | // Do not capture num_threads-clause expressions. |
| 8067 | break; |
| 8068 | case OMPD_target_data: |
| 8069 | case OMPD_target_enter_data: |
| 8070 | case OMPD_target_exit_data: |
| 8071 | case OMPD_target_update: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8072 | case OMPD_target: |
| 8073 | case OMPD_target_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8074 | case OMPD_target_teams: |
| 8075 | case OMPD_target_teams_distribute: |
| 8076 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8077 | case OMPD_cancel: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8078 | case OMPD_task: |
| 8079 | case OMPD_taskloop: |
| 8080 | case OMPD_taskloop_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8081 | case OMPD_threadprivate: |
| 8082 | case OMPD_taskyield: |
| 8083 | case OMPD_barrier: |
| 8084 | case OMPD_taskwait: |
| 8085 | case OMPD_cancellation_point: |
| 8086 | case OMPD_flush: |
| 8087 | case OMPD_declare_reduction: |
| 8088 | case OMPD_declare_simd: |
| 8089 | case OMPD_declare_target: |
| 8090 | case OMPD_end_declare_target: |
| 8091 | case OMPD_teams: |
| 8092 | case OMPD_simd: |
| 8093 | case OMPD_for: |
| 8094 | case OMPD_for_simd: |
| 8095 | case OMPD_sections: |
| 8096 | case OMPD_section: |
| 8097 | case OMPD_single: |
| 8098 | case OMPD_master: |
| 8099 | case OMPD_critical: |
| 8100 | case OMPD_taskgroup: |
| 8101 | case OMPD_distribute: |
| 8102 | case OMPD_ordered: |
| 8103 | case OMPD_atomic: |
| 8104 | case OMPD_distribute_simd: |
| 8105 | case OMPD_teams_distribute: |
| 8106 | case OMPD_teams_distribute_simd: |
| 8107 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 8108 | case OMPD_unknown: |
| 8109 | llvm_unreachable("Unknown OpenMP directive"); |
| 8110 | } |
| 8111 | break; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8112 | case OMPC_num_teams: |
| 8113 | switch (DKind) { |
| 8114 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8115 | case OMPD_target_teams_distribute: |
| 8116 | case OMPD_target_teams_distribute_simd: |
| 8117 | case OMPD_target_teams_distribute_parallel_for: |
| 8118 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8119 | CaptureRegion = OMPD_target; |
| 8120 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8121 | case OMPD_teams_distribute_parallel_for: |
| 8122 | case OMPD_teams_distribute_parallel_for_simd: |
| 8123 | case OMPD_teams: |
| 8124 | case OMPD_teams_distribute: |
| 8125 | case OMPD_teams_distribute_simd: |
| 8126 | // Do not capture num_teams-clause expressions. |
| 8127 | break; |
| 8128 | case OMPD_distribute_parallel_for: |
| 8129 | case OMPD_distribute_parallel_for_simd: |
| 8130 | case OMPD_task: |
| 8131 | case OMPD_taskloop: |
| 8132 | case OMPD_taskloop_simd: |
| 8133 | case OMPD_target_data: |
| 8134 | case OMPD_target_enter_data: |
| 8135 | case OMPD_target_exit_data: |
| 8136 | case OMPD_target_update: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8137 | case OMPD_cancel: |
| 8138 | case OMPD_parallel: |
| 8139 | case OMPD_parallel_sections: |
| 8140 | case OMPD_parallel_for: |
| 8141 | case OMPD_parallel_for_simd: |
| 8142 | case OMPD_target: |
| 8143 | case OMPD_target_simd: |
| 8144 | case OMPD_target_parallel: |
| 8145 | case OMPD_target_parallel_for: |
| 8146 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8147 | case OMPD_threadprivate: |
| 8148 | case OMPD_taskyield: |
| 8149 | case OMPD_barrier: |
| 8150 | case OMPD_taskwait: |
| 8151 | case OMPD_cancellation_point: |
| 8152 | case OMPD_flush: |
| 8153 | case OMPD_declare_reduction: |
| 8154 | case OMPD_declare_simd: |
| 8155 | case OMPD_declare_target: |
| 8156 | case OMPD_end_declare_target: |
| 8157 | case OMPD_simd: |
| 8158 | case OMPD_for: |
| 8159 | case OMPD_for_simd: |
| 8160 | case OMPD_sections: |
| 8161 | case OMPD_section: |
| 8162 | case OMPD_single: |
| 8163 | case OMPD_master: |
| 8164 | case OMPD_critical: |
| 8165 | case OMPD_taskgroup: |
| 8166 | case OMPD_distribute: |
| 8167 | case OMPD_ordered: |
| 8168 | case OMPD_atomic: |
| 8169 | case OMPD_distribute_simd: |
| 8170 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 8171 | case OMPD_unknown: |
| 8172 | llvm_unreachable("Unknown OpenMP directive"); |
| 8173 | } |
| 8174 | break; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8175 | case OMPC_thread_limit: |
| 8176 | switch (DKind) { |
| 8177 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8178 | case OMPD_target_teams_distribute: |
| 8179 | case OMPD_target_teams_distribute_simd: |
| 8180 | case OMPD_target_teams_distribute_parallel_for: |
| 8181 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8182 | CaptureRegion = OMPD_target; |
| 8183 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8184 | case OMPD_teams_distribute_parallel_for: |
| 8185 | case OMPD_teams_distribute_parallel_for_simd: |
| 8186 | case OMPD_teams: |
| 8187 | case OMPD_teams_distribute: |
| 8188 | case OMPD_teams_distribute_simd: |
| 8189 | // Do not capture thread_limit-clause expressions. |
| 8190 | break; |
| 8191 | case OMPD_distribute_parallel_for: |
| 8192 | case OMPD_distribute_parallel_for_simd: |
| 8193 | case OMPD_task: |
| 8194 | case OMPD_taskloop: |
| 8195 | case OMPD_taskloop_simd: |
| 8196 | case OMPD_target_data: |
| 8197 | case OMPD_target_enter_data: |
| 8198 | case OMPD_target_exit_data: |
| 8199 | case OMPD_target_update: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8200 | case OMPD_cancel: |
| 8201 | case OMPD_parallel: |
| 8202 | case OMPD_parallel_sections: |
| 8203 | case OMPD_parallel_for: |
| 8204 | case OMPD_parallel_for_simd: |
| 8205 | case OMPD_target: |
| 8206 | case OMPD_target_simd: |
| 8207 | case OMPD_target_parallel: |
| 8208 | case OMPD_target_parallel_for: |
| 8209 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8210 | case OMPD_threadprivate: |
| 8211 | case OMPD_taskyield: |
| 8212 | case OMPD_barrier: |
| 8213 | case OMPD_taskwait: |
| 8214 | case OMPD_cancellation_point: |
| 8215 | case OMPD_flush: |
| 8216 | case OMPD_declare_reduction: |
| 8217 | case OMPD_declare_simd: |
| 8218 | case OMPD_declare_target: |
| 8219 | case OMPD_end_declare_target: |
| 8220 | case OMPD_simd: |
| 8221 | case OMPD_for: |
| 8222 | case OMPD_for_simd: |
| 8223 | case OMPD_sections: |
| 8224 | case OMPD_section: |
| 8225 | case OMPD_single: |
| 8226 | case OMPD_master: |
| 8227 | case OMPD_critical: |
| 8228 | case OMPD_taskgroup: |
| 8229 | case OMPD_distribute: |
| 8230 | case OMPD_ordered: |
| 8231 | case OMPD_atomic: |
| 8232 | case OMPD_distribute_simd: |
| 8233 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 8234 | case OMPD_unknown: |
| 8235 | llvm_unreachable("Unknown OpenMP directive"); |
| 8236 | } |
| 8237 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8238 | case OMPC_schedule: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8239 | switch (DKind) { |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8240 | case OMPD_parallel_for: |
| 8241 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 8242 | case OMPD_distribute_parallel_for: |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 8243 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8244 | case OMPD_teams_distribute_parallel_for: |
| 8245 | case OMPD_teams_distribute_parallel_for_simd: |
| 8246 | case OMPD_target_parallel_for: |
| 8247 | case OMPD_target_parallel_for_simd: |
| 8248 | case OMPD_target_teams_distribute_parallel_for: |
| 8249 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 8250 | CaptureRegion = OMPD_parallel; |
| 8251 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8252 | case OMPD_for: |
| 8253 | case OMPD_for_simd: |
| 8254 | // Do not capture schedule-clause expressions. |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8255 | break; |
| 8256 | case OMPD_task: |
| 8257 | case OMPD_taskloop: |
| 8258 | case OMPD_taskloop_simd: |
| 8259 | case OMPD_target_data: |
| 8260 | case OMPD_target_enter_data: |
| 8261 | case OMPD_target_exit_data: |
| 8262 | case OMPD_target_update: |
| 8263 | case OMPD_teams: |
| 8264 | case OMPD_teams_distribute: |
| 8265 | case OMPD_teams_distribute_simd: |
| 8266 | case OMPD_target_teams_distribute: |
| 8267 | case OMPD_target_teams_distribute_simd: |
| 8268 | case OMPD_target: |
| 8269 | case OMPD_target_simd: |
| 8270 | case OMPD_target_parallel: |
| 8271 | case OMPD_cancel: |
| 8272 | case OMPD_parallel: |
| 8273 | case OMPD_parallel_sections: |
| 8274 | case OMPD_threadprivate: |
| 8275 | case OMPD_taskyield: |
| 8276 | case OMPD_barrier: |
| 8277 | case OMPD_taskwait: |
| 8278 | case OMPD_cancellation_point: |
| 8279 | case OMPD_flush: |
| 8280 | case OMPD_declare_reduction: |
| 8281 | case OMPD_declare_simd: |
| 8282 | case OMPD_declare_target: |
| 8283 | case OMPD_end_declare_target: |
| 8284 | case OMPD_simd: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8285 | case OMPD_sections: |
| 8286 | case OMPD_section: |
| 8287 | case OMPD_single: |
| 8288 | case OMPD_master: |
| 8289 | case OMPD_critical: |
| 8290 | case OMPD_taskgroup: |
| 8291 | case OMPD_distribute: |
| 8292 | case OMPD_ordered: |
| 8293 | case OMPD_atomic: |
| 8294 | case OMPD_distribute_simd: |
| 8295 | case OMPD_target_teams: |
| 8296 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 8297 | case OMPD_unknown: |
| 8298 | llvm_unreachable("Unknown OpenMP directive"); |
| 8299 | } |
| 8300 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8301 | case OMPC_dist_schedule: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8302 | switch (DKind) { |
| 8303 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8304 | case OMPD_teams_distribute_parallel_for_simd: |
| 8305 | case OMPD_teams_distribute: |
| 8306 | case OMPD_teams_distribute_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8307 | case OMPD_target_teams_distribute_parallel_for: |
| 8308 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8309 | case OMPD_target_teams_distribute: |
| 8310 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8311 | CaptureRegion = OMPD_teams; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8312 | break; |
| 8313 | case OMPD_distribute_parallel_for: |
| 8314 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8315 | case OMPD_distribute: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8316 | case OMPD_distribute_simd: |
| 8317 | // Do not capture thread_limit-clause expressions. |
| 8318 | break; |
| 8319 | case OMPD_parallel_for: |
| 8320 | case OMPD_parallel_for_simd: |
| 8321 | case OMPD_target_parallel_for_simd: |
| 8322 | case OMPD_target_parallel_for: |
| 8323 | case OMPD_task: |
| 8324 | case OMPD_taskloop: |
| 8325 | case OMPD_taskloop_simd: |
| 8326 | case OMPD_target_data: |
| 8327 | case OMPD_target_enter_data: |
| 8328 | case OMPD_target_exit_data: |
| 8329 | case OMPD_target_update: |
| 8330 | case OMPD_teams: |
| 8331 | case OMPD_target: |
| 8332 | case OMPD_target_simd: |
| 8333 | case OMPD_target_parallel: |
| 8334 | case OMPD_cancel: |
| 8335 | case OMPD_parallel: |
| 8336 | case OMPD_parallel_sections: |
| 8337 | case OMPD_threadprivate: |
| 8338 | case OMPD_taskyield: |
| 8339 | case OMPD_barrier: |
| 8340 | case OMPD_taskwait: |
| 8341 | case OMPD_cancellation_point: |
| 8342 | case OMPD_flush: |
| 8343 | case OMPD_declare_reduction: |
| 8344 | case OMPD_declare_simd: |
| 8345 | case OMPD_declare_target: |
| 8346 | case OMPD_end_declare_target: |
| 8347 | case OMPD_simd: |
| 8348 | case OMPD_for: |
| 8349 | case OMPD_for_simd: |
| 8350 | case OMPD_sections: |
| 8351 | case OMPD_section: |
| 8352 | case OMPD_single: |
| 8353 | case OMPD_master: |
| 8354 | case OMPD_critical: |
| 8355 | case OMPD_taskgroup: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8356 | case OMPD_ordered: |
| 8357 | case OMPD_atomic: |
| 8358 | case OMPD_target_teams: |
| 8359 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 8360 | case OMPD_unknown: |
| 8361 | llvm_unreachable("Unknown OpenMP directive"); |
| 8362 | } |
| 8363 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8364 | case OMPC_device: |
| 8365 | switch (DKind) { |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8366 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 8367 | case OMPD_target_enter_data: |
| 8368 | case OMPD_target_exit_data: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 8369 | case OMPD_target: |
| Alexey Bataev | f41c88f | 2018-01-16 15:05:16 +0000 | [diff] [blame] | 8370 | case OMPD_target_simd: |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 8371 | case OMPD_target_teams: |
| Alexey Bataev | 54d5c7d | 2018-01-16 16:27:49 +0000 | [diff] [blame] | 8372 | case OMPD_target_parallel: |
| Alexey Bataev | 79df756 | 2018-01-16 16:46:46 +0000 | [diff] [blame] | 8373 | case OMPD_target_teams_distribute: |
| Alexey Bataev | 8d16a43 | 2018-01-16 17:22:50 +0000 | [diff] [blame] | 8374 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 8ed89551 | 2018-01-16 17:41:04 +0000 | [diff] [blame] | 8375 | case OMPD_target_parallel_for: |
| Alexey Bataev | d60d1ba | 2018-01-16 17:55:15 +0000 | [diff] [blame] | 8376 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 8377 | case OMPD_target_teams_distribute_parallel_for: |
| Alexey Bataev | 9350fc3 | 2018-01-16 19:18:24 +0000 | [diff] [blame] | 8378 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8379 | CaptureRegion = OMPD_task; |
| 8380 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8381 | case OMPD_target_data: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8382 | // Do not capture device-clause expressions. |
| 8383 | break; |
| 8384 | case OMPD_teams_distribute_parallel_for: |
| 8385 | case OMPD_teams_distribute_parallel_for_simd: |
| 8386 | case OMPD_teams: |
| 8387 | case OMPD_teams_distribute: |
| 8388 | case OMPD_teams_distribute_simd: |
| 8389 | case OMPD_distribute_parallel_for: |
| 8390 | case OMPD_distribute_parallel_for_simd: |
| 8391 | case OMPD_task: |
| 8392 | case OMPD_taskloop: |
| 8393 | case OMPD_taskloop_simd: |
| 8394 | case OMPD_cancel: |
| 8395 | case OMPD_parallel: |
| 8396 | case OMPD_parallel_sections: |
| 8397 | case OMPD_parallel_for: |
| 8398 | case OMPD_parallel_for_simd: |
| 8399 | case OMPD_threadprivate: |
| 8400 | case OMPD_taskyield: |
| 8401 | case OMPD_barrier: |
| 8402 | case OMPD_taskwait: |
| 8403 | case OMPD_cancellation_point: |
| 8404 | case OMPD_flush: |
| 8405 | case OMPD_declare_reduction: |
| 8406 | case OMPD_declare_simd: |
| 8407 | case OMPD_declare_target: |
| 8408 | case OMPD_end_declare_target: |
| 8409 | case OMPD_simd: |
| 8410 | case OMPD_for: |
| 8411 | case OMPD_for_simd: |
| 8412 | case OMPD_sections: |
| 8413 | case OMPD_section: |
| 8414 | case OMPD_single: |
| 8415 | case OMPD_master: |
| 8416 | case OMPD_critical: |
| 8417 | case OMPD_taskgroup: |
| 8418 | case OMPD_distribute: |
| 8419 | case OMPD_ordered: |
| 8420 | case OMPD_atomic: |
| 8421 | case OMPD_distribute_simd: |
| 8422 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 8423 | case OMPD_unknown: |
| 8424 | llvm_unreachable("Unknown OpenMP directive"); |
| 8425 | } |
| 8426 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8427 | case OMPC_firstprivate: |
| 8428 | case OMPC_lastprivate: |
| 8429 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8430 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8431 | case OMPC_in_reduction: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8432 | case OMPC_linear: |
| 8433 | case OMPC_default: |
| 8434 | case OMPC_proc_bind: |
| 8435 | case OMPC_final: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8436 | case OMPC_safelen: |
| 8437 | case OMPC_simdlen: |
| 8438 | case OMPC_collapse: |
| 8439 | case OMPC_private: |
| 8440 | case OMPC_shared: |
| 8441 | case OMPC_aligned: |
| 8442 | case OMPC_copyin: |
| 8443 | case OMPC_copyprivate: |
| 8444 | case OMPC_ordered: |
| 8445 | case OMPC_nowait: |
| 8446 | case OMPC_untied: |
| 8447 | case OMPC_mergeable: |
| 8448 | case OMPC_threadprivate: |
| 8449 | case OMPC_flush: |
| 8450 | case OMPC_read: |
| 8451 | case OMPC_write: |
| 8452 | case OMPC_update: |
| 8453 | case OMPC_capture: |
| 8454 | case OMPC_seq_cst: |
| 8455 | case OMPC_depend: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8456 | case OMPC_threads: |
| 8457 | case OMPC_simd: |
| 8458 | case OMPC_map: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8459 | case OMPC_priority: |
| 8460 | case OMPC_grainsize: |
| 8461 | case OMPC_nogroup: |
| 8462 | case OMPC_num_tasks: |
| 8463 | case OMPC_hint: |
| 8464 | case OMPC_defaultmap: |
| 8465 | case OMPC_unknown: |
| 8466 | case OMPC_uniform: |
| 8467 | case OMPC_to: |
| 8468 | case OMPC_from: |
| 8469 | case OMPC_use_device_ptr: |
| 8470 | case OMPC_is_device_ptr: |
| 8471 | llvm_unreachable("Unexpected OpenMP clause."); |
| 8472 | } |
| 8473 | return CaptureRegion; |
| 8474 | } |
| 8475 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8476 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 8477 | Expr *Condition, SourceLocation StartLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8478 | SourceLocation LParenLoc, |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8479 | SourceLocation NameModifierLoc, |
| 8480 | SourceLocation ColonLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8481 | SourceLocation EndLoc) { |
| 8482 | Expr *ValExpr = Condition; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8483 | Stmt *HelperValStmt = nullptr; |
| 8484 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8485 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 8486 | !Condition->isInstantiationDependent() && |
| 8487 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8488 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8489 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8490 | return nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8491 | |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 8492 | ValExpr = Val.get(); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8493 | |
| 8494 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 8495 | CaptureRegion = |
| 8496 | getOpenMPCaptureRegionForClause(DKind, OMPC_if, NameModifier); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8497 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 8498 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8499 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8500 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 8501 | HelperValStmt = buildPreInits(Context, Captures); |
| 8502 | } |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8503 | } |
| 8504 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8505 | return new (Context) |
| 8506 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 8507 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8508 | } |
| 8509 | |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8510 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 8511 | SourceLocation StartLoc, |
| 8512 | SourceLocation LParenLoc, |
| 8513 | SourceLocation EndLoc) { |
| 8514 | Expr *ValExpr = Condition; |
| 8515 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 8516 | !Condition->isInstantiationDependent() && |
| 8517 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8518 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8519 | if (Val.isInvalid()) |
| 8520 | return nullptr; |
| 8521 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8522 | ValExpr = MakeFullExpr(Val.get()).get(); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8523 | } |
| 8524 | |
| 8525 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8526 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8527 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 8528 | Expr *Op) { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8529 | if (!Op) |
| 8530 | return ExprError(); |
| 8531 | |
| 8532 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 8533 | public: |
| 8534 | IntConvertDiagnoser() |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8535 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 8536 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 8537 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8538 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 8539 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8540 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 8541 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8542 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 8543 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8544 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 8545 | QualType T, |
| 8546 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8547 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 8548 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8549 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 8550 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8551 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8552 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8553 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8554 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 8555 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8556 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 8557 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8558 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 8559 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8560 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8561 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8562 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8563 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 8564 | QualType) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8565 | llvm_unreachable("conversion functions are permitted"); |
| 8566 | } |
| 8567 | } ConvertDiagnoser; |
| 8568 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 8569 | } |
| 8570 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8571 | static bool isNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8572 | OpenMPClauseKind CKind, |
| 8573 | bool StrictlyPositive) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8574 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 8575 | !ValExpr->isInstantiationDependent()) { |
| 8576 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 8577 | ExprResult Value = |
| 8578 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 8579 | if (Value.isInvalid()) |
| 8580 | return false; |
| 8581 | |
| 8582 | ValExpr = Value.get(); |
| 8583 | // The expression must evaluate to a non-negative integer value. |
| 8584 | llvm::APSInt Result; |
| 8585 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8586 | Result.isSigned() && |
| 8587 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 8588 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8589 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8590 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 8591 | << ValExpr->getSourceRange(); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8592 | return false; |
| 8593 | } |
| 8594 | } |
| 8595 | return true; |
| 8596 | } |
| 8597 | |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8598 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 8599 | SourceLocation StartLoc, |
| 8600 | SourceLocation LParenLoc, |
| 8601 | SourceLocation EndLoc) { |
| 8602 | Expr *ValExpr = NumThreads; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8603 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8604 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8605 | // OpenMP [2.5, Restrictions] |
| 8606 | // The num_threads expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8607 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8608 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8609 | return nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8610 | |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8611 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8612 | OpenMPDirectiveKind CaptureRegion = |
| 8613 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads); |
| 8614 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 8615 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8616 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8617 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 8618 | HelperValStmt = buildPreInits(Context, Captures); |
| 8619 | } |
| 8620 | |
| 8621 | return new (Context) OMPNumThreadsClause( |
| 8622 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8623 | } |
| 8624 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8625 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8626 | OpenMPClauseKind CKind, |
| 8627 | bool StrictlyPositive) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8628 | if (!E) |
| 8629 | return ExprError(); |
| 8630 | if (E->isValueDependent() || E->isTypeDependent() || |
| 8631 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8632 | return E; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8633 | llvm::APSInt Result; |
| 8634 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 8635 | if (ICE.isInvalid()) |
| 8636 | return ExprError(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8637 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 8638 | (!StrictlyPositive && !Result.isNonNegative())) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8639 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8640 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 8641 | << E->getSourceRange(); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8642 | return ExprError(); |
| 8643 | } |
| Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 8644 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 8645 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 8646 | << E->getSourceRange(); |
| 8647 | return ExprError(); |
| 8648 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8649 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 8650 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 8651 | else if (CKind == OMPC_ordered) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8652 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8653 | return ICE; |
| 8654 | } |
| 8655 | |
| 8656 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 8657 | SourceLocation LParenLoc, |
| 8658 | SourceLocation EndLoc) { |
| 8659 | // OpenMP [2.8.1, simd construct, Description] |
| 8660 | // The parameter of the safelen clause must be a constant |
| 8661 | // positive integer expression. |
| 8662 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 8663 | if (Safelen.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8664 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8665 | return new (Context) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8666 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8667 | } |
| 8668 | |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8669 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 8670 | SourceLocation LParenLoc, |
| 8671 | SourceLocation EndLoc) { |
| 8672 | // OpenMP [2.8.1, simd construct, Description] |
| 8673 | // The parameter of the simdlen clause must be a constant |
| 8674 | // positive integer expression. |
| 8675 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 8676 | if (Simdlen.isInvalid()) |
| 8677 | return nullptr; |
| 8678 | return new (Context) |
| 8679 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 8680 | } |
| 8681 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8682 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 8683 | SourceLocation StartLoc, |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8684 | SourceLocation LParenLoc, |
| 8685 | SourceLocation EndLoc) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8686 | // OpenMP [2.7.1, loop construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8687 | // OpenMP [2.8.1, simd construct, Description] |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8688 | // OpenMP [2.9.6, distribute construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8689 | // The parameter of the collapse clause must be a constant |
| 8690 | // positive integer expression. |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8691 | ExprResult NumForLoopsResult = |
| 8692 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 8693 | if (NumForLoopsResult.isInvalid()) |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8694 | return nullptr; |
| 8695 | return new (Context) |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8696 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8697 | } |
| 8698 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8699 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 8700 | SourceLocation EndLoc, |
| 8701 | SourceLocation LParenLoc, |
| 8702 | Expr *NumForLoops) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8703 | // OpenMP [2.7.1, loop construct, Description] |
| 8704 | // OpenMP [2.8.1, simd construct, Description] |
| 8705 | // OpenMP [2.9.6, distribute construct, Description] |
| 8706 | // The parameter of the ordered clause must be a constant |
| 8707 | // positive integer expression if any. |
| 8708 | if (NumForLoops && LParenLoc.isValid()) { |
| 8709 | ExprResult NumForLoopsResult = |
| 8710 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 8711 | if (NumForLoopsResult.isInvalid()) |
| 8712 | return nullptr; |
| 8713 | NumForLoops = NumForLoopsResult.get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8714 | } else { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8715 | NumForLoops = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8716 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 8717 | auto *Clause = OMPOrderedClause::Create( |
| 8718 | Context, NumForLoops, NumForLoops ? DSAStack->getAssociatedLoops() : 0, |
| 8719 | StartLoc, LParenLoc, EndLoc); |
| 8720 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops, Clause); |
| 8721 | return Clause; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8722 | } |
| 8723 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8724 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 8725 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 8726 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8727 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8728 | switch (Kind) { |
| 8729 | case OMPC_default: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8730 | Res = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8731 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 8732 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8733 | break; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8734 | case OMPC_proc_bind: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8735 | Res = ActOnOpenMPProcBindClause( |
| 8736 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 8737 | LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8738 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8739 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8740 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8741 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8742 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8743 | case OMPC_simdlen: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8744 | case OMPC_collapse: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8745 | case OMPC_schedule: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8746 | case OMPC_private: |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8747 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8748 | case OMPC_lastprivate: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8749 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8750 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8751 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8752 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8753 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8754 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8755 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8756 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8757 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8758 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8759 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8760 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8761 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8762 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8763 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8764 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8765 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8766 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8767 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8768 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8769 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8770 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8771 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8772 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8773 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8774 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8775 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8776 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8777 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8778 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8779 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8780 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8781 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8782 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8783 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8784 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8785 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8786 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8787 | case OMPC_is_device_ptr: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8788 | llvm_unreachable("Clause is not allowed."); |
| 8789 | } |
| 8790 | return Res; |
| 8791 | } |
| 8792 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8793 | static std::string |
| 8794 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 8795 | ArrayRef<unsigned> Exclude = llvm::None) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8796 | SmallString<256> Buffer; |
| 8797 | llvm::raw_svector_ostream Out(Buffer); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8798 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 8799 | unsigned Skipped = Exclude.size(); |
| 8800 | auto S = Exclude.begin(), E = Exclude.end(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8801 | for (unsigned I = First; I < Last; ++I) { |
| 8802 | if (std::find(S, E, I) != E) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8803 | --Skipped; |
| 8804 | continue; |
| 8805 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8806 | Out << "'" << getOpenMPSimpleClauseTypeName(K, I) << "'"; |
| 8807 | if (I == Bound - Skipped) |
| 8808 | Out << " or "; |
| 8809 | else if (I != Bound + 1 - Skipped) |
| 8810 | Out << ", "; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8811 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8812 | return Out.str(); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8813 | } |
| 8814 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8815 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 8816 | SourceLocation KindKwLoc, |
| 8817 | SourceLocation StartLoc, |
| 8818 | SourceLocation LParenLoc, |
| 8819 | SourceLocation EndLoc) { |
| 8820 | if (Kind == OMPC_DEFAULT_unknown) { |
| Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 8821 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 8822 | "OMPC_DEFAULT_unknown not greater than 0"); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8823 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8824 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 8825 | /*Last=*/OMPC_DEFAULT_unknown) |
| 8826 | << getOpenMPClauseName(OMPC_default); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8827 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8828 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8829 | switch (Kind) { |
| 8830 | case OMPC_DEFAULT_none: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8831 | DSAStack->setDefaultDSANone(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8832 | break; |
| 8833 | case OMPC_DEFAULT_shared: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8834 | DSAStack->setDefaultDSAShared(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8835 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8836 | case OMPC_DEFAULT_unknown: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8837 | llvm_unreachable("Clause kind is not allowed."); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8838 | break; |
| 8839 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8840 | return new (Context) |
| 8841 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8842 | } |
| 8843 | |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8844 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 8845 | SourceLocation KindKwLoc, |
| 8846 | SourceLocation StartLoc, |
| 8847 | SourceLocation LParenLoc, |
| 8848 | SourceLocation EndLoc) { |
| 8849 | if (Kind == OMPC_PROC_BIND_unknown) { |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8850 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8851 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 8852 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 8853 | << getOpenMPClauseName(OMPC_proc_bind); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8854 | return nullptr; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8855 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8856 | return new (Context) |
| 8857 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8858 | } |
| 8859 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8860 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8861 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8862 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8863 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8864 | SourceLocation EndLoc) { |
| 8865 | OMPClause *Res = nullptr; |
| 8866 | switch (Kind) { |
| 8867 | case OMPC_schedule: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8868 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 8869 | assert(Argument.size() == NumberOfElements && |
| 8870 | ArgumentLoc.size() == NumberOfElements); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8871 | Res = ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8872 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 8873 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 8874 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 8875 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 8876 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8877 | break; |
| 8878 | case OMPC_if: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8879 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 8880 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 8881 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 8882 | DelimLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8883 | break; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8884 | case OMPC_dist_schedule: |
| 8885 | Res = ActOnOpenMPDistScheduleClause( |
| 8886 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 8887 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 8888 | break; |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8889 | case OMPC_defaultmap: |
| 8890 | enum { Modifier, DefaultmapKind }; |
| 8891 | Res = ActOnOpenMPDefaultmapClause( |
| 8892 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 8893 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8894 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 8895 | EndLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8896 | break; |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8897 | case OMPC_final: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8898 | case OMPC_num_threads: |
| 8899 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8900 | case OMPC_simdlen: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8901 | case OMPC_collapse: |
| 8902 | case OMPC_default: |
| 8903 | case OMPC_proc_bind: |
| 8904 | case OMPC_private: |
| 8905 | case OMPC_firstprivate: |
| 8906 | case OMPC_lastprivate: |
| 8907 | case OMPC_shared: |
| 8908 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8909 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8910 | case OMPC_in_reduction: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8911 | case OMPC_linear: |
| 8912 | case OMPC_aligned: |
| 8913 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8914 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8915 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8916 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8917 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8918 | case OMPC_mergeable: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8919 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8920 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8921 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8922 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8923 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8924 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8925 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8926 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8927 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8928 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8929 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8930 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8931 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8932 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8933 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8934 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8935 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8936 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8937 | case OMPC_hint: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8938 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8939 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8940 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8941 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8942 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8943 | case OMPC_is_device_ptr: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8944 | llvm_unreachable("Clause is not allowed."); |
| 8945 | } |
| 8946 | return Res; |
| 8947 | } |
| 8948 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8949 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 8950 | OpenMPScheduleClauseModifier M2, |
| 8951 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 8952 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 8953 | SmallVector<unsigned, 2> Excluded; |
| 8954 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 8955 | Excluded.push_back(M2); |
| 8956 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 8957 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 8958 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 8959 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 8960 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 8961 | << getListOfPossibleValues(OMPC_schedule, |
| 8962 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 8963 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 8964 | Excluded) |
| 8965 | << getOpenMPClauseName(OMPC_schedule); |
| 8966 | return true; |
| 8967 | } |
| 8968 | return false; |
| 8969 | } |
| 8970 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8971 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8972 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8973 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8974 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 8975 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 8976 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 8977 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 8978 | return nullptr; |
| 8979 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 8980 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 8981 | // but not both. |
| 8982 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 8983 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 8984 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 8985 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 8986 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 8987 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 8988 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 8989 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 8990 | return nullptr; |
| 8991 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8992 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 8993 | std::string Values; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8994 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 8995 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 8996 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 8997 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 8998 | Exclude); |
| 8999 | } else { |
| 9000 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 9001 | /*Last=*/OMPC_SCHEDULE_unknown); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9002 | } |
| 9003 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9004 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 9005 | return nullptr; |
| 9006 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9007 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 9008 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 9009 | // schedule(guided). |
| 9010 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 9011 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 9012 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 9013 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 9014 | diag::err_omp_schedule_nonmonotonic_static); |
| 9015 | return nullptr; |
| 9016 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9017 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9018 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9019 | if (ChunkSize) { |
| 9020 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9021 | !ChunkSize->isInstantiationDependent() && |
| 9022 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9023 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9024 | ExprResult Val = |
| 9025 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9026 | if (Val.isInvalid()) |
| 9027 | return nullptr; |
| 9028 | |
| 9029 | ValExpr = Val.get(); |
| 9030 | |
| 9031 | // OpenMP [2.7.1, Restrictions] |
| 9032 | // chunk_size must be a loop invariant integer expression with a positive |
| 9033 | // value. |
| 9034 | llvm::APSInt Result; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 9035 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9036 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9037 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9038 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 9039 | return nullptr; |
| 9040 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 9041 | } else if (getOpenMPCaptureRegionForClause( |
| 9042 | DSAStack->getCurrentDirective(), OMPC_schedule) != |
| 9043 | OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 9044 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 9045 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9046 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9047 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 9048 | HelperValStmt = buildPreInits(Context, Captures); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9049 | } |
| 9050 | } |
| 9051 | } |
| 9052 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9053 | return new (Context) |
| 9054 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9055 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9056 | } |
| 9057 | |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9058 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 9059 | SourceLocation StartLoc, |
| 9060 | SourceLocation EndLoc) { |
| 9061 | OMPClause *Res = nullptr; |
| 9062 | switch (Kind) { |
| 9063 | case OMPC_ordered: |
| 9064 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 9065 | break; |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9066 | case OMPC_nowait: |
| 9067 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 9068 | break; |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9069 | case OMPC_untied: |
| 9070 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 9071 | break; |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9072 | case OMPC_mergeable: |
| 9073 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 9074 | break; |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9075 | case OMPC_read: |
| 9076 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 9077 | break; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9078 | case OMPC_write: |
| 9079 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 9080 | break; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9081 | case OMPC_update: |
| 9082 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 9083 | break; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9084 | case OMPC_capture: |
| 9085 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 9086 | break; |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9087 | case OMPC_seq_cst: |
| 9088 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 9089 | break; |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9090 | case OMPC_threads: |
| 9091 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 9092 | break; |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9093 | case OMPC_simd: |
| 9094 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 9095 | break; |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9096 | case OMPC_nogroup: |
| 9097 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 9098 | break; |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9099 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9100 | case OMPC_final: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9101 | case OMPC_num_threads: |
| 9102 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9103 | case OMPC_simdlen: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9104 | case OMPC_collapse: |
| 9105 | case OMPC_schedule: |
| 9106 | case OMPC_private: |
| 9107 | case OMPC_firstprivate: |
| 9108 | case OMPC_lastprivate: |
| 9109 | case OMPC_shared: |
| 9110 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9111 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9112 | case OMPC_in_reduction: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9113 | case OMPC_linear: |
| 9114 | case OMPC_aligned: |
| 9115 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9116 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9117 | case OMPC_default: |
| 9118 | case OMPC_proc_bind: |
| 9119 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9120 | case OMPC_flush: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9121 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9122 | case OMPC_device: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9123 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9124 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9125 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9126 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9127 | case OMPC_grainsize: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9128 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9129 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9130 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9131 | case OMPC_defaultmap: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9132 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9133 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9134 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9135 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9136 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9137 | case OMPC_is_device_ptr: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9138 | llvm_unreachable("Clause is not allowed."); |
| 9139 | } |
| 9140 | return Res; |
| 9141 | } |
| 9142 | |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9143 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 9144 | SourceLocation EndLoc) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 9145 | DSAStack->setNowaitRegion(); |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9146 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 9147 | } |
| 9148 | |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9149 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 9150 | SourceLocation EndLoc) { |
| 9151 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 9152 | } |
| 9153 | |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9154 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 9155 | SourceLocation EndLoc) { |
| 9156 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 9157 | } |
| 9158 | |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9159 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 9160 | SourceLocation EndLoc) { |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9161 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 9162 | } |
| 9163 | |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9164 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 9165 | SourceLocation EndLoc) { |
| 9166 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 9167 | } |
| 9168 | |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9169 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 9170 | SourceLocation EndLoc) { |
| 9171 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 9172 | } |
| 9173 | |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9174 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 9175 | SourceLocation EndLoc) { |
| 9176 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 9177 | } |
| 9178 | |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9179 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 9180 | SourceLocation EndLoc) { |
| 9181 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 9182 | } |
| 9183 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9184 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 9185 | SourceLocation EndLoc) { |
| 9186 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 9187 | } |
| 9188 | |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9189 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 9190 | SourceLocation EndLoc) { |
| 9191 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 9192 | } |
| 9193 | |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9194 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 9195 | SourceLocation EndLoc) { |
| 9196 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 9197 | } |
| 9198 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9199 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 9200 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 9201 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 9202 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9203 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9204 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 9205 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9206 | SourceLocation DepLinMapLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9207 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9208 | switch (Kind) { |
| 9209 | case OMPC_private: |
| 9210 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9211 | break; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9212 | case OMPC_firstprivate: |
| 9213 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9214 | break; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9215 | case OMPC_lastprivate: |
| 9216 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9217 | break; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9218 | case OMPC_shared: |
| 9219 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9220 | break; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9221 | case OMPC_reduction: |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9222 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 9223 | EndLoc, ReductionIdScopeSpec, ReductionId); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9224 | break; |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9225 | case OMPC_task_reduction: |
| 9226 | Res = ActOnOpenMPTaskReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 9227 | EndLoc, ReductionIdScopeSpec, |
| 9228 | ReductionId); |
| 9229 | break; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9230 | case OMPC_in_reduction: |
| 9231 | Res = |
| 9232 | ActOnOpenMPInReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 9233 | EndLoc, ReductionIdScopeSpec, ReductionId); |
| 9234 | break; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9235 | case OMPC_linear: |
| 9236 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9237 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9238 | break; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9239 | case OMPC_aligned: |
| 9240 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 9241 | ColonLoc, EndLoc); |
| 9242 | break; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9243 | case OMPC_copyin: |
| 9244 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9245 | break; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9246 | case OMPC_copyprivate: |
| 9247 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9248 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9249 | case OMPC_flush: |
| 9250 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9251 | break; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9252 | case OMPC_depend: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9253 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9254 | StartLoc, LParenLoc, EndLoc); |
| 9255 | break; |
| 9256 | case OMPC_map: |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9257 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9258 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 9259 | LParenLoc, EndLoc); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9260 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9261 | case OMPC_to: |
| 9262 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9263 | break; |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9264 | case OMPC_from: |
| 9265 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9266 | break; |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9267 | case OMPC_use_device_ptr: |
| 9268 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9269 | break; |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9270 | case OMPC_is_device_ptr: |
| 9271 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9272 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 9273 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9274 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9275 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9276 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9277 | case OMPC_simdlen: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9278 | case OMPC_collapse: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9279 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9280 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9281 | case OMPC_schedule: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9282 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9283 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9284 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9285 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9286 | case OMPC_threadprivate: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9287 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9288 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9289 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9290 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9291 | case OMPC_seq_cst: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9292 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9293 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9294 | case OMPC_simd: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9295 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9296 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9297 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9298 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9299 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9300 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9301 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9302 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9303 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9304 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9305 | case OMPC_uniform: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9306 | llvm_unreachable("Clause is not allowed."); |
| 9307 | } |
| 9308 | return Res; |
| 9309 | } |
| 9310 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9311 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9312 | ExprObjectKind OK, SourceLocation Loc) { |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9313 | ExprResult Res = BuildDeclRefExpr( |
| 9314 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 9315 | if (!Res.isUsable()) |
| 9316 | return ExprError(); |
| 9317 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 9318 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 9319 | if (!Res.isUsable()) |
| 9320 | return ExprError(); |
| 9321 | } |
| 9322 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 9323 | Res = DefaultLvalueConversion(Res.get()); |
| 9324 | if (!Res.isUsable()) |
| 9325 | return ExprError(); |
| 9326 | } |
| 9327 | return Res; |
| 9328 | } |
| 9329 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9330 | static std::pair<ValueDecl *, bool> |
| 9331 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 9332 | SourceRange &ERange, bool AllowArraySection = false) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9333 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 9334 | RefExpr->containsUnexpandedParameterPack()) |
| 9335 | return std::make_pair(nullptr, true); |
| 9336 | |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9337 | // OpenMP [3.1, C/C++] |
| 9338 | // A list item is a variable name. |
| 9339 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 9340 | // A variable that is part of another variable (as an array or |
| 9341 | // structure element) cannot appear in a private clause. |
| 9342 | RefExpr = RefExpr->IgnoreParens(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9343 | enum { |
| 9344 | NoArrayExpr = -1, |
| 9345 | ArraySubscript = 0, |
| 9346 | OMPArraySection = 1 |
| 9347 | } IsArrayExpr = NoArrayExpr; |
| 9348 | if (AllowArraySection) { |
| 9349 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9350 | Expr *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9351 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 9352 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 9353 | RefExpr = Base; |
| 9354 | IsArrayExpr = ArraySubscript; |
| 9355 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9356 | Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9357 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 9358 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 9359 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 9360 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 9361 | RefExpr = Base; |
| 9362 | IsArrayExpr = OMPArraySection; |
| 9363 | } |
| 9364 | } |
| 9365 | ELoc = RefExpr->getExprLoc(); |
| 9366 | ERange = RefExpr->getSourceRange(); |
| 9367 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9368 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 9369 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 9370 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 9371 | (S.getCurrentThisType().isNull() || !ME || |
| 9372 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 9373 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9374 | if (IsArrayExpr != NoArrayExpr) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9375 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 9376 | << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9377 | } else { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9378 | S.Diag(ELoc, |
| 9379 | AllowArraySection |
| 9380 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 9381 | : diag::err_omp_expected_var_name_member_expr) |
| 9382 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 9383 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9384 | return std::make_pair(nullptr, false); |
| 9385 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9386 | return std::make_pair( |
| 9387 | getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9388 | } |
| 9389 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9390 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 9391 | SourceLocation StartLoc, |
| 9392 | SourceLocation LParenLoc, |
| 9393 | SourceLocation EndLoc) { |
| 9394 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9395 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9396 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9397 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9398 | SourceLocation ELoc; |
| 9399 | SourceRange ERange; |
| 9400 | Expr *SimpleRefExpr = RefExpr; |
| 9401 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9402 | if (Res.second) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9403 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9404 | Vars.push_back(RefExpr); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9405 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9406 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9407 | ValueDecl *D = Res.first; |
| 9408 | if (!D) |
| 9409 | continue; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9410 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9411 | QualType Type = D->getType(); |
| 9412 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9413 | |
| 9414 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9415 | // A variable that appears in a private clause must not have an incomplete |
| 9416 | // type or a reference type. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9417 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9418 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9419 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9420 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9421 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9422 | // in a Construct] |
| 9423 | // Variables with the predetermined data-sharing attributes may not be |
| 9424 | // listed in data-sharing attributes clauses, except for the cases |
| 9425 | // listed below. For these exceptions only, listing a predetermined |
| 9426 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9427 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9428 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9429 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9430 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9431 | << getOpenMPClauseName(OMPC_private); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9432 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9433 | continue; |
| 9434 | } |
| 9435 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9436 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9437 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9438 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 9439 | isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9440 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 9441 | << getOpenMPClauseName(OMPC_private) << Type |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 9442 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9443 | bool IsDecl = |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9444 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9445 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9446 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9447 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9448 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9449 | continue; |
| 9450 | } |
| 9451 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9452 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 9453 | // A list item cannot appear in both a map clause and a data-sharing |
| 9454 | // attribute clause on the same construct |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9455 | if (isOpenMPTargetExecutionDirective(CurrDir)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9456 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9457 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9458 | VD, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9459 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 9460 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 9461 | ConflictKind = WhereFoundClauseKind; |
| 9462 | return true; |
| 9463 | })) { |
| 9464 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9465 | << getOpenMPClauseName(OMPC_private) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9466 | << getOpenMPClauseName(ConflictKind) |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 9467 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9468 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9469 | continue; |
| 9470 | } |
| 9471 | } |
| 9472 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9473 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 9474 | // A variable of class type (or array thereof) that appears in a private |
| 9475 | // clause requires an accessible, unambiguous default constructor for the |
| 9476 | // class type. |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9477 | // Generate helper private variable and initialize it with the default |
| 9478 | // value. The address of the original variable is replaced by the address of |
| 9479 | // the new private variable in CodeGen. This new variable is not added to |
| 9480 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 9481 | // proper diagnostics. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9482 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9483 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 9484 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9485 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 9486 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9487 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9488 | if (VDPrivate->isInvalidDecl()) |
| 9489 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9490 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9491 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9492 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9493 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9494 | if (!VD && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9495 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9496 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9497 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9498 | ? RefExpr->IgnoreParens() |
| 9499 | : Ref); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9500 | PrivateCopies.push_back(VDPrivateRefExpr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9501 | } |
| 9502 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9503 | if (Vars.empty()) |
| 9504 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9505 | |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9506 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9507 | PrivateCopies); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9508 | } |
| 9509 | |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9510 | namespace { |
| 9511 | class DiagsUninitializedSeveretyRAII { |
| 9512 | private: |
| 9513 | DiagnosticsEngine &Diags; |
| 9514 | SourceLocation SavedLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9515 | bool IsIgnored = false; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9516 | |
| 9517 | public: |
| 9518 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 9519 | bool IsIgnored) |
| 9520 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 9521 | if (!IsIgnored) { |
| 9522 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 9523 | /*Map*/ diag::Severity::Ignored, Loc); |
| 9524 | } |
| 9525 | } |
| 9526 | ~DiagsUninitializedSeveretyRAII() { |
| 9527 | if (!IsIgnored) |
| 9528 | Diags.popMappings(SavedLoc); |
| 9529 | } |
| 9530 | }; |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 9531 | } |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9532 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9533 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 9534 | SourceLocation StartLoc, |
| 9535 | SourceLocation LParenLoc, |
| 9536 | SourceLocation EndLoc) { |
| 9537 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9538 | SmallVector<Expr *, 8> PrivateCopies; |
| 9539 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 9540 | SmallVector<Decl *, 4> ExprCaptures; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9541 | bool IsImplicitClause = |
| 9542 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9543 | SourceLocation ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9544 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9545 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9546 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9547 | SourceLocation ELoc; |
| 9548 | SourceRange ERange; |
| 9549 | Expr *SimpleRefExpr = RefExpr; |
| 9550 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9551 | if (Res.second) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9552 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9553 | Vars.push_back(RefExpr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9554 | PrivateCopies.push_back(nullptr); |
| 9555 | Inits.push_back(nullptr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9556 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9557 | ValueDecl *D = Res.first; |
| 9558 | if (!D) |
| 9559 | continue; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9560 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9561 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9562 | QualType Type = D->getType(); |
| 9563 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9564 | |
| 9565 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9566 | // A variable that appears in a private clause must not have an incomplete |
| 9567 | // type or a reference type. |
| 9568 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9569 | diag::err_omp_firstprivate_incomplete_type)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9570 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9571 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9572 | |
| 9573 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 9574 | // 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] | 9575 | // clause requires an accessible, unambiguous copy constructor for the |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9576 | // class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9577 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9578 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9579 | // If an implicit firstprivate variable found it was checked already. |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9580 | DSAStackTy::DSAVarData TopDVar; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9581 | if (!IsImplicitClause) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9582 | DSAStackTy::DSAVarData DVar = |
| 9583 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9584 | TopDVar = DVar; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9585 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9586 | bool IsConstant = ElemType.isConstant(Context); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9587 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 9588 | // A list item that specifies a given variable may not appear in more |
| 9589 | // than one clause on the same directive, except that a variable may be |
| 9590 | // specified in both firstprivate and lastprivate clauses. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9591 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 9592 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 9593 | // both. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9594 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 9595 | (isOpenMPDistributeDirective(CurrDir) || |
| 9596 | DVar.CKind != OMPC_lastprivate) && |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9597 | DVar.RefExpr) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9598 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9599 | << getOpenMPClauseName(DVar.CKind) |
| 9600 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9601 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9602 | continue; |
| 9603 | } |
| 9604 | |
| 9605 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9606 | // in a Construct] |
| 9607 | // Variables with the predetermined data-sharing attributes may not be |
| 9608 | // listed in data-sharing attributes clauses, except for the cases |
| 9609 | // listed below. For these exceptions only, listing a predetermined |
| 9610 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9611 | // the variable's predetermined data-sharing attributes. |
| 9612 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9613 | // in a Construct, C/C++, p.2] |
| 9614 | // Variables with const-qualified type having no mutable member may be |
| 9615 | // listed in a firstprivate clause, even if they are static data members. |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9616 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9617 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 9618 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9619 | << getOpenMPClauseName(DVar.CKind) |
| 9620 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9621 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9622 | continue; |
| 9623 | } |
| 9624 | |
| 9625 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 9626 | // A list item that is private within a parallel region must not appear |
| 9627 | // in a firstprivate clause on a worksharing construct if any of the |
| 9628 | // worksharing regions arising from the worksharing construct ever bind |
| 9629 | // to any of the parallel regions arising from the parallel construct. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9630 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 9631 | // A list item that is private within a teams region must not appear in a |
| 9632 | // firstprivate clause on a distribute construct if any of the distribute |
| 9633 | // regions arising from the distribute construct ever bind to any of the |
| 9634 | // teams regions arising from the teams construct. |
| 9635 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 9636 | // A list item that appears in a reduction clause of a teams construct |
| 9637 | // must not appear in a firstprivate clause on a distribute construct if |
| 9638 | // any of the distribute regions arising from the distribute construct |
| 9639 | // ever bind to any of the teams regions arising from the teams construct. |
| 9640 | if ((isOpenMPWorksharingDirective(CurrDir) || |
| 9641 | isOpenMPDistributeDirective(CurrDir)) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 9642 | !isOpenMPParallelDirective(CurrDir) && |
| 9643 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9644 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9645 | if (DVar.CKind != OMPC_shared && |
| 9646 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9647 | isOpenMPTeamsDirective(DVar.DKind) || |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9648 | DVar.DKind == OMPD_unknown)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9649 | Diag(ELoc, diag::err_omp_required_access) |
| 9650 | << getOpenMPClauseName(OMPC_firstprivate) |
| 9651 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9652 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9653 | continue; |
| 9654 | } |
| 9655 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9656 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 9657 | // A list item that appears in a reduction clause of a parallel construct |
| 9658 | // must not appear in a firstprivate clause on a worksharing or task |
| 9659 | // construct if any of the worksharing or task regions arising from the |
| 9660 | // worksharing or task construct ever bind to any of the parallel regions |
| 9661 | // arising from the parallel construct. |
| 9662 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 9663 | // A list item that appears in a reduction clause in worksharing |
| 9664 | // construct must not appear in a firstprivate clause in a task construct |
| 9665 | // encountered during execution of any of the worksharing regions arising |
| 9666 | // from the worksharing construct. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 9667 | if (isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 9668 | DVar = DSAStack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9669 | D, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 9670 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 9671 | return isOpenMPParallelDirective(K) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9672 | isOpenMPWorksharingDirective(K) || |
| 9673 | isOpenMPTeamsDirective(K); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 9674 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9675 | /*FromParent=*/true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9676 | if (DVar.CKind == OMPC_reduction && |
| 9677 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9678 | isOpenMPWorksharingDirective(DVar.DKind) || |
| 9679 | isOpenMPTeamsDirective(DVar.DKind))) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9680 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 9681 | << getOpenMPDirectiveName(DVar.DKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9682 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9683 | continue; |
| 9684 | } |
| 9685 | } |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 9686 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9687 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 9688 | // A list item cannot appear in both a map clause and a data-sharing |
| 9689 | // attribute clause on the same construct |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 9690 | if (isOpenMPTargetExecutionDirective(CurrDir)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9691 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9692 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9693 | VD, /*CurrentRegionOnly=*/true, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9694 | [&ConflictKind]( |
| 9695 | OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 9696 | OpenMPClauseKind WhereFoundClauseKind) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9697 | ConflictKind = WhereFoundClauseKind; |
| 9698 | return true; |
| 9699 | })) { |
| 9700 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9701 | << getOpenMPClauseName(OMPC_firstprivate) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9702 | << getOpenMPClauseName(ConflictKind) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9703 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9704 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9705 | continue; |
| 9706 | } |
| 9707 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9708 | } |
| 9709 | |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9710 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9711 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 9712 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9713 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 9714 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 9715 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 9716 | bool IsDecl = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9717 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9718 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9719 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9720 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9721 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9722 | continue; |
| 9723 | } |
| 9724 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9725 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9726 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 9727 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9728 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 9729 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9730 | // Generate helper private variable and initialize it with the value of the |
| 9731 | // original variable. The address of the original variable is replaced by |
| 9732 | // the address of the new private variable in the CodeGen. This new variable |
| 9733 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 9734 | // original variable for proper diagnostics and variable capturing. |
| 9735 | Expr *VDInitRefExpr = nullptr; |
| 9736 | // For arrays generate initializer for single element and replace it by the |
| 9737 | // original array element in CodeGen. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9738 | if (Type->isArrayType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9739 | VarDecl *VDInit = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9740 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9741 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9742 | Expr *Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9743 | ElemType = ElemType.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9744 | VarDecl *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
| 9745 | ".firstprivate.temp"); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 9746 | InitializedEntity Entity = |
| 9747 | InitializedEntity::InitializeVariable(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9748 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 9749 | |
| 9750 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 9751 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 9752 | if (Result.isInvalid()) |
| 9753 | VDPrivate->setInvalidDecl(); |
| 9754 | else |
| 9755 | VDPrivate->setInit(Result.getAs<Expr>()); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9756 | // Remove temp variable declaration. |
| 9757 | Context.Deallocate(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9758 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9759 | VarDecl *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 9760 | ".firstprivate.temp"); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9761 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 9762 | RefExpr->getExprLoc()); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 9763 | AddInitializerToDecl(VDPrivate, |
| 9764 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9765 | /*DirectInit=*/false); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9766 | } |
| 9767 | if (VDPrivate->isInvalidDecl()) { |
| 9768 | if (IsImplicitClause) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9769 | Diag(RefExpr->getExprLoc(), |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9770 | diag::note_omp_task_predetermined_firstprivate_here); |
| 9771 | } |
| 9772 | continue; |
| 9773 | } |
| 9774 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9775 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9776 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 9777 | RefExpr->getExprLoc()); |
| 9778 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9779 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9780 | if (TopDVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9781 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9782 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9783 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9784 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9785 | ExprCaptures.push_back(Ref->getDecl()); |
| 9786 | } |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 9787 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9788 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9789 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9790 | ? RefExpr->IgnoreParens() |
| 9791 | : Ref); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 9792 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 9793 | Inits.push_back(VDInitRefExpr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9794 | } |
| 9795 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9796 | if (Vars.empty()) |
| 9797 | return nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9798 | |
| 9799 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9800 | Vars, PrivateCopies, Inits, |
| 9801 | buildPreInits(Context, ExprCaptures)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9802 | } |
| 9803 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9804 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 9805 | SourceLocation StartLoc, |
| 9806 | SourceLocation LParenLoc, |
| 9807 | SourceLocation EndLoc) { |
| 9808 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9809 | SmallVector<Expr *, 8> SrcExprs; |
| 9810 | SmallVector<Expr *, 8> DstExprs; |
| 9811 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9812 | SmallVector<Decl *, 4> ExprCaptures; |
| 9813 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9814 | for (Expr *RefExpr : VarList) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9815 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9816 | SourceLocation ELoc; |
| 9817 | SourceRange ERange; |
| 9818 | Expr *SimpleRefExpr = RefExpr; |
| 9819 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9820 | if (Res.second) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9821 | // It will be analyzed later. |
| 9822 | Vars.push_back(RefExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9823 | SrcExprs.push_back(nullptr); |
| 9824 | DstExprs.push_back(nullptr); |
| 9825 | AssignmentOps.push_back(nullptr); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9826 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9827 | ValueDecl *D = Res.first; |
| 9828 | if (!D) |
| 9829 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9830 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9831 | QualType Type = D->getType(); |
| 9832 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9833 | |
| 9834 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 9835 | // A variable that appears in a lastprivate clause must not have an |
| 9836 | // incomplete type or a reference type. |
| 9837 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9838 | diag::err_omp_lastprivate_incomplete_type)) |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9839 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9840 | Type = Type.getNonReferenceType(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9841 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9842 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9843 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9844 | // in a Construct] |
| 9845 | // Variables with the predetermined data-sharing attributes may not be |
| 9846 | // listed in data-sharing attributes clauses, except for the cases |
| 9847 | // listed below. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 9848 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 9849 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 9850 | // both. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9851 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9852 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 9853 | (isOpenMPDistributeDirective(CurrDir) || |
| 9854 | DVar.CKind != OMPC_firstprivate) && |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9855 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 9856 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9857 | << getOpenMPClauseName(DVar.CKind) |
| 9858 | << getOpenMPClauseName(OMPC_lastprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9859 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9860 | continue; |
| 9861 | } |
| 9862 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9863 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 9864 | // A list item that is private within a parallel region, or that appears in |
| 9865 | // the reduction clause of a parallel construct, must not appear in a |
| 9866 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 9867 | // worksharing regions ever binds to any of the corresponding parallel |
| 9868 | // regions. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9869 | DSAStackTy::DSAVarData TopDVar = DVar; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 9870 | if (isOpenMPWorksharingDirective(CurrDir) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 9871 | !isOpenMPParallelDirective(CurrDir) && |
| 9872 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9873 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9874 | if (DVar.CKind != OMPC_shared) { |
| 9875 | Diag(ELoc, diag::err_omp_required_access) |
| 9876 | << getOpenMPClauseName(OMPC_lastprivate) |
| 9877 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9878 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9879 | continue; |
| 9880 | } |
| 9881 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9882 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9883 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9884 | // A variable of class type (or array thereof) that appears in a |
| 9885 | // lastprivate clause requires an accessible, unambiguous default |
| 9886 | // constructor for the class type, unless the list item is also specified |
| 9887 | // in a firstprivate clause. |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9888 | // A variable of class type (or array thereof) that appears in a |
| 9889 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 9890 | // operator for the class type. |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9891 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9892 | VarDecl *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
| 9893 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 9894 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9895 | DeclRefExpr *PseudoSrcExpr = |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9896 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9897 | VarDecl *DstVD = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9898 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9899 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9900 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9901 | // For arrays generate assignment operation for single element and replace |
| 9902 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9903 | ExprResult AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
| 9904 | PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9905 | if (AssignmentOp.isInvalid()) |
| 9906 | continue; |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9907 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9908 | /*DiscardedValue=*/true); |
| 9909 | if (AssignmentOp.isInvalid()) |
| 9910 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9911 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 9912 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9913 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9914 | if (TopDVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9915 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9916 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9917 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9918 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9919 | ExprCaptures.push_back(Ref->getDecl()); |
| 9920 | } |
| 9921 | if (TopDVar.CKind == OMPC_firstprivate || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9922 | (!isOpenMPCapturedDecl(D) && |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9923 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9924 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9925 | if (!RefRes.isUsable()) |
| 9926 | continue; |
| 9927 | ExprResult PostUpdateRes = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9928 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 9929 | RefRes.get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9930 | if (!PostUpdateRes.isUsable()) |
| 9931 | continue; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9932 | ExprPostUpdates.push_back( |
| 9933 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9934 | } |
| 9935 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 9936 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9937 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9938 | ? RefExpr->IgnoreParens() |
| 9939 | : Ref); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 9940 | SrcExprs.push_back(PseudoSrcExpr); |
| 9941 | DstExprs.push_back(PseudoDstExpr); |
| 9942 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9943 | } |
| 9944 | |
| 9945 | if (Vars.empty()) |
| 9946 | return nullptr; |
| 9947 | |
| 9948 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9949 | Vars, SrcExprs, DstExprs, AssignmentOps, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9950 | buildPreInits(Context, ExprCaptures), |
| 9951 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9952 | } |
| 9953 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9954 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 9955 | SourceLocation StartLoc, |
| 9956 | SourceLocation LParenLoc, |
| 9957 | SourceLocation EndLoc) { |
| 9958 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9959 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9960 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9961 | SourceLocation ELoc; |
| 9962 | SourceRange ERange; |
| 9963 | Expr *SimpleRefExpr = RefExpr; |
| 9964 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9965 | if (Res.second) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9966 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9967 | Vars.push_back(RefExpr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9968 | } |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9969 | ValueDecl *D = Res.first; |
| 9970 | if (!D) |
| 9971 | continue; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9972 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9973 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9974 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9975 | // in a Construct] |
| 9976 | // Variables with the predetermined data-sharing attributes may not be |
| 9977 | // listed in data-sharing attributes clauses, except for the cases |
| 9978 | // listed below. For these exceptions only, listing a predetermined |
| 9979 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9980 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9981 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9982 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 9983 | DVar.RefExpr) { |
| 9984 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9985 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9986 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9987 | continue; |
| 9988 | } |
| 9989 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9990 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9991 | if (!VD && isOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9992 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9993 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9994 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 9995 | ? RefExpr->IgnoreParens() |
| 9996 | : Ref); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9997 | } |
| 9998 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9999 | if (Vars.empty()) |
| 10000 | return nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10001 | |
| 10002 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 10003 | } |
| 10004 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10005 | namespace { |
| 10006 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 10007 | DSAStackTy *Stack; |
| 10008 | |
| 10009 | public: |
| 10010 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10011 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 10012 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10013 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 10014 | return false; |
| 10015 | if (DVar.CKind != OMPC_unknown) |
| 10016 | return true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10017 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10018 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) { return true; }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10019 | /*FromParent=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10020 | return DVarPrivate.CKind != OMPC_unknown; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10021 | } |
| 10022 | return false; |
| 10023 | } |
| 10024 | bool VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10025 | for (Stmt *Child : S->children()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10026 | if (Child && Visit(Child)) |
| 10027 | return true; |
| 10028 | } |
| 10029 | return false; |
| 10030 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10031 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10032 | }; |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10033 | } // namespace |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10034 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10035 | namespace { |
| 10036 | // Transform MemberExpression for specified FieldDecl of current class to |
| 10037 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 10038 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 10039 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10040 | ValueDecl *Field = nullptr; |
| 10041 | DeclRefExpr *CapturedExpr = nullptr; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10042 | |
| 10043 | public: |
| 10044 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 10045 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 10046 | |
| 10047 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 10048 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 10049 | E->getMemberDecl() == Field) { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10050 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10051 | return CapturedExpr; |
| 10052 | } |
| 10053 | return BaseTransform::TransformMemberExpr(E); |
| 10054 | } |
| 10055 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 10056 | }; |
| 10057 | } // namespace |
| 10058 | |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 10059 | template <typename T, typename U> |
| 10060 | static T filterLookupForUDR(SmallVectorImpl<U> &Lookups, |
| 10061 | const llvm::function_ref<T(ValueDecl *)> Gen) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10062 | for (U &Set : Lookups) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10063 | for (auto *D : Set) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10064 | if (T Res = Gen(cast<ValueDecl>(D))) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10065 | return Res; |
| 10066 | } |
| 10067 | } |
| 10068 | return T(); |
| 10069 | } |
| 10070 | |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10071 | static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D) { |
| 10072 | assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case"); |
| 10073 | |
| 10074 | for (auto RD : D->redecls()) { |
| 10075 | // Don't bother with extra checks if we already know this one isn't visible. |
| 10076 | if (RD == D) |
| 10077 | continue; |
| 10078 | |
| 10079 | auto ND = cast<NamedDecl>(RD); |
| 10080 | if (LookupResult::isVisible(SemaRef, ND)) |
| 10081 | return ND; |
| 10082 | } |
| 10083 | |
| 10084 | return nullptr; |
| 10085 | } |
| 10086 | |
| 10087 | static void |
| 10088 | argumentDependentLookup(Sema &SemaRef, const DeclarationNameInfo &ReductionId, |
| 10089 | SourceLocation Loc, QualType Ty, |
| 10090 | SmallVectorImpl<UnresolvedSet<8>> &Lookups) { |
| 10091 | // Find all of the associated namespaces and classes based on the |
| 10092 | // arguments we have. |
| 10093 | Sema::AssociatedNamespaceSet AssociatedNamespaces; |
| 10094 | Sema::AssociatedClassSet AssociatedClasses; |
| 10095 | OpaqueValueExpr OVE(Loc, Ty, VK_LValue); |
| 10096 | SemaRef.FindAssociatedClassesAndNamespaces(Loc, &OVE, AssociatedNamespaces, |
| 10097 | AssociatedClasses); |
| 10098 | |
| 10099 | // C++ [basic.lookup.argdep]p3: |
| 10100 | // Let X be the lookup set produced by unqualified lookup (3.4.1) |
| 10101 | // and let Y be the lookup set produced by argument dependent |
| 10102 | // lookup (defined as follows). If X contains [...] then Y is |
| 10103 | // empty. Otherwise Y is the set of declarations found in the |
| 10104 | // namespaces associated with the argument types as described |
| 10105 | // below. The set of declarations found by the lookup of the name |
| 10106 | // is the union of X and Y. |
| 10107 | // |
| 10108 | // Here, we compute Y and add its members to the overloaded |
| 10109 | // candidate set. |
| 10110 | for (auto *NS : AssociatedNamespaces) { |
| 10111 | // When considering an associated namespace, the lookup is the |
| 10112 | // same as the lookup performed when the associated namespace is |
| 10113 | // used as a qualifier (3.4.3.2) except that: |
| 10114 | // |
| 10115 | // -- Any using-directives in the associated namespace are |
| 10116 | // ignored. |
| 10117 | // |
| 10118 | // -- Any namespace-scope friend functions declared in |
| 10119 | // associated classes are visible within their respective |
| 10120 | // namespaces even if they are not visible during an ordinary |
| 10121 | // lookup (11.4). |
| 10122 | DeclContext::lookup_result R = NS->lookup(ReductionId.getName()); |
| 10123 | for (auto *D : R) { |
| 10124 | auto *Underlying = D; |
| 10125 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 10126 | Underlying = USD->getTargetDecl(); |
| 10127 | |
| 10128 | if (!isa<OMPDeclareReductionDecl>(Underlying)) |
| 10129 | continue; |
| 10130 | |
| 10131 | if (!SemaRef.isVisible(D)) { |
| 10132 | D = findAcceptableDecl(SemaRef, D); |
| 10133 | if (!D) |
| 10134 | continue; |
| 10135 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 10136 | Underlying = USD->getTargetDecl(); |
| 10137 | } |
| 10138 | Lookups.emplace_back(); |
| 10139 | Lookups.back().addDecl(Underlying); |
| 10140 | } |
| 10141 | } |
| 10142 | } |
| 10143 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10144 | static ExprResult |
| 10145 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 10146 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 10147 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 10148 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 10149 | if (ReductionIdScopeSpec.isInvalid()) |
| 10150 | return ExprError(); |
| 10151 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 10152 | if (S) { |
| 10153 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 10154 | Lookup.suppressDiagnostics(); |
| 10155 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10156 | NamedDecl *D = Lookup.getRepresentativeDecl(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10157 | do { |
| 10158 | S = S->getParent(); |
| 10159 | } while (S && !S->isDeclScope(D)); |
| 10160 | if (S) |
| 10161 | S = S->getParent(); |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10162 | Lookups.emplace_back(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10163 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 10164 | Lookup.clear(); |
| 10165 | } |
| 10166 | } else if (auto *ULE = |
| 10167 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 10168 | Lookups.push_back(UnresolvedSet<8>()); |
| 10169 | Decl *PrevD = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10170 | for (NamedDecl *D : ULE->decls()) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10171 | if (D == PrevD) |
| 10172 | Lookups.push_back(UnresolvedSet<8>()); |
| 10173 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 10174 | Lookups.back().addDecl(DRD); |
| 10175 | PrevD = D; |
| 10176 | } |
| 10177 | } |
| Alexey Bataev | fdc2035 | 2017-08-25 15:43:55 +0000 | [diff] [blame] | 10178 | if (SemaRef.CurContext->isDependentContext() || Ty->isDependentType() || |
| 10179 | Ty->isInstantiationDependentType() || |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10180 | Ty->containsUnexpandedParameterPack() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10181 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10182 | return !D->isInvalidDecl() && |
| 10183 | (D->getType()->isDependentType() || |
| 10184 | D->getType()->isInstantiationDependentType() || |
| 10185 | D->getType()->containsUnexpandedParameterPack()); |
| 10186 | })) { |
| 10187 | UnresolvedSet<8> ResSet; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10188 | for (const UnresolvedSet<8> &Set : Lookups) { |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10189 | if (Set.empty()) |
| 10190 | continue; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10191 | ResSet.append(Set.begin(), Set.end()); |
| 10192 | // The last item marks the end of all declarations at the specified scope. |
| 10193 | ResSet.addDecl(Set[Set.size() - 1]); |
| 10194 | } |
| 10195 | return UnresolvedLookupExpr::Create( |
| 10196 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 10197 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 10198 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 10199 | } |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10200 | // Lookup inside the classes. |
| 10201 | // C++ [over.match.oper]p3: |
| 10202 | // For a unary operator @ with an operand of a type whose |
| 10203 | // cv-unqualified version is T1, and for a binary operator @ with |
| 10204 | // a left operand of a type whose cv-unqualified version is T1 and |
| 10205 | // a right operand of a type whose cv-unqualified version is T2, |
| 10206 | // three sets of candidate functions, designated member |
| 10207 | // candidates, non-member candidates and built-in candidates, are |
| 10208 | // constructed as follows: |
| 10209 | // -- If T1 is a complete class type or a class currently being |
| 10210 | // defined, the set of member candidates is the result of the |
| 10211 | // qualified lookup of T1::operator@ (13.3.1.1.1); otherwise, |
| 10212 | // the set of member candidates is empty. |
| 10213 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 10214 | Lookup.suppressDiagnostics(); |
| 10215 | if (const auto *TyRec = Ty->getAs<RecordType>()) { |
| 10216 | // Complete the type if it can be completed. |
| 10217 | // If the type is neither complete nor being defined, bail out now. |
| 10218 | if (SemaRef.isCompleteType(Loc, Ty) || TyRec->isBeingDefined() || |
| 10219 | TyRec->getDecl()->getDefinition()) { |
| 10220 | Lookup.clear(); |
| 10221 | SemaRef.LookupQualifiedName(Lookup, TyRec->getDecl()); |
| 10222 | if (Lookup.empty()) { |
| 10223 | Lookups.emplace_back(); |
| 10224 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 10225 | } |
| 10226 | } |
| 10227 | } |
| 10228 | // Perform ADL. |
| 10229 | argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10230 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 10231 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 10232 | if (!D->isInvalidDecl() && |
| 10233 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 10234 | return D; |
| 10235 | return nullptr; |
| 10236 | })) |
| 10237 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 10238 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 10239 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 10240 | if (!D->isInvalidDecl() && |
| 10241 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 10242 | !Ty.isMoreQualifiedThan(D->getType())) |
| 10243 | return D; |
| 10244 | return nullptr; |
| 10245 | })) { |
| 10246 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 10247 | /*DetectVirtual=*/false); |
| 10248 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 10249 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 10250 | VD->getType().getUnqualifiedType()))) { |
| 10251 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 10252 | /*DiagID=*/0) != |
| 10253 | Sema::AR_inaccessible) { |
| 10254 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 10255 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 10256 | } |
| 10257 | } |
| 10258 | } |
| 10259 | } |
| 10260 | if (ReductionIdScopeSpec.isSet()) { |
| 10261 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 10262 | return ExprError(); |
| 10263 | } |
| 10264 | return ExprEmpty(); |
| 10265 | } |
| 10266 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10267 | namespace { |
| 10268 | /// Data for the reduction-based clauses. |
| 10269 | struct ReductionData { |
| 10270 | /// List of original reduction items. |
| 10271 | SmallVector<Expr *, 8> Vars; |
| 10272 | /// List of private copies of the reduction items. |
| 10273 | SmallVector<Expr *, 8> Privates; |
| 10274 | /// LHS expressions for the reduction_op expressions. |
| 10275 | SmallVector<Expr *, 8> LHSs; |
| 10276 | /// RHS expressions for the reduction_op expressions. |
| 10277 | SmallVector<Expr *, 8> RHSs; |
| 10278 | /// Reduction operation expression. |
| 10279 | SmallVector<Expr *, 8> ReductionOps; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10280 | /// Taskgroup descriptors for the corresponding reduction items in |
| 10281 | /// in_reduction clauses. |
| 10282 | SmallVector<Expr *, 8> TaskgroupDescriptors; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10283 | /// List of captures for clause. |
| 10284 | SmallVector<Decl *, 4> ExprCaptures; |
| 10285 | /// List of postupdate expressions. |
| 10286 | SmallVector<Expr *, 4> ExprPostUpdates; |
| 10287 | ReductionData() = delete; |
| 10288 | /// Reserves required memory for the reduction data. |
| 10289 | ReductionData(unsigned Size) { |
| 10290 | Vars.reserve(Size); |
| 10291 | Privates.reserve(Size); |
| 10292 | LHSs.reserve(Size); |
| 10293 | RHSs.reserve(Size); |
| 10294 | ReductionOps.reserve(Size); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10295 | TaskgroupDescriptors.reserve(Size); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10296 | ExprCaptures.reserve(Size); |
| 10297 | ExprPostUpdates.reserve(Size); |
| 10298 | } |
| 10299 | /// Stores reduction item and reduction operation only (required for dependent |
| 10300 | /// reduction item). |
| 10301 | void push(Expr *Item, Expr *ReductionOp) { |
| 10302 | Vars.emplace_back(Item); |
| 10303 | Privates.emplace_back(nullptr); |
| 10304 | LHSs.emplace_back(nullptr); |
| 10305 | RHSs.emplace_back(nullptr); |
| 10306 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10307 | TaskgroupDescriptors.emplace_back(nullptr); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10308 | } |
| 10309 | /// Stores reduction data. |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10310 | void push(Expr *Item, Expr *Private, Expr *LHS, Expr *RHS, Expr *ReductionOp, |
| 10311 | Expr *TaskgroupDescriptor) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10312 | Vars.emplace_back(Item); |
| 10313 | Privates.emplace_back(Private); |
| 10314 | LHSs.emplace_back(LHS); |
| 10315 | RHSs.emplace_back(RHS); |
| 10316 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10317 | TaskgroupDescriptors.emplace_back(TaskgroupDescriptor); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10318 | } |
| 10319 | }; |
| 10320 | } // namespace |
| 10321 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10322 | static bool checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10323 | ASTContext &Context, const OMPArraySectionExpr *OASE, bool &SingleElement, |
| 10324 | SmallVectorImpl<llvm::APSInt> &ArraySizes) { |
| 10325 | const Expr *Length = OASE->getLength(); |
| 10326 | if (Length == nullptr) { |
| 10327 | // For array sections of the form [1:] or [:], we would need to analyze |
| 10328 | // the lower bound... |
| 10329 | if (OASE->getColonLoc().isValid()) |
| 10330 | return false; |
| 10331 | |
| 10332 | // This is an array subscript which has implicit length 1! |
| 10333 | SingleElement = true; |
| 10334 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10335 | } else { |
| 10336 | llvm::APSInt ConstantLengthValue; |
| 10337 | if (!Length->EvaluateAsInt(ConstantLengthValue, Context)) |
| 10338 | return false; |
| 10339 | |
| 10340 | SingleElement = (ConstantLengthValue.getSExtValue() == 1); |
| 10341 | ArraySizes.push_back(ConstantLengthValue); |
| 10342 | } |
| 10343 | |
| 10344 | // Get the base of this array section and walk up from there. |
| 10345 | const Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 10346 | |
| 10347 | // We require length = 1 for all array sections except the right-most to |
| 10348 | // guarantee that the memory region is contiguous and has no holes in it. |
| 10349 | while (const auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) { |
| 10350 | Length = TempOASE->getLength(); |
| 10351 | if (Length == nullptr) { |
| 10352 | // For array sections of the form [1:] or [:], we would need to analyze |
| 10353 | // the lower bound... |
| 10354 | if (OASE->getColonLoc().isValid()) |
| 10355 | return false; |
| 10356 | |
| 10357 | // This is an array subscript which has implicit length 1! |
| 10358 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10359 | } else { |
| 10360 | llvm::APSInt ConstantLengthValue; |
| 10361 | if (!Length->EvaluateAsInt(ConstantLengthValue, Context) || |
| 10362 | ConstantLengthValue.getSExtValue() != 1) |
| 10363 | return false; |
| 10364 | |
| 10365 | ArraySizes.push_back(ConstantLengthValue); |
| 10366 | } |
| 10367 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 10368 | } |
| 10369 | |
| 10370 | // If we have a single element, we don't need to add the implicit lengths. |
| 10371 | if (!SingleElement) { |
| 10372 | while (const auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) { |
| 10373 | // Has implicit length 1! |
| 10374 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10375 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 10376 | } |
| 10377 | } |
| 10378 | |
| 10379 | // This array section can be privatized as a single value or as a constant |
| 10380 | // sized array. |
| 10381 | return true; |
| 10382 | } |
| 10383 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10384 | static bool actOnOMPReductionKindClause( |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10385 | Sema &S, DSAStackTy *Stack, OpenMPClauseKind ClauseKind, |
| 10386 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 10387 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 10388 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10389 | ArrayRef<Expr *> UnresolvedReductions, ReductionData &RD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10390 | DeclarationName DN = ReductionId.getName(); |
| 10391 | OverloadedOperatorKind OOK = DN.getCXXOverloadedOperator(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10392 | BinaryOperatorKind BOK = BO_Comma; |
| 10393 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10394 | ASTContext &Context = S.Context; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10395 | // OpenMP [2.14.3.6, reduction clause] |
| 10396 | // C |
| 10397 | // reduction-identifier is either an identifier or one of the following |
| 10398 | // operators: +, -, *, &, |, ^, && and || |
| 10399 | // C++ |
| 10400 | // reduction-identifier is either an id-expression or one of the following |
| 10401 | // operators: +, -, *, &, |, ^, && and || |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10402 | switch (OOK) { |
| 10403 | case OO_Plus: |
| 10404 | case OO_Minus: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10405 | BOK = BO_Add; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10406 | break; |
| 10407 | case OO_Star: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10408 | BOK = BO_Mul; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10409 | break; |
| 10410 | case OO_Amp: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10411 | BOK = BO_And; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10412 | break; |
| 10413 | case OO_Pipe: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10414 | BOK = BO_Or; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10415 | break; |
| 10416 | case OO_Caret: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10417 | BOK = BO_Xor; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10418 | break; |
| 10419 | case OO_AmpAmp: |
| 10420 | BOK = BO_LAnd; |
| 10421 | break; |
| 10422 | case OO_PipePipe: |
| 10423 | BOK = BO_LOr; |
| 10424 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10425 | case OO_New: |
| 10426 | case OO_Delete: |
| 10427 | case OO_Array_New: |
| 10428 | case OO_Array_Delete: |
| 10429 | case OO_Slash: |
| 10430 | case OO_Percent: |
| 10431 | case OO_Tilde: |
| 10432 | case OO_Exclaim: |
| 10433 | case OO_Equal: |
| 10434 | case OO_Less: |
| 10435 | case OO_Greater: |
| 10436 | case OO_LessEqual: |
| 10437 | case OO_GreaterEqual: |
| 10438 | case OO_PlusEqual: |
| 10439 | case OO_MinusEqual: |
| 10440 | case OO_StarEqual: |
| 10441 | case OO_SlashEqual: |
| 10442 | case OO_PercentEqual: |
| 10443 | case OO_CaretEqual: |
| 10444 | case OO_AmpEqual: |
| 10445 | case OO_PipeEqual: |
| 10446 | case OO_LessLess: |
| 10447 | case OO_GreaterGreater: |
| 10448 | case OO_LessLessEqual: |
| 10449 | case OO_GreaterGreaterEqual: |
| 10450 | case OO_EqualEqual: |
| 10451 | case OO_ExclaimEqual: |
| Richard Smith | d30b23d | 2017-12-01 02:13:10 +0000 | [diff] [blame] | 10452 | case OO_Spaceship: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10453 | case OO_PlusPlus: |
| 10454 | case OO_MinusMinus: |
| 10455 | case OO_Comma: |
| 10456 | case OO_ArrowStar: |
| 10457 | case OO_Arrow: |
| 10458 | case OO_Call: |
| 10459 | case OO_Subscript: |
| 10460 | case OO_Conditional: |
| Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 10461 | case OO_Coawait: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10462 | case NUM_OVERLOADED_OPERATORS: |
| 10463 | llvm_unreachable("Unexpected reduction identifier"); |
| 10464 | case OO_None: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10465 | if (IdentifierInfo *II = DN.getAsIdentifierInfo()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10466 | if (II->isStr("max")) |
| 10467 | BOK = BO_GT; |
| 10468 | else if (II->isStr("min")) |
| 10469 | BOK = BO_LT; |
| 10470 | } |
| 10471 | break; |
| 10472 | } |
| 10473 | SourceRange ReductionIdRange; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10474 | if (ReductionIdScopeSpec.isValid()) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10475 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 10476 | else |
| 10477 | ReductionIdRange.setBegin(ReductionId.getBeginLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10478 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10479 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10480 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 10481 | bool FirstIter = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10482 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10483 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10484 | // OpenMP [2.1, C/C++] |
| 10485 | // A list item is a variable or array section, subject to the restrictions |
| 10486 | // specified in Section 2.4 on page 42 and in each of the sections |
| 10487 | // describing clauses and directives for which a list appears. |
| 10488 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 10489 | // A variable that is part of another variable (as an array or |
| 10490 | // structure element) cannot appear in a private clause. |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10491 | if (!FirstIter && IR != ER) |
| 10492 | ++IR; |
| 10493 | FirstIter = false; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10494 | SourceLocation ELoc; |
| 10495 | SourceRange ERange; |
| 10496 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10497 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10498 | /*AllowArraySection=*/true); |
| 10499 | if (Res.second) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10500 | // Try to find 'declare reduction' corresponding construct before using |
| 10501 | // builtin/overloaded operators. |
| 10502 | QualType Type = Context.DependentTy; |
| 10503 | CXXCastPath BasePath; |
| 10504 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10505 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10506 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10507 | Expr *ReductionOp = nullptr; |
| 10508 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10509 | (DeclareReductionRef.isUnset() || |
| 10510 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10511 | ReductionOp = DeclareReductionRef.get(); |
| 10512 | // It will be analyzed later. |
| 10513 | RD.push(RefExpr, ReductionOp); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10514 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10515 | ValueDecl *D = Res.first; |
| 10516 | if (!D) |
| 10517 | continue; |
| 10518 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10519 | Expr *TaskgroupDescriptor = nullptr; |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10520 | QualType Type; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10521 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 10522 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10523 | if (ASE) { |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10524 | Type = ASE->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10525 | } else if (OASE) { |
| 10526 | QualType BaseType = |
| 10527 | OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 10528 | if (const auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10529 | Type = ATy->getElementType(); |
| 10530 | else |
| 10531 | Type = BaseType->getPointeeType(); |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10532 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10533 | } else { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10534 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10535 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10536 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10537 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10538 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 10539 | // A variable that appears in a private clause must not have an incomplete |
| 10540 | // type or a reference type. |
| Joel E. Denny | 3cabf73 | 2018-06-28 19:54:49 +0000 | [diff] [blame] | 10541 | if (S.RequireCompleteType(ELoc, D->getType(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10542 | diag::err_omp_reduction_incomplete_type)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10543 | continue; |
| 10544 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10545 | // A list item that appears in a reduction clause must not be |
| 10546 | // const-qualified. |
| 10547 | if (Type.getNonReferenceType().isConstant(Context)) { |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10548 | S.Diag(ELoc, diag::err_omp_const_reduction_list_item) << ERange; |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10549 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10550 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 10551 | VarDecl::DeclarationOnly; |
| 10552 | S.Diag(D->getLocation(), |
| 10553 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10554 | << D; |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10555 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10556 | continue; |
| 10557 | } |
| 10558 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 10559 | // If a list-item is a reference type then it must bind to the same object |
| 10560 | // for all threads of the team. |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10561 | if (!ASE && !OASE && VD) { |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10562 | VarDecl *VDDef = VD->getDefinition(); |
| David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 10563 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10564 | DSARefChecker Check(Stack); |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10565 | if (Check.Visit(VDDef->getInit())) { |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10566 | S.Diag(ELoc, diag::err_omp_reduction_ref_type_arg) |
| 10567 | << getOpenMPClauseName(ClauseKind) << ERange; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10568 | S.Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 10569 | continue; |
| 10570 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10571 | } |
| 10572 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10573 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10574 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 10575 | // in a Construct] |
| 10576 | // Variables with the predetermined data-sharing attributes may not be |
| 10577 | // listed in data-sharing attributes clauses, except for the cases |
| 10578 | // listed below. For these exceptions only, listing a predetermined |
| 10579 | // variable in a data-sharing attribute clause is allowed and overrides |
| 10580 | // the variable's predetermined data-sharing attributes. |
| 10581 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 10582 | // Any number of reduction clauses can be specified on the directive, |
| 10583 | // but a list item can appear only once in the reduction clauses for that |
| 10584 | // directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10585 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10586 | if (DVar.CKind == OMPC_reduction) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10587 | S.Diag(ELoc, diag::err_omp_once_referenced) |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10588 | << getOpenMPClauseName(ClauseKind); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10589 | if (DVar.RefExpr) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10590 | S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 10591 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10592 | } |
| 10593 | if (DVar.CKind != OMPC_unknown) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10594 | S.Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10595 | << getOpenMPClauseName(DVar.CKind) |
| 10596 | << getOpenMPClauseName(OMPC_reduction); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10597 | reportOriginalDsa(S, Stack, D, DVar); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10598 | continue; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10599 | } |
| 10600 | |
| 10601 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 10602 | // A list item that appears in a reduction clause of a worksharing |
| 10603 | // construct must be shared in the parallel regions to which any of the |
| 10604 | // worksharing regions arising from the worksharing construct bind. |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10605 | OpenMPDirectiveKind CurrDir = Stack->getCurrentDirective(); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10606 | if (isOpenMPWorksharingDirective(CurrDir) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10607 | !isOpenMPParallelDirective(CurrDir) && |
| 10608 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10609 | DVar = Stack->getImplicitDSA(D, true); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10610 | if (DVar.CKind != OMPC_shared) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10611 | S.Diag(ELoc, diag::err_omp_required_access) |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10612 | << getOpenMPClauseName(OMPC_reduction) |
| 10613 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10614 | reportOriginalDsa(S, Stack, D, DVar); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10615 | continue; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10616 | } |
| 10617 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10618 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10619 | // Try to find 'declare reduction' corresponding construct before using |
| 10620 | // builtin/overloaded operators. |
| 10621 | CXXCastPath BasePath; |
| 10622 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10623 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10624 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 10625 | if (DeclareReductionRef.isInvalid()) |
| 10626 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10627 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10628 | (DeclareReductionRef.isUnset() || |
| 10629 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10630 | RD.push(RefExpr, DeclareReductionRef.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10631 | continue; |
| 10632 | } |
| 10633 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 10634 | // Not allowed reduction identifier is found. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10635 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10636 | diag::err_omp_unknown_reduction_identifier) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10637 | << Type << ReductionIdRange; |
| 10638 | continue; |
| 10639 | } |
| 10640 | |
| 10641 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 10642 | // The type of a list item that appears in a reduction clause must be valid |
| 10643 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 10644 | // of the list item must be an allowed arithmetic data type: char, int, |
| 10645 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 10646 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 10647 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 10648 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 10649 | if (DeclareReductionRef.isUnset()) { |
| 10650 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 10651 | !(Type->isScalarType() || |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10652 | (S.getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 10653 | S.Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10654 | << getOpenMPClauseName(ClauseKind) << S.getLangOpts().CPlusPlus; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10655 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10656 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 10657 | VarDecl::DeclarationOnly; |
| 10658 | S.Diag(D->getLocation(), |
| 10659 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10660 | << D; |
| 10661 | } |
| 10662 | continue; |
| 10663 | } |
| 10664 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10665 | !S.getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10666 | S.Diag(ELoc, diag::err_omp_clause_floating_type_arg) |
| 10667 | << getOpenMPClauseName(ClauseKind); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10668 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10669 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 10670 | VarDecl::DeclarationOnly; |
| 10671 | S.Diag(D->getLocation(), |
| 10672 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10673 | << D; |
| 10674 | } |
| 10675 | continue; |
| 10676 | } |
| 10677 | } |
| 10678 | |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10679 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10680 | VarDecl *LHSVD = buildVarDecl(S, ELoc, Type, ".reduction.lhs", |
| 10681 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10682 | VarDecl *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(), |
| 10683 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10684 | QualType PrivateTy = Type; |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10685 | |
| 10686 | // Try if we can determine constant lengths for all array sections and avoid |
| 10687 | // the VLA. |
| 10688 | bool ConstantLengthOASE = false; |
| 10689 | if (OASE) { |
| 10690 | bool SingleElement; |
| 10691 | llvm::SmallVector<llvm::APSInt, 4> ArraySizes; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10692 | ConstantLengthOASE = checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10693 | Context, OASE, SingleElement, ArraySizes); |
| 10694 | |
| 10695 | // If we don't have a single element, we must emit a constant array type. |
| 10696 | if (ConstantLengthOASE && !SingleElement) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10697 | for (llvm::APSInt &Size : ArraySizes) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10698 | PrivateTy = Context.getConstantArrayType( |
| 10699 | PrivateTy, Size, ArrayType::Normal, /*IndexTypeQuals=*/0); |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10700 | } |
| 10701 | } |
| 10702 | |
| 10703 | if ((OASE && !ConstantLengthOASE) || |
| Jonas Hahnfeld | 96087f3 | 2017-11-02 13:30:42 +0000 | [diff] [blame] | 10704 | (!OASE && !ASE && |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10705 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 10706 | if (!Context.getTargetInfo().isVLASupported() && |
| 10707 | S.shouldDiagnoseTargetSupportFromOpenMP()) { |
| 10708 | S.Diag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; |
| 10709 | S.Diag(ELoc, diag::note_vla_unsupported); |
| 10710 | continue; |
| 10711 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10712 | // For arrays/array sections only: |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10713 | // Create pseudo array type for private copy. The size for this array will |
| 10714 | // be generated during codegen. |
| 10715 | // For array subscripts or single variables Private Ty is the same as Type |
| 10716 | // (type of the variable or single array element). |
| 10717 | PrivateTy = Context.getVariableArrayType( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10718 | Type, |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 10719 | new (Context) OpaqueValueExpr(ELoc, Context.getSizeType(), VK_RValue), |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10720 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10721 | } else if (!ASE && !OASE && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10722 | Context.getAsArrayType(D->getType().getNonReferenceType())) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10723 | PrivateTy = D->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10724 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10725 | // Private copy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10726 | VarDecl *PrivateVD = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 10727 | buildVarDecl(S, ELoc, PrivateTy, D->getName(), |
| 10728 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 10729 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10730 | // Add initializer for private variable. |
| 10731 | Expr *Init = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10732 | DeclRefExpr *LHSDRE = buildDeclRefExpr(S, LHSVD, Type, ELoc); |
| 10733 | DeclRefExpr *RHSDRE = buildDeclRefExpr(S, RHSVD, Type, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10734 | if (DeclareReductionRef.isUsable()) { |
| 10735 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 10736 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 10737 | if (DRD->getInitializer()) { |
| 10738 | Init = DRDRef; |
| 10739 | RHSVD->setInit(DRDRef); |
| 10740 | RHSVD->setInitStyle(VarDecl::CallInit); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10741 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10742 | } else { |
| 10743 | switch (BOK) { |
| 10744 | case BO_Add: |
| 10745 | case BO_Xor: |
| 10746 | case BO_Or: |
| 10747 | case BO_LOr: |
| 10748 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 10749 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10750 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10751 | break; |
| 10752 | case BO_Mul: |
| 10753 | case BO_LAnd: |
| 10754 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 10755 | // '*' and '&&' reduction ops - initializer is '1'. |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10756 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10757 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10758 | break; |
| 10759 | case BO_And: { |
| 10760 | // '&' reduction op - initializer is '~0'. |
| 10761 | QualType OrigType = Type; |
| 10762 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 10763 | Type = ComplexTy->getElementType(); |
| 10764 | if (Type->isRealFloatingType()) { |
| 10765 | llvm::APFloat InitValue = |
| 10766 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 10767 | /*isIEEE=*/true); |
| 10768 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 10769 | Type, ELoc); |
| 10770 | } else if (Type->isScalarType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10771 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10772 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 10773 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 10774 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 10775 | } |
| 10776 | if (Init && OrigType->isAnyComplexType()) { |
| 10777 | // Init = 0xFFFF + 0xFFFFi; |
| 10778 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10779 | Init = S.CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10780 | } |
| 10781 | Type = OrigType; |
| 10782 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10783 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10784 | case BO_LT: |
| 10785 | case BO_GT: { |
| 10786 | // 'min' reduction op - initializer is 'Largest representable number in |
| 10787 | // the reduction list item type'. |
| 10788 | // 'max' reduction op - initializer is 'Least representable number in |
| 10789 | // the reduction list item type'. |
| 10790 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 10791 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10792 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10793 | QualType IntTy = |
| 10794 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 10795 | llvm::APInt InitValue = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10796 | (BOK != BO_LT) ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 10797 | : llvm::APInt::getMinValue(Size) |
| 10798 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 10799 | : llvm::APInt::getMaxValue(Size); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10800 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 10801 | if (Type->isPointerType()) { |
| 10802 | // Cast to pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10803 | ExprResult CastExpr = S.BuildCStyleCastExpr( |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 10804 | ELoc, Context.getTrivialTypeSourceInfo(Type, ELoc), ELoc, Init); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10805 | if (CastExpr.isInvalid()) |
| 10806 | continue; |
| 10807 | Init = CastExpr.get(); |
| 10808 | } |
| 10809 | } else if (Type->isRealFloatingType()) { |
| 10810 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 10811 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 10812 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 10813 | Type, ELoc); |
| 10814 | } |
| 10815 | break; |
| 10816 | } |
| 10817 | case BO_PtrMemD: |
| 10818 | case BO_PtrMemI: |
| 10819 | case BO_MulAssign: |
| 10820 | case BO_Div: |
| 10821 | case BO_Rem: |
| 10822 | case BO_Sub: |
| 10823 | case BO_Shl: |
| 10824 | case BO_Shr: |
| 10825 | case BO_LE: |
| 10826 | case BO_GE: |
| 10827 | case BO_EQ: |
| 10828 | case BO_NE: |
| Richard Smith | c70f1d6 | 2017-12-14 15:16:18 +0000 | [diff] [blame] | 10829 | case BO_Cmp: |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10830 | case BO_AndAssign: |
| 10831 | case BO_XorAssign: |
| 10832 | case BO_OrAssign: |
| 10833 | case BO_Assign: |
| 10834 | case BO_AddAssign: |
| 10835 | case BO_SubAssign: |
| 10836 | case BO_DivAssign: |
| 10837 | case BO_RemAssign: |
| 10838 | case BO_ShlAssign: |
| 10839 | case BO_ShrAssign: |
| 10840 | case BO_Comma: |
| 10841 | llvm_unreachable("Unexpected reduction operation"); |
| 10842 | } |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10843 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10844 | if (Init && DeclareReductionRef.isUnset()) |
| 10845 | S.AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
| 10846 | else if (!Init) |
| 10847 | S.ActOnUninitializedDecl(RHSVD); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10848 | if (RHSVD->isInvalidDecl()) |
| 10849 | continue; |
| 10850 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10851 | S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible) |
| 10852 | << Type << ReductionIdRange; |
| 10853 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 10854 | VarDecl::DeclarationOnly; |
| 10855 | S.Diag(D->getLocation(), |
| 10856 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10857 | << D; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10858 | continue; |
| 10859 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10860 | // Store initializer for single element in private copy. Will be used during |
| 10861 | // codegen. |
| 10862 | PrivateVD->setInit(RHSVD->getInit()); |
| 10863 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10864 | DeclRefExpr *PrivateDRE = buildDeclRefExpr(S, PrivateVD, PrivateTy, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10865 | ExprResult ReductionOp; |
| 10866 | if (DeclareReductionRef.isUsable()) { |
| 10867 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 10868 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10869 | ExprResult LHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 10870 | ExprResult RHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10871 | if (!BasePath.empty()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10872 | LHS = S.DefaultLvalueConversion(LHS.get()); |
| 10873 | RHS = S.DefaultLvalueConversion(RHS.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10874 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 10875 | CK_UncheckedDerivedToBase, LHS.get(), |
| 10876 | &BasePath, LHS.get()->getValueKind()); |
| 10877 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 10878 | CK_UncheckedDerivedToBase, RHS.get(), |
| 10879 | &BasePath, RHS.get()->getValueKind()); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10880 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10881 | FunctionProtoType::ExtProtoInfo EPI; |
| 10882 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 10883 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 10884 | auto *OVE = new (Context) OpaqueValueExpr( |
| 10885 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10886 | S.DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10887 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 10888 | ReductionOp = new (Context) |
| 10889 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 10890 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10891 | ReductionOp = S.BuildBinOp( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10892 | Stack->getCurScope(), ReductionId.getBeginLoc(), BOK, LHSDRE, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10893 | if (ReductionOp.isUsable()) { |
| 10894 | if (BOK != BO_LT && BOK != BO_GT) { |
| 10895 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10896 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10897 | BO_Assign, LHSDRE, ReductionOp.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10898 | } else { |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 10899 | auto *ConditionalOp = new (Context) |
| 10900 | ConditionalOperator(ReductionOp.get(), ELoc, LHSDRE, ELoc, RHSDRE, |
| 10901 | Type, VK_LValue, OK_Ordinary); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10902 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10903 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10904 | BO_Assign, LHSDRE, ConditionalOp); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10905 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 10906 | if (ReductionOp.isUsable()) |
| 10907 | ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10908 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 10909 | if (!ReductionOp.isUsable()) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10910 | continue; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10911 | } |
| 10912 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10913 | // OpenMP [2.15.4.6, Restrictions, p.2] |
| 10914 | // A list item that appears in an in_reduction clause of a task construct |
| 10915 | // must appear in a task_reduction clause of a construct associated with a |
| 10916 | // taskgroup region that includes the participating task in its taskgroup |
| 10917 | // set. The construct associated with the innermost region that meets this |
| 10918 | // condition must specify the same reduction-identifier as the in_reduction |
| 10919 | // clause. |
| 10920 | if (ClauseKind == OMPC_in_reduction) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10921 | SourceRange ParentSR; |
| 10922 | BinaryOperatorKind ParentBOK; |
| 10923 | const Expr *ParentReductionOp; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10924 | Expr *ParentBOKTD, *ParentReductionOpTD; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 10925 | DSAStackTy::DSAVarData ParentBOKDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10926 | Stack->getTopMostTaskgroupReductionData(D, ParentSR, ParentBOK, |
| 10927 | ParentBOKTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 10928 | DSAStackTy::DSAVarData ParentReductionOpDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10929 | Stack->getTopMostTaskgroupReductionData( |
| 10930 | D, ParentSR, ParentReductionOp, ParentReductionOpTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 10931 | bool IsParentBOK = ParentBOKDSA.DKind != OMPD_unknown; |
| 10932 | bool IsParentReductionOp = ParentReductionOpDSA.DKind != OMPD_unknown; |
| 10933 | if (!IsParentBOK && !IsParentReductionOp) { |
| 10934 | S.Diag(ELoc, diag::err_omp_in_reduction_not_task_reduction); |
| 10935 | continue; |
| 10936 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10937 | if ((DeclareReductionRef.isUnset() && IsParentReductionOp) || |
| 10938 | (DeclareReductionRef.isUsable() && IsParentBOK) || BOK != ParentBOK || |
| 10939 | IsParentReductionOp) { |
| 10940 | bool EmitError = true; |
| 10941 | if (IsParentReductionOp && DeclareReductionRef.isUsable()) { |
| 10942 | llvm::FoldingSetNodeID RedId, ParentRedId; |
| 10943 | ParentReductionOp->Profile(ParentRedId, Context, /*Canonical=*/true); |
| 10944 | DeclareReductionRef.get()->Profile(RedId, Context, |
| 10945 | /*Canonical=*/true); |
| 10946 | EmitError = RedId != ParentRedId; |
| 10947 | } |
| 10948 | if (EmitError) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10949 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10950 | diag::err_omp_reduction_identifier_mismatch) |
| 10951 | << ReductionIdRange << RefExpr->getSourceRange(); |
| 10952 | S.Diag(ParentSR.getBegin(), |
| 10953 | diag::note_omp_previous_reduction_identifier) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 10954 | << ParentSR |
| 10955 | << (IsParentBOK ? ParentBOKDSA.RefExpr |
| 10956 | : ParentReductionOpDSA.RefExpr) |
| 10957 | ->getSourceRange(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10958 | continue; |
| 10959 | } |
| 10960 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10961 | TaskgroupDescriptor = IsParentBOK ? ParentBOKTD : ParentReductionOpTD; |
| 10962 | assert(TaskgroupDescriptor && "Taskgroup descriptor must be defined."); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 10963 | } |
| 10964 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10965 | DeclRefExpr *Ref = nullptr; |
| 10966 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10967 | if (!VD && !S.CurContext->isDependentContext()) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10968 | if (ASE || OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10969 | TransformExprToCaptures RebuildToCapture(S, D); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10970 | VarsExpr = |
| 10971 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 10972 | Ref = RebuildToCapture.getCapturedExpr(); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10973 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10974 | VarsExpr = Ref = buildCapture(S, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10975 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10976 | if (!S.isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10977 | RD.ExprCaptures.emplace_back(Ref->getDecl()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10978 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10979 | ExprResult RefRes = S.DefaultLvalueConversion(Ref); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10980 | if (!RefRes.isUsable()) |
| 10981 | continue; |
| 10982 | ExprResult PostUpdateRes = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10983 | S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 10984 | RefRes.get()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10985 | if (!PostUpdateRes.isUsable()) |
| 10986 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10987 | if (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
| 10988 | Stack->getCurrentDirective() == OMPD_taskgroup) { |
| 10989 | S.Diag(RefExpr->getExprLoc(), |
| 10990 | diag::err_omp_reduction_non_addressable_expression) |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 10991 | << RefExpr->getSourceRange(); |
| 10992 | continue; |
| 10993 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10994 | RD.ExprPostUpdates.emplace_back( |
| 10995 | S.IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10996 | } |
| 10997 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10998 | } |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10999 | // All reduction items are still marked as reduction (to do not increase |
| 11000 | // code base size). |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11001 | Stack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11002 | if (CurrDir == OMPD_taskgroup) { |
| 11003 | if (DeclareReductionRef.isUsable()) |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 11004 | Stack->addTaskgroupReductionData(D, ReductionIdRange, |
| 11005 | DeclareReductionRef.get()); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11006 | else |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 11007 | Stack->addTaskgroupReductionData(D, ReductionIdRange, BOK); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11008 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11009 | RD.push(VarsExpr, PrivateDRE, LHSDRE, RHSDRE, ReductionOp.get(), |
| 11010 | TaskgroupDescriptor); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11011 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11012 | return RD.Vars.empty(); |
| 11013 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11014 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11015 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 11016 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11017 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11018 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11019 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11020 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11021 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_reduction, VarList, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11022 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11023 | ReductionIdScopeSpec, ReductionId, |
| 11024 | UnresolvedReductions, RD)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11025 | return nullptr; |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 11026 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11027 | return OMPReductionClause::Create( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11028 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11029 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 11030 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 11031 | buildPreInits(Context, RD.ExprCaptures), |
| 11032 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11033 | } |
| 11034 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11035 | OMPClause *Sema::ActOnOpenMPTaskReductionClause( |
| 11036 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11037 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11038 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11039 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11040 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11041 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_task_reduction, VarList, |
| 11042 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11043 | ReductionIdScopeSpec, ReductionId, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11044 | UnresolvedReductions, RD)) |
| 11045 | return nullptr; |
| 11046 | |
| 11047 | return OMPTaskReductionClause::Create( |
| 11048 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11049 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 11050 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 11051 | buildPreInits(Context, RD.ExprCaptures), |
| 11052 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 11053 | } |
| 11054 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11055 | OMPClause *Sema::ActOnOpenMPInReductionClause( |
| 11056 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11057 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11058 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11059 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11060 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11061 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_in_reduction, VarList, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11062 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11063 | ReductionIdScopeSpec, ReductionId, |
| 11064 | UnresolvedReductions, RD)) |
| 11065 | return nullptr; |
| 11066 | |
| 11067 | return OMPInReductionClause::Create( |
| 11068 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11069 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11070 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, RD.TaskgroupDescriptors, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11071 | buildPreInits(Context, RD.ExprCaptures), |
| 11072 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 11073 | } |
| 11074 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11075 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 11076 | SourceLocation LinLoc) { |
| 11077 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 11078 | LinKind == OMPC_LINEAR_unknown) { |
| 11079 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 11080 | return true; |
| 11081 | } |
| 11082 | return false; |
| 11083 | } |
| 11084 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11085 | bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11086 | OpenMPLinearClauseKind LinKind, |
| 11087 | QualType Type) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11088 | const auto *VD = dyn_cast_or_null<VarDecl>(D); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11089 | // A variable must not have an incomplete type or a reference type. |
| 11090 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 11091 | return true; |
| 11092 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 11093 | !Type->isReferenceType()) { |
| 11094 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 11095 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 11096 | return true; |
| 11097 | } |
| 11098 | Type = Type.getNonReferenceType(); |
| 11099 | |
| 11100 | // A list item must not be const-qualified. |
| 11101 | if (Type.isConstant(Context)) { |
| 11102 | Diag(ELoc, diag::err_omp_const_variable) |
| 11103 | << getOpenMPClauseName(OMPC_linear); |
| 11104 | if (D) { |
| 11105 | bool IsDecl = |
| 11106 | !VD || |
| 11107 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 11108 | Diag(D->getLocation(), |
| 11109 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 11110 | << D; |
| 11111 | } |
| 11112 | return true; |
| 11113 | } |
| 11114 | |
| 11115 | // A list item must be of integral or pointer type. |
| 11116 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 11117 | const auto *Ty = Type.getTypePtrOrNull(); |
| 11118 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 11119 | !Ty->isPointerType())) { |
| 11120 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 11121 | if (D) { |
| 11122 | bool IsDecl = |
| 11123 | !VD || |
| 11124 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 11125 | Diag(D->getLocation(), |
| 11126 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 11127 | << D; |
| 11128 | } |
| 11129 | return true; |
| 11130 | } |
| 11131 | return false; |
| 11132 | } |
| 11133 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11134 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 11135 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 11136 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 11137 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11138 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11139 | SmallVector<Expr *, 8> Privates; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11140 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11141 | SmallVector<Decl *, 4> ExprCaptures; |
| 11142 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11143 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11144 | LinKind = OMPC_LINEAR_val; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11145 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11146 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11147 | SourceLocation ELoc; |
| 11148 | SourceRange ERange; |
| 11149 | Expr *SimpleRefExpr = RefExpr; |
| 11150 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 11151 | /*AllowArraySection=*/false); |
| 11152 | if (Res.second) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11153 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11154 | Vars.push_back(RefExpr); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11155 | Privates.push_back(nullptr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11156 | Inits.push_back(nullptr); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11157 | } |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11158 | ValueDecl *D = Res.first; |
| 11159 | if (!D) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11160 | continue; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11161 | |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11162 | QualType Type = D->getType(); |
| 11163 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11164 | |
| 11165 | // OpenMP [2.14.3.7, linear clause] |
| 11166 | // A list-item cannot appear in more than one linear clause. |
| 11167 | // A list-item that appears in a linear clause cannot appear in any |
| 11168 | // other data-sharing attribute clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11169 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11170 | if (DVar.RefExpr) { |
| 11171 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 11172 | << getOpenMPClauseName(OMPC_linear); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11173 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11174 | continue; |
| 11175 | } |
| 11176 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11177 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11178 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11179 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11180 | |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11181 | // Build private copy of original var. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11182 | VarDecl *Private = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 11183 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11184 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 11185 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11186 | DeclRefExpr *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11187 | // Build var to save initial value. |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11188 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11189 | Expr *InitExpr; |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11190 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 11191 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11192 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11193 | if (!isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11194 | ExprCaptures.push_back(Ref->getDecl()); |
| 11195 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 11196 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 11197 | if (!RefRes.isUsable()) |
| 11198 | continue; |
| 11199 | ExprResult PostUpdateRes = |
| 11200 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 11201 | SimpleRefExpr, RefRes.get()); |
| 11202 | if (!PostUpdateRes.isUsable()) |
| 11203 | continue; |
| 11204 | ExprPostUpdates.push_back( |
| 11205 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 11206 | } |
| 11207 | } |
| 11208 | } |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11209 | if (LinKind == OMPC_LINEAR_uval) |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11210 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11211 | else |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11212 | InitExpr = VD ? SimpleRefExpr : Ref; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11213 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11214 | /*DirectInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11215 | DeclRefExpr *InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11216 | |
| 11217 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 11218 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 11219 | ? RefExpr->IgnoreParens() |
| 11220 | : Ref); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11221 | Privates.push_back(PrivateRef); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11222 | Inits.push_back(InitRef); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11223 | } |
| 11224 | |
| 11225 | if (Vars.empty()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11226 | return nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11227 | |
| 11228 | Expr *StepExpr = Step; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11229 | Expr *CalcStepExpr = nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11230 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 11231 | !Step->isInstantiationDependent() && |
| 11232 | !Step->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11233 | SourceLocation StepLoc = Step->getBeginLoc(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 11234 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11235 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11236 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11237 | StepExpr = Val.get(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11238 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11239 | // Build var to save the step value. |
| 11240 | VarDecl *SaveVar = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 11241 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11242 | ExprResult SaveRef = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 11243 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11244 | ExprResult CalcStep = |
| 11245 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11246 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11247 | |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11248 | // Warn about zero linear step (it would be probably better specified as |
| 11249 | // making corresponding variables 'const'). |
| 11250 | llvm::APSInt Result; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11251 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 11252 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11253 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 11254 | << (Vars.size() > 1); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11255 | if (!IsConstant && CalcStep.isUsable()) { |
| 11256 | // Calculate the step beforehand instead of doing this on each iteration. |
| 11257 | // (This is not used if the number of iterations may be kfold-ed). |
| 11258 | CalcStepExpr = CalcStep.get(); |
| 11259 | } |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11260 | } |
| 11261 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11262 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 11263 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11264 | StepExpr, CalcStepExpr, |
| 11265 | buildPreInits(Context, ExprCaptures), |
| 11266 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11267 | } |
| 11268 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11269 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 11270 | Expr *NumIterations, Sema &SemaRef, |
| 11271 | Scope *S, DSAStackTy *Stack) { |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11272 | // Walk the vars and build update/final expressions for the CodeGen. |
| 11273 | SmallVector<Expr *, 8> Updates; |
| 11274 | SmallVector<Expr *, 8> Finals; |
| 11275 | Expr *Step = Clause.getStep(); |
| 11276 | Expr *CalcStep = Clause.getCalcStep(); |
| 11277 | // OpenMP [2.14.3.7, linear clause] |
| 11278 | // If linear-step is not specified it is assumed to be 1. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11279 | if (!Step) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11280 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11281 | else if (CalcStep) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11282 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 11283 | bool HasErrors = false; |
| 11284 | auto CurInit = Clause.inits().begin(); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11285 | auto CurPrivate = Clause.privates().begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11286 | OpenMPLinearClauseKind LinKind = Clause.getModifier(); |
| 11287 | for (Expr *RefExpr : Clause.varlists()) { |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11288 | SourceLocation ELoc; |
| 11289 | SourceRange ERange; |
| 11290 | Expr *SimpleRefExpr = RefExpr; |
| 11291 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 11292 | /*AllowArraySection=*/false); |
| 11293 | ValueDecl *D = Res.first; |
| 11294 | if (Res.second || !D) { |
| 11295 | Updates.push_back(nullptr); |
| 11296 | Finals.push_back(nullptr); |
| 11297 | HasErrors = true; |
| 11298 | continue; |
| 11299 | } |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11300 | auto &&Info = Stack->isLoopControlVariable(D); |
| Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 11301 | // OpenMP [2.15.11, distribute simd Construct] |
| 11302 | // A list item may not appear in a linear clause, unless it is the loop |
| 11303 | // iteration variable. |
| 11304 | if (isOpenMPDistributeDirective(Stack->getCurrentDirective()) && |
| 11305 | isOpenMPSimdDirective(Stack->getCurrentDirective()) && !Info.first) { |
| 11306 | SemaRef.Diag(ELoc, |
| 11307 | diag::err_omp_linear_distribute_var_non_loop_iteration); |
| 11308 | Updates.push_back(nullptr); |
| 11309 | Finals.push_back(nullptr); |
| 11310 | HasErrors = true; |
| 11311 | continue; |
| 11312 | } |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11313 | Expr *InitExpr = *CurInit; |
| 11314 | |
| 11315 | // Build privatized reference to the current linear var. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11316 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11317 | Expr *CapturedRef; |
| 11318 | if (LinKind == OMPC_LINEAR_uval) |
| 11319 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 11320 | else |
| 11321 | CapturedRef = |
| 11322 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 11323 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 11324 | /*RefersToCapture=*/true); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11325 | |
| 11326 | // Build update: Var = InitExpr + IV * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11327 | ExprResult Update; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11328 | if (!Info.first) |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11329 | Update = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11330 | buildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11331 | InitExpr, IV, Step, /* Subtract */ false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11332 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11333 | Update = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11334 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11335 | /*DiscardedValue=*/true); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11336 | |
| 11337 | // Build final: Var = InitExpr + NumIterations * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11338 | ExprResult Final; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11339 | if (!Info.first) |
| 11340 | Final = |
| 11341 | buildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 11342 | InitExpr, NumIterations, Step, /*Subtract=*/false); |
| 11343 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11344 | Final = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11345 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 11346 | /*DiscardedValue=*/true); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11347 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11348 | if (!Update.isUsable() || !Final.isUsable()) { |
| 11349 | Updates.push_back(nullptr); |
| 11350 | Finals.push_back(nullptr); |
| 11351 | HasErrors = true; |
| 11352 | } else { |
| 11353 | Updates.push_back(Update.get()); |
| 11354 | Finals.push_back(Final.get()); |
| 11355 | } |
| Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 11356 | ++CurInit; |
| 11357 | ++CurPrivate; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11358 | } |
| 11359 | Clause.setUpdates(Updates); |
| 11360 | Clause.setFinals(Finals); |
| 11361 | return HasErrors; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11362 | } |
| 11363 | |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11364 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 11365 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 11366 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11367 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11368 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11369 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 11370 | SourceLocation ELoc; |
| 11371 | SourceRange ERange; |
| 11372 | Expr *SimpleRefExpr = RefExpr; |
| 11373 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 11374 | /*AllowArraySection=*/false); |
| 11375 | if (Res.second) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11376 | // It will be analyzed later. |
| 11377 | Vars.push_back(RefExpr); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11378 | } |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11379 | ValueDecl *D = Res.first; |
| 11380 | if (!D) |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11381 | continue; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11382 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11383 | QualType QType = D->getType(); |
| 11384 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11385 | |
| 11386 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 11387 | // The type of list items appearing in the aligned clause must be |
| 11388 | // array, pointer, reference to array, or reference to pointer. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 11389 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11390 | const Type *Ty = QType.getTypePtrOrNull(); |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11391 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11392 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11393 | << QType << getLangOpts().CPlusPlus << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11394 | bool IsDecl = |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11395 | !VD || |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11396 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11397 | Diag(D->getLocation(), |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11398 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11399 | << D; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11400 | continue; |
| 11401 | } |
| 11402 | |
| 11403 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 11404 | // A list-item cannot appear in more than one aligned clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11405 | if (const Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 11406 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11407 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 11408 | << getOpenMPClauseName(OMPC_aligned); |
| 11409 | continue; |
| 11410 | } |
| 11411 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11412 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11413 | if (!VD && isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11414 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11415 | Vars.push_back(DefaultFunctionArrayConversion( |
| 11416 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 11417 | .get()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11418 | } |
| 11419 | |
| 11420 | // OpenMP [2.8.1, simd construct, Description] |
| 11421 | // The parameter of the aligned clause, alignment, must be a constant |
| 11422 | // positive integer expression. |
| 11423 | // If no optional parameter is specified, implementation-defined default |
| 11424 | // alignments for SIMD instructions on the target platforms are assumed. |
| 11425 | if (Alignment != nullptr) { |
| 11426 | ExprResult AlignResult = |
| 11427 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 11428 | if (AlignResult.isInvalid()) |
| 11429 | return nullptr; |
| 11430 | Alignment = AlignResult.get(); |
| 11431 | } |
| 11432 | if (Vars.empty()) |
| 11433 | return nullptr; |
| 11434 | |
| 11435 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 11436 | EndLoc, Vars, Alignment); |
| 11437 | } |
| 11438 | |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11439 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 11440 | SourceLocation StartLoc, |
| 11441 | SourceLocation LParenLoc, |
| 11442 | SourceLocation EndLoc) { |
| 11443 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11444 | SmallVector<Expr *, 8> SrcExprs; |
| 11445 | SmallVector<Expr *, 8> DstExprs; |
| 11446 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11447 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11448 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 11449 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11450 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11451 | Vars.push_back(RefExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11452 | SrcExprs.push_back(nullptr); |
| 11453 | DstExprs.push_back(nullptr); |
| 11454 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11455 | continue; |
| 11456 | } |
| 11457 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11458 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11459 | // OpenMP [2.1, C/C++] |
| 11460 | // A list item is a variable name. |
| 11461 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 11462 | // A list item that appears in a copyin clause must be threadprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11463 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11464 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 11465 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 11466 | << 0 << RefExpr->getSourceRange(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11467 | continue; |
| 11468 | } |
| 11469 | |
| 11470 | Decl *D = DE->getDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11471 | auto *VD = cast<VarDecl>(D); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11472 | |
| 11473 | QualType Type = VD->getType(); |
| 11474 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 11475 | // It will be analyzed later. |
| 11476 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11477 | SrcExprs.push_back(nullptr); |
| 11478 | DstExprs.push_back(nullptr); |
| 11479 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11480 | continue; |
| 11481 | } |
| 11482 | |
| 11483 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 11484 | // A list item that appears in a copyin clause must be threadprivate. |
| 11485 | if (!DSAStack->isThreadPrivate(VD)) { |
| 11486 | Diag(ELoc, diag::err_omp_required_access) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11487 | << getOpenMPClauseName(OMPC_copyin) |
| 11488 | << getOpenMPDirectiveName(OMPD_threadprivate); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11489 | continue; |
| 11490 | } |
| 11491 | |
| 11492 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 11493 | // A variable of class type (or array thereof) that appears in a |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 11494 | // copyin clause requires an accessible, unambiguous copy assignment |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11495 | // operator for the class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11496 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| 11497 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11498 | buildVarDecl(*this, DE->getBeginLoc(), ElemType.getUnqualifiedType(), |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 11499 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11500 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr( |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 11501 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11502 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11503 | buildVarDecl(*this, DE->getBeginLoc(), ElemType, ".copyin.dst", |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 11504 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11505 | DeclRefExpr *PseudoDstExpr = |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 11506 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11507 | // For arrays generate assignment operation for single element and replace |
| 11508 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11509 | ExprResult AssignmentOp = |
| 11510 | BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, PseudoDstExpr, |
| 11511 | PseudoSrcExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11512 | if (AssignmentOp.isInvalid()) |
| 11513 | continue; |
| 11514 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 11515 | /*DiscardedValue=*/true); |
| 11516 | if (AssignmentOp.isInvalid()) |
| 11517 | continue; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11518 | |
| 11519 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 11520 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11521 | SrcExprs.push_back(PseudoSrcExpr); |
| 11522 | DstExprs.push_back(PseudoDstExpr); |
| 11523 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11524 | } |
| 11525 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11526 | if (Vars.empty()) |
| 11527 | return nullptr; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11528 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 11529 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 11530 | SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 11531 | } |
| 11532 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11533 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 11534 | SourceLocation StartLoc, |
| 11535 | SourceLocation LParenLoc, |
| 11536 | SourceLocation EndLoc) { |
| 11537 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11538 | SmallVector<Expr *, 8> SrcExprs; |
| 11539 | SmallVector<Expr *, 8> DstExprs; |
| 11540 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11541 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11542 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 11543 | SourceLocation ELoc; |
| 11544 | SourceRange ERange; |
| 11545 | Expr *SimpleRefExpr = RefExpr; |
| 11546 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 11547 | /*AllowArraySection=*/false); |
| 11548 | if (Res.second) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11549 | // It will be analyzed later. |
| 11550 | Vars.push_back(RefExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11551 | SrcExprs.push_back(nullptr); |
| 11552 | DstExprs.push_back(nullptr); |
| 11553 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11554 | } |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11555 | ValueDecl *D = Res.first; |
| 11556 | if (!D) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11557 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11558 | |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11559 | QualType Type = D->getType(); |
| 11560 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11561 | |
| 11562 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 11563 | // A list item that appears in a copyprivate clause may not appear in a |
| 11564 | // private or firstprivate clause on the single construct. |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11565 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11566 | DSAStackTy::DSAVarData DVar = |
| 11567 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11568 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 11569 | DVar.RefExpr) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11570 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 11571 | << getOpenMPClauseName(DVar.CKind) |
| 11572 | << getOpenMPClauseName(OMPC_copyprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11573 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11574 | continue; |
| 11575 | } |
| 11576 | |
| 11577 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 11578 | // All list items that appear in a copyprivate clause must be either |
| 11579 | // threadprivate or private in the enclosing context. |
| 11580 | if (DVar.CKind == OMPC_unknown) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11581 | DVar = DSAStack->getImplicitDSA(D, false); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11582 | if (DVar.CKind == OMPC_shared) { |
| 11583 | Diag(ELoc, diag::err_omp_required_access) |
| 11584 | << getOpenMPClauseName(OMPC_copyprivate) |
| 11585 | << "threadprivate or private in the enclosing context"; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11586 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11587 | continue; |
| 11588 | } |
| 11589 | } |
| 11590 | } |
| 11591 | |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11592 | // Variably modified types are not supported. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 11593 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11594 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 11595 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 11596 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11597 | bool IsDecl = |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11598 | !VD || |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11599 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11600 | Diag(D->getLocation(), |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11601 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11602 | << D; |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 11603 | continue; |
| 11604 | } |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 11605 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11606 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 11607 | // A variable of class type (or array thereof) that appears in a |
| 11608 | // copyin clause requires an accessible, unambiguous copy assignment |
| 11609 | // operator for the class type. |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11610 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 11611 | .getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11612 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11613 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.src", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11614 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11615 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
| 11616 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11617 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.dst", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11618 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11619 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 11620 | ExprResult AssignmentOp = BuildBinOp( |
| 11621 | DSAStack->getCurScope(), ELoc, BO_Assign, PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11622 | if (AssignmentOp.isInvalid()) |
| 11623 | continue; |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11624 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11625 | /*DiscardedValue=*/true); |
| 11626 | if (AssignmentOp.isInvalid()) |
| 11627 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11628 | |
| 11629 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 11630 | // implicitly private. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11631 | assert(VD || isOpenMPCapturedDecl(D)); |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 11632 | Vars.push_back( |
| 11633 | VD ? RefExpr->IgnoreParens() |
| 11634 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11635 | SrcExprs.push_back(PseudoSrcExpr); |
| 11636 | DstExprs.push_back(PseudoDstExpr); |
| 11637 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11638 | } |
| 11639 | |
| 11640 | if (Vars.empty()) |
| 11641 | return nullptr; |
| 11642 | |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 11643 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11644 | Vars, SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 11645 | } |
| 11646 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 11647 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 11648 | SourceLocation StartLoc, |
| 11649 | SourceLocation LParenLoc, |
| 11650 | SourceLocation EndLoc) { |
| 11651 | if (VarList.empty()) |
| 11652 | return nullptr; |
| 11653 | |
| 11654 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 11655 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 11656 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11657 | OMPClause * |
| 11658 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 11659 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 11660 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 11661 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 11662 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11663 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 11664 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11665 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 11666 | return nullptr; |
| 11667 | } |
| 11668 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11669 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 11670 | DepKind == OMPC_DEPEND_sink)) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11671 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11672 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 11673 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 11674 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 11675 | << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11676 | return nullptr; |
| 11677 | } |
| 11678 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 11679 | DSAStackTy::OperatorOffsetTy OpsOffs; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11680 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 11681 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11682 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) { |
| 11683 | if (const Expr *OrderedCountExpr = |
| 11684 | DSAStack->getParentOrderedRegionParam().first) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11685 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 11686 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11687 | } |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11688 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11689 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11690 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 11691 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 11692 | // It will be analyzed later. |
| 11693 | Vars.push_back(RefExpr); |
| 11694 | continue; |
| 11695 | } |
| 11696 | |
| 11697 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11698 | Expr *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11699 | if (DepKind == OMPC_DEPEND_sink) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11700 | if (DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11701 | DepCounter >= TotalDepCount) { |
| 11702 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 11703 | continue; |
| 11704 | } |
| 11705 | ++DepCounter; |
| 11706 | // OpenMP [2.13.9, Summary] |
| 11707 | // depend(dependence-type : vec), where dependence-type is: |
| 11708 | // 'sink' and where vec is the iteration vector, which has the form: |
| 11709 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 11710 | // where n is the value specified by the ordered clause in the loop |
| 11711 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 11712 | // loop associated with the loop directive, and di is a constant |
| 11713 | // non-negative integer. |
| 11714 | if (CurContext->isDependentContext()) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11715 | // It will be analyzed later. |
| 11716 | Vars.push_back(RefExpr); |
| 11717 | continue; |
| 11718 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11719 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 11720 | OverloadedOperatorKind OOK = OO_None; |
| 11721 | SourceLocation OOLoc; |
| 11722 | Expr *LHS = SimpleExpr; |
| 11723 | Expr *RHS = nullptr; |
| 11724 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 11725 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 11726 | OOLoc = BO->getOperatorLoc(); |
| 11727 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 11728 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 11729 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 11730 | OOK = OCE->getOperator(); |
| 11731 | OOLoc = OCE->getOperatorLoc(); |
| 11732 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 11733 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 11734 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 11735 | OOK = MCE->getMethodDecl() |
| 11736 | ->getNameInfo() |
| 11737 | .getName() |
| 11738 | .getCXXOverloadedOperator(); |
| 11739 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 11740 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 11741 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11742 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11743 | SourceLocation ELoc; |
| 11744 | SourceRange ERange; |
| 11745 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 11746 | /*AllowArraySection=*/false); |
| 11747 | if (Res.second) { |
| 11748 | // It will be analyzed later. |
| 11749 | Vars.push_back(RefExpr); |
| 11750 | } |
| 11751 | ValueDecl *D = Res.first; |
| 11752 | if (!D) |
| 11753 | continue; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11754 | |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11755 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 11756 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 11757 | continue; |
| 11758 | } |
| 11759 | if (RHS) { |
| 11760 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 11761 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 11762 | if (RHSRes.isInvalid()) |
| 11763 | continue; |
| 11764 | } |
| 11765 | if (!CurContext->isDependentContext() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11766 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11767 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11768 | const ValueDecl *VD = |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11769 | DSAStack->getParentLoopControlVariable(DepCounter.getZExtValue()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11770 | if (VD) |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11771 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 11772 | << 1 << VD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11773 | else |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11774 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) << 0; |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11775 | continue; |
| 11776 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11777 | OpsOffs.emplace_back(RHS, OOK); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11778 | } else { |
| 11779 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 11780 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 11781 | (ASE && |
| 11782 | !ASE->getBase()->getType().getNonReferenceType()->isPointerType() && |
| 11783 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
| 11784 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 11785 | << RefExpr->getSourceRange(); |
| 11786 | continue; |
| 11787 | } |
| 11788 | bool Suppress = getDiagnostics().getSuppressAllDiagnostics(); |
| 11789 | getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 11790 | ExprResult Res = |
| 11791 | CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RefExpr->IgnoreParenImpCasts()); |
| 11792 | getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 11793 | if (!Res.isUsable() && !isa<OMPArraySectionExpr>(SimpleExpr)) { |
| 11794 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 11795 | << RefExpr->getSourceRange(); |
| 11796 | continue; |
| 11797 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11798 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11799 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 11800 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11801 | |
| 11802 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 11803 | TotalDepCount > VarList.size() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11804 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11805 | DSAStack->getParentLoopControlVariable(VarList.size() + 1)) { |
| 11806 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 11807 | << 1 << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 11808 | } |
| 11809 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 11810 | Vars.empty()) |
| 11811 | return nullptr; |
| 11812 | |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 11813 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 11814 | DepKind, DepLoc, ColonLoc, Vars, |
| 11815 | TotalDepCount.getZExtValue()); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 11816 | if ((DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) && |
| 11817 | DSAStack->isParentOrderedRegion()) |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 11818 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 11819 | return C; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 11820 | } |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 11821 | |
| 11822 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 11823 | SourceLocation LParenLoc, |
| 11824 | SourceLocation EndLoc) { |
| 11825 | Expr *ValExpr = Device; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 11826 | Stmt *HelperValStmt = nullptr; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 11827 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11828 | // OpenMP [2.9.1, Restrictions] |
| 11829 | // The device expression must evaluate to a non-negative integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11830 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11831 | /*StrictlyPositive=*/false)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11832 | return nullptr; |
| 11833 | |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 11834 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 11835 | OpenMPDirectiveKind CaptureRegion = |
| 11836 | getOpenMPCaptureRegionForClause(DKind, OMPC_device); |
| 11837 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 11838 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11839 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 11840 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11841 | HelperValStmt = buildPreInits(Context, Captures); |
| 11842 | } |
| 11843 | |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 11844 | return new (Context) OMPDeviceClause(ValExpr, HelperValStmt, CaptureRegion, |
| 11845 | StartLoc, LParenLoc, EndLoc); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 11846 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11847 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11848 | static bool checkTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 11849 | DSAStackTy *Stack, QualType QTy, |
| 11850 | bool FullCheck = true) { |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11851 | NamedDecl *ND; |
| 11852 | if (QTy->isIncompleteType(&ND)) { |
| 11853 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 11854 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11855 | } |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 11856 | if (FullCheck && !SemaRef.CurContext->isDependentContext() && |
| 11857 | !QTy.isTrivialType(SemaRef.Context)) |
| 11858 | SemaRef.Diag(SL, diag::warn_omp_non_trivial_type_mapped) << QTy << SR; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11859 | return true; |
| 11860 | } |
| 11861 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11862 | /// Return true if it can be proven that the provided array expression |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11863 | /// (array section or array subscript) does NOT specify the whole size of the |
| 11864 | /// array whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11865 | static bool checkArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11866 | const Expr *E, |
| 11867 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11868 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11869 | |
| 11870 | // If this is an array subscript, it refers to the whole size if the size of |
| 11871 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 11872 | // format of an array subscript if no colon is used. |
| 11873 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11874 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11875 | return ATy->getSize().getSExtValue() != 1; |
| 11876 | // Size can't be evaluated statically. |
| 11877 | return false; |
| 11878 | } |
| 11879 | |
| 11880 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11881 | const Expr *LowerBound = OASE->getLowerBound(); |
| 11882 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11883 | |
| 11884 | // 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] | 11885 | // covering the whole dimension. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11886 | if (LowerBound) { |
| 11887 | llvm::APSInt ConstLowerBound; |
| 11888 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 11889 | return false; // Can't get the integer value as a constant. |
| 11890 | if (ConstLowerBound.getSExtValue()) |
| 11891 | return true; |
| 11892 | } |
| 11893 | |
| 11894 | // If we don't have a length we covering the whole dimension. |
| 11895 | if (!Length) |
| 11896 | return false; |
| 11897 | |
| 11898 | // If the base is a pointer, we don't have a way to get the size of the |
| 11899 | // pointee. |
| 11900 | if (BaseQTy->isPointerType()) |
| 11901 | return false; |
| 11902 | |
| 11903 | // We can only check if the length is the same as the size of the dimension |
| 11904 | // if we have a constant array. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11905 | const auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11906 | if (!CATy) |
| 11907 | return false; |
| 11908 | |
| 11909 | llvm::APSInt ConstLength; |
| 11910 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 11911 | return false; // Can't get the integer value as a constant. |
| 11912 | |
| 11913 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 11914 | } |
| 11915 | |
| 11916 | // Return true if it can be proven that the provided array expression (array |
| 11917 | // section or array subscript) does NOT specify a single element of the array |
| 11918 | // whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11919 | static bool checkArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11920 | const Expr *E, |
| 11921 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11922 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11923 | |
| 11924 | // An array subscript always refer to a single element. Also, an array section |
| 11925 | // assumes the format of an array subscript if no colon is used. |
| 11926 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 11927 | return false; |
| 11928 | |
| 11929 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11930 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11931 | |
| 11932 | // If we don't have a length we have to check if the array has unitary size |
| 11933 | // for this dimension. Also, we should always expect a length if the base type |
| 11934 | // is pointer. |
| 11935 | if (!Length) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11936 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11937 | return ATy->getSize().getSExtValue() != 1; |
| 11938 | // We cannot assume anything. |
| 11939 | return false; |
| 11940 | } |
| 11941 | |
| 11942 | // Check if the length evaluates to 1. |
| 11943 | llvm::APSInt ConstLength; |
| 11944 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 11945 | return false; // Can't get the integer value as a constant. |
| 11946 | |
| 11947 | return ConstLength.getSExtValue() != 1; |
| 11948 | } |
| 11949 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11950 | // Return the expression of the base of the mappable expression or null if it |
| 11951 | // cannot be determined and do all the necessary checks to see if the expression |
| 11952 | // 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] | 11953 | // components of the expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11954 | static const Expr *checkMapClauseExpressionBase( |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11955 | Sema &SemaRef, Expr *E, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11956 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 11957 | OpenMPClauseKind CKind, bool NoDiagnose) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11958 | SourceLocation ELoc = E->getExprLoc(); |
| 11959 | SourceRange ERange = E->getSourceRange(); |
| 11960 | |
| 11961 | // The base of elements of list in a map clause have to be either: |
| 11962 | // - a reference to variable or field. |
| 11963 | // - a member expression. |
| 11964 | // - an array expression. |
| 11965 | // |
| 11966 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 11967 | // reference to 'r'. |
| 11968 | // |
| 11969 | // If we have: |
| 11970 | // |
| 11971 | // struct SS { |
| 11972 | // Bla S; |
| 11973 | // foo() { |
| 11974 | // #pragma omp target map (S.Arr[:12]); |
| 11975 | // } |
| 11976 | // } |
| 11977 | // |
| 11978 | // We want to retrieve the member expression 'this->S'; |
| 11979 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11980 | const Expr *RelevantExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11981 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11982 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 11983 | // If a list item is an array section, it must specify contiguous storage. |
| 11984 | // |
| 11985 | // For this restriction it is sufficient that we make sure only references |
| 11986 | // to variables or fields and array expressions, and that no array sections |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11987 | // exist except in the rightmost expression (unless they cover the whole |
| 11988 | // dimension of the array). E.g. these would be invalid: |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11989 | // |
| 11990 | // r.ArrS[3:5].Arr[6:7] |
| 11991 | // |
| 11992 | // r.ArrS[3:5].x |
| 11993 | // |
| 11994 | // but these would be valid: |
| 11995 | // r.ArrS[3].Arr[6:7] |
| 11996 | // |
| 11997 | // r.ArrS[3].x |
| 11998 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 11999 | bool AllowUnitySizeArraySection = true; |
| 12000 | bool AllowWholeSizeArraySection = true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12001 | |
| Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 12002 | while (!RelevantExpr) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12003 | E = E->IgnoreParenImpCasts(); |
| 12004 | |
| 12005 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 12006 | if (!isa<VarDecl>(CurE->getDecl())) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12007 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12008 | |
| 12009 | RelevantExpr = CurE; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12010 | |
| 12011 | // If we got a reference to a declaration, we should not expect any array |
| 12012 | // section before that. |
| 12013 | AllowUnitySizeArraySection = false; |
| 12014 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12015 | |
| 12016 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12017 | CurComponents.emplace_back(CurE, CurE->getDecl()); |
| 12018 | } else if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12019 | Expr *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12020 | |
| 12021 | if (isa<CXXThisExpr>(BaseE)) |
| 12022 | // We found a base expression: this->Val. |
| 12023 | RelevantExpr = CurE; |
| 12024 | else |
| 12025 | E = BaseE; |
| 12026 | |
| 12027 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12028 | if (!NoDiagnose) { |
| 12029 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 12030 | << CurE->getSourceRange(); |
| 12031 | return nullptr; |
| 12032 | } |
| 12033 | if (RelevantExpr) |
| 12034 | return nullptr; |
| 12035 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12036 | } |
| 12037 | |
| 12038 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 12039 | |
| 12040 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 12041 | // A bit-field cannot appear in a map clause. |
| 12042 | // |
| 12043 | if (FD->isBitField()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12044 | if (!NoDiagnose) { |
| 12045 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 12046 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
| 12047 | return nullptr; |
| 12048 | } |
| 12049 | if (RelevantExpr) |
| 12050 | return nullptr; |
| 12051 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12052 | } |
| 12053 | |
| 12054 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12055 | // If the type of a list item is a reference to a type T then the type |
| 12056 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12057 | QualType CurType = BaseE->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12058 | |
| 12059 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 12060 | // A list item cannot be a variable that is a member of a structure with |
| 12061 | // a union type. |
| 12062 | // |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12063 | if (CurType->isUnionType()) { |
| 12064 | if (!NoDiagnose) { |
| 12065 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 12066 | << CurE->getSourceRange(); |
| 12067 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12068 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12069 | continue; |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12070 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12071 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12072 | // If we got a member expression, we should not expect any array section |
| 12073 | // before that: |
| 12074 | // |
| 12075 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 12076 | // If a list item is an element of a structure, only the rightmost symbol |
| 12077 | // of the variable reference can be an array section. |
| 12078 | // |
| 12079 | AllowUnitySizeArraySection = false; |
| 12080 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12081 | |
| 12082 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12083 | CurComponents.emplace_back(CurE, FD); |
| 12084 | } else if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12085 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 12086 | |
| 12087 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12088 | if (!NoDiagnose) { |
| 12089 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 12090 | << 0 << CurE->getSourceRange(); |
| 12091 | return nullptr; |
| 12092 | } |
| 12093 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12094 | } |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12095 | |
| 12096 | // If we got an array subscript that express the whole dimension we |
| 12097 | // can have any array expressions before. If it only expressing part of |
| 12098 | // the dimension, we can only have unitary-size array expressions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12099 | if (checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12100 | E->getType())) |
| 12101 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12102 | |
| 12103 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12104 | CurComponents.emplace_back(CurE, nullptr); |
| 12105 | } else if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12106 | assert(!NoDiagnose && "Array sections cannot be implicitly mapped."); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12107 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 12108 | |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12109 | QualType CurType = |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12110 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 12111 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12112 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12113 | // If the type of a list item is a reference to a type T then the type |
| 12114 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12115 | if (CurType->isReferenceType()) |
| 12116 | CurType = CurType->getPointeeType(); |
| 12117 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12118 | bool IsPointer = CurType->isAnyPointerType(); |
| 12119 | |
| 12120 | if (!IsPointer && !CurType->isArrayType()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12121 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 12122 | << 0 << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12123 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12124 | } |
| 12125 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12126 | bool NotWhole = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12127 | checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12128 | bool NotUnity = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12129 | checkArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12130 | |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 12131 | if (AllowWholeSizeArraySection) { |
| 12132 | // Any array section is currently allowed. Allowing a whole size array |
| 12133 | // section implies allowing a unity array section as well. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12134 | // |
| 12135 | // If this array section refers to the whole dimension we can still |
| 12136 | // accept other array sections before this one, except if the base is a |
| 12137 | // pointer. Otherwise, only unitary sections are accepted. |
| 12138 | if (NotWhole || IsPointer) |
| 12139 | AllowWholeSizeArraySection = false; |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 12140 | } else if (AllowUnitySizeArraySection && NotUnity) { |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12141 | // A unity or whole array section is not allowed and that is not |
| 12142 | // compatible with the properties of the current array section. |
| 12143 | SemaRef.Diag( |
| 12144 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 12145 | << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12146 | return nullptr; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12147 | } |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12148 | |
| 12149 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12150 | CurComponents.emplace_back(CurE, nullptr); |
| 12151 | } else { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12152 | if (!NoDiagnose) { |
| 12153 | // If nothing else worked, this is not a valid map clause expression. |
| 12154 | SemaRef.Diag( |
| 12155 | ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 12156 | << ERange; |
| 12157 | } |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12158 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12159 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12160 | } |
| 12161 | |
| 12162 | return RelevantExpr; |
| 12163 | } |
| 12164 | |
| 12165 | // Return true if expression E associated with value VD has conflicts with other |
| 12166 | // map information. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12167 | static bool checkMapConflicts( |
| 12168 | Sema &SemaRef, DSAStackTy *DSAS, const ValueDecl *VD, const Expr *E, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12169 | bool CurrentRegionOnly, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12170 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 12171 | OpenMPClauseKind CKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12172 | assert(VD && E); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12173 | SourceLocation ELoc = E->getExprLoc(); |
| 12174 | SourceRange ERange = E->getSourceRange(); |
| 12175 | |
| 12176 | // In order to easily check the conflicts we need to match each component of |
| 12177 | // the expression under test with the components of the expressions that are |
| 12178 | // already in the stack. |
| 12179 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12180 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12181 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12182 | "Map clause expression with unexpected base!"); |
| 12183 | |
| 12184 | // Variables to help detecting enclosing problems in data environment nests. |
| 12185 | bool IsEnclosedByDataEnvironmentExpr = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12186 | const Expr *EnclosingExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12187 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12188 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 12189 | VD, CurrentRegionOnly, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12190 | [&IsEnclosedByDataEnvironmentExpr, &SemaRef, VD, CurrentRegionOnly, ELoc, |
| 12191 | ERange, CKind, &EnclosingExpr, |
| 12192 | CurComponents](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 12193 | StackComponents, |
| 12194 | OpenMPClauseKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12195 | assert(!StackComponents.empty() && |
| 12196 | "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12197 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12198 | "Map clause expression with unexpected base!"); |
| Fangrui Song | 16fe49a | 2018-04-18 19:32:01 +0000 | [diff] [blame] | 12199 | (void)VD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12200 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12201 | // The whole expression in the stack. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12202 | const Expr *RE = StackComponents.front().getAssociatedExpression(); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12203 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12204 | // Expressions must start from the same base. Here we detect at which |
| 12205 | // point both expressions diverge from each other and see if we can |
| 12206 | // detect if the memory referred to both expressions is contiguous and |
| 12207 | // do not overlap. |
| 12208 | auto CI = CurComponents.rbegin(); |
| 12209 | auto CE = CurComponents.rend(); |
| 12210 | auto SI = StackComponents.rbegin(); |
| 12211 | auto SE = StackComponents.rend(); |
| 12212 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 12213 | |
| 12214 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 12215 | // At most one list item can be an array item derived from a given |
| 12216 | // variable in map clauses of the same construct. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12217 | if (CurrentRegionOnly && |
| 12218 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 12219 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 12220 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 12221 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 12222 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12223 | diag::err_omp_multiple_array_items_in_map_clause) |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12224 | << CI->getAssociatedExpression()->getSourceRange(); |
| 12225 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 12226 | diag::note_used_here) |
| 12227 | << SI->getAssociatedExpression()->getSourceRange(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12228 | return true; |
| 12229 | } |
| 12230 | |
| 12231 | // Do both expressions have the same kind? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12232 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 12233 | SI->getAssociatedExpression()->getStmtClass()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12234 | break; |
| 12235 | |
| 12236 | // Are we dealing with different variables/fields? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12237 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12238 | break; |
| 12239 | } |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12240 | // Check if the extra components of the expressions in the enclosing |
| 12241 | // data environment are redundant for the current base declaration. |
| 12242 | // If they are, the maps completely overlap, which is legal. |
| 12243 | for (; SI != SE; ++SI) { |
| 12244 | QualType Type; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12245 | if (const auto *ASE = |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12246 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12247 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12248 | } else if (const auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12249 | SI->getAssociatedExpression())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12250 | const Expr *E = OASE->getBase()->IgnoreParenImpCasts(); |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12251 | Type = |
| 12252 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 12253 | } |
| 12254 | if (Type.isNull() || Type->isAnyPointerType() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12255 | checkArrayExpressionDoesNotReferToWholeSize( |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12256 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 12257 | break; |
| 12258 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12259 | |
| 12260 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 12261 | // List items of map clauses in the same construct must not share |
| 12262 | // original storage. |
| 12263 | // |
| 12264 | // If the expressions are exactly the same or one is a subset of the |
| 12265 | // other, it means they are sharing storage. |
| 12266 | if (CI == CE && SI == SE) { |
| 12267 | if (CurrentRegionOnly) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12268 | if (CKind == OMPC_map) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12269 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12270 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12271 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12272 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 12273 | << ERange; |
| 12274 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12275 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12276 | << RE->getSourceRange(); |
| 12277 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12278 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12279 | // If we find the same expression in the enclosing data environment, |
| 12280 | // that is legal. |
| 12281 | IsEnclosedByDataEnvironmentExpr = true; |
| 12282 | return false; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12283 | } |
| 12284 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12285 | QualType DerivedType = |
| 12286 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 12287 | SourceLocation DerivedLoc = |
| 12288 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12289 | |
| 12290 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12291 | // If the type of a list item is a reference to a type T then the type |
| 12292 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12293 | DerivedType = DerivedType.getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12294 | |
| 12295 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 12296 | // A variable for which the type is pointer and an array section |
| 12297 | // derived from that variable must not appear as list items of map |
| 12298 | // clauses of the same construct. |
| 12299 | // |
| 12300 | // Also, cover one of the cases in: |
| 12301 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 12302 | // If any part of the original storage of a list item has corresponding |
| 12303 | // storage in the device data environment, all of the original storage |
| 12304 | // must have corresponding storage in the device data environment. |
| 12305 | // |
| 12306 | if (DerivedType->isAnyPointerType()) { |
| 12307 | if (CI == CE || SI == SE) { |
| 12308 | SemaRef.Diag( |
| 12309 | DerivedLoc, |
| 12310 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 12311 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12312 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12313 | << RE->getSourceRange(); |
| 12314 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12315 | } |
| 12316 | if (CI->getAssociatedExpression()->getStmtClass() != |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12317 | SI->getAssociatedExpression()->getStmtClass() || |
| 12318 | CI->getAssociatedDeclaration()->getCanonicalDecl() == |
| 12319 | SI->getAssociatedDeclaration()->getCanonicalDecl()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12320 | assert(CI != CE && SI != SE); |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12321 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_dereferenced) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12322 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12323 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12324 | << RE->getSourceRange(); |
| 12325 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12326 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12327 | } |
| 12328 | |
| 12329 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 12330 | // List items of map clauses in the same construct must not share |
| 12331 | // original storage. |
| 12332 | // |
| 12333 | // An expression is a subset of the other. |
| 12334 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12335 | if (CKind == OMPC_map) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12336 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12337 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12338 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12339 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 12340 | << ERange; |
| 12341 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12342 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12343 | << RE->getSourceRange(); |
| 12344 | return true; |
| 12345 | } |
| 12346 | |
| 12347 | // The current expression uses the same base as other expression in the |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12348 | // data environment but does not contain it completely. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12349 | if (!CurrentRegionOnly && SI != SE) |
| 12350 | EnclosingExpr = RE; |
| 12351 | |
| 12352 | // The current expression is a subset of the expression in the data |
| 12353 | // environment. |
| 12354 | IsEnclosedByDataEnvironmentExpr |= |
| 12355 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 12356 | |
| 12357 | return false; |
| 12358 | }); |
| 12359 | |
| 12360 | if (CurrentRegionOnly) |
| 12361 | return FoundError; |
| 12362 | |
| 12363 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 12364 | // If any part of the original storage of a list item has corresponding |
| 12365 | // storage in the device data environment, all of the original storage must |
| 12366 | // have corresponding storage in the device data environment. |
| 12367 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 12368 | // If a list item is an element of a structure, and a different element of |
| 12369 | // the structure has a corresponding list item in the device data environment |
| 12370 | // prior to a task encountering the construct associated with the map clause, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12371 | // 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] | 12372 | // data environment prior to the task encountering the construct. |
| 12373 | // |
| 12374 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 12375 | SemaRef.Diag(ELoc, |
| 12376 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 12377 | << ERange; |
| 12378 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 12379 | << EnclosingExpr->getSourceRange(); |
| 12380 | return true; |
| 12381 | } |
| 12382 | |
| 12383 | return FoundError; |
| 12384 | } |
| 12385 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12386 | namespace { |
| 12387 | // Utility struct that gathers all the related lists associated with a mappable |
| 12388 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12389 | struct MappableVarListInfo { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12390 | // The list of expressions. |
| 12391 | ArrayRef<Expr *> VarList; |
| 12392 | // The list of processed expressions. |
| 12393 | SmallVector<Expr *, 16> ProcessedVarList; |
| 12394 | // The mappble components for each expression. |
| 12395 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 12396 | // The base declaration of the variable. |
| 12397 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 12398 | |
| 12399 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 12400 | // We have a list of components and base declarations for each entry in the |
| 12401 | // variable list. |
| 12402 | VarComponents.reserve(VarList.size()); |
| 12403 | VarBaseDeclarations.reserve(VarList.size()); |
| 12404 | } |
| 12405 | }; |
| 12406 | } |
| 12407 | |
| 12408 | // Check the validity of the provided variable list for the provided clause kind |
| 12409 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 12410 | // components and variables are extracted and used to fill \a Vars, |
| 12411 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 12412 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 12413 | static void |
| 12414 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 12415 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 12416 | SourceLocation StartLoc, |
| 12417 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 12418 | bool IsMapTypeImplicit = false) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12419 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 12420 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12421 | "Unexpected clause kind with mappable expressions!"); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12422 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12423 | // Keep track of the mappable components and base declarations in this clause. |
| 12424 | // Each entry in the list is going to have a list of components associated. We |
| 12425 | // record each set of the components so that we can build the clause later on. |
| 12426 | // In the end we should have the same amount of declarations and component |
| 12427 | // lists. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12428 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12429 | for (Expr *RE : MVLI.VarList) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12430 | assert(RE && "Null expr in omp to/from/map clause"); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12431 | SourceLocation ELoc = RE->getExprLoc(); |
| 12432 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12433 | const Expr *VE = RE->IgnoreParenLValueCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12434 | |
| 12435 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 12436 | VE->isInstantiationDependent() || |
| 12437 | VE->containsUnexpandedParameterPack()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12438 | // We can only analyze this information once the missing information is |
| 12439 | // resolved. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12440 | MVLI.ProcessedVarList.push_back(RE); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12441 | continue; |
| 12442 | } |
| 12443 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12444 | Expr *SimpleExpr = RE->IgnoreParenCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12445 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12446 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12447 | SemaRef.Diag(ELoc, |
| 12448 | diag::err_omp_expected_named_var_member_or_array_expression) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12449 | << RE->getSourceRange(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12450 | continue; |
| 12451 | } |
| 12452 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12453 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 12454 | ValueDecl *CurDeclaration = nullptr; |
| 12455 | |
| 12456 | // Obtain the array or member expression bases if required. Also, fill the |
| 12457 | // components array with all the components identified in the process. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12458 | const Expr *BE = checkMapClauseExpressionBase( |
| 12459 | SemaRef, SimpleExpr, CurComponents, CKind, /*NoDiagnose=*/false); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12460 | if (!BE) |
| 12461 | continue; |
| 12462 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12463 | assert(!CurComponents.empty() && |
| 12464 | "Invalid mappable expression information."); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12465 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12466 | // For the following checks, we rely on the base declaration which is |
| 12467 | // expected to be associated with the last component. The declaration is |
| 12468 | // expected to be a variable or a field (if 'this' is being mapped). |
| 12469 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 12470 | assert(CurDeclaration && "Null decl on map clause."); |
| 12471 | assert( |
| 12472 | CurDeclaration->isCanonicalDecl() && |
| 12473 | "Expecting components to have associated only canonical declarations."); |
| 12474 | |
| 12475 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12476 | const auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12477 | |
| 12478 | assert((VD || FD) && "Only variables or fields are expected here!"); |
| NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 12479 | (void)FD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12480 | |
| 12481 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12482 | // threadprivate variables cannot appear in a map clause. |
| 12483 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 12484 | // threadprivate variables cannot appear in a from clause. |
| 12485 | if (VD && DSAS->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12486 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12487 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 12488 | << getOpenMPClauseName(CKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12489 | reportOriginalDsa(SemaRef, DSAS, VD, DVar); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12490 | continue; |
| 12491 | } |
| 12492 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12493 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 12494 | // A list item cannot appear in both a map clause and a data-sharing |
| 12495 | // attribute clause on the same construct. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12496 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12497 | // Check conflicts with other map clause expressions. We check the conflicts |
| 12498 | // with the current construct separately from the enclosing data |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12499 | // environment, because the restrictions are different. We only have to |
| 12500 | // check conflicts across regions for the map clauses. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12501 | if (checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12502 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12503 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12504 | if (CKind == OMPC_map && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12505 | checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12506 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12507 | break; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12508 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12509 | // OpenMP 4.5 [2.10.5, target update Construct] |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12510 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12511 | // If the type of a list item is a reference to a type T then the type will |
| 12512 | // be considered to be T for all purposes of this clause. |
| Alexey Bataev | 354df2e | 2018-05-02 18:44:10 +0000 | [diff] [blame] | 12513 | auto I = llvm::find_if( |
| 12514 | CurComponents, |
| 12515 | [](const OMPClauseMappableExprCommon::MappableComponent &MC) { |
| 12516 | return MC.getAssociatedDeclaration(); |
| 12517 | }); |
| 12518 | assert(I != CurComponents.end() && "Null decl on map clause."); |
| 12519 | QualType Type = |
| 12520 | I->getAssociatedDeclaration()->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12521 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12522 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 12523 | // 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] | 12524 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12525 | // A list item must have a mappable type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12526 | if (!checkTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12527 | DSAS, Type)) |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12528 | continue; |
| 12529 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12530 | if (CKind == OMPC_map) { |
| 12531 | // target enter data |
| 12532 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 12533 | // A map-type must be specified in all map clauses and must be either |
| 12534 | // to or alloc. |
| 12535 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 12536 | if (DKind == OMPD_target_enter_data && |
| 12537 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 12538 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 12539 | << (IsMapTypeImplicit ? 1 : 0) |
| 12540 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 12541 | << getOpenMPDirectiveName(DKind); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12542 | continue; |
| 12543 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12544 | |
| 12545 | // target exit_data |
| 12546 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 12547 | // A map-type must be specified in all map clauses and must be either |
| 12548 | // from, release, or delete. |
| 12549 | if (DKind == OMPD_target_exit_data && |
| 12550 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 12551 | MapType == OMPC_MAP_delete)) { |
| 12552 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 12553 | << (IsMapTypeImplicit ? 1 : 0) |
| 12554 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 12555 | << getOpenMPDirectiveName(DKind); |
| 12556 | continue; |
| 12557 | } |
| 12558 | |
| 12559 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 12560 | // A list item cannot appear in both a map clause and a data-sharing |
| 12561 | // attribute clause on the same construct |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12562 | if (VD && isOpenMPTargetExecutionDirective(DKind)) { |
| 12563 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12564 | if (isOpenMPPrivate(DVar.CKind)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12565 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12566 | << getOpenMPClauseName(DVar.CKind) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12567 | << getOpenMPClauseName(OMPC_map) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12568 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12569 | reportOriginalDsa(SemaRef, DSAS, CurDeclaration, DVar); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12570 | continue; |
| 12571 | } |
| 12572 | } |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 12573 | } |
| 12574 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12575 | // Save the current expression. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12576 | MVLI.ProcessedVarList.push_back(RE); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12577 | |
| 12578 | // Store the components in the stack so that they can be used to check |
| 12579 | // against other clauses later on. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12580 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 12581 | /*WhereFoundClauseKind=*/OMPC_map); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12582 | |
| 12583 | // Save the components and declaration to create the clause. For purposes of |
| 12584 | // the clause creation, any component list that has has base 'this' uses |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 12585 | // null as base declaration. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12586 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 12587 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 12588 | CurComponents.end()); |
| 12589 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 12590 | : CurDeclaration); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12591 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12592 | } |
| 12593 | |
| 12594 | OMPClause * |
| 12595 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 12596 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 12597 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 12598 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 12599 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 12600 | MappableVarListInfo MVLI(VarList); |
| 12601 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 12602 | MapType, IsMapTypeImplicit); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12603 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12604 | // We need to produce a map clause even if we don't have variables so that |
| 12605 | // other diagnostics related with non-existing map clauses are accurate. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12606 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 12607 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 12608 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 12609 | IsMapTypeImplicit, MapLoc); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12610 | } |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12611 | |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12612 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 12613 | TypeResult ParsedType) { |
| 12614 | assert(ParsedType.isUsable()); |
| 12615 | |
| 12616 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 12617 | if (ReductionType.isNull()) |
| 12618 | return QualType(); |
| 12619 | |
| 12620 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 12621 | // A type name in a declare reduction directive cannot be a function type, an |
| 12622 | // array type, a reference type, or a type qualified with const, volatile or |
| 12623 | // restrict. |
| 12624 | if (ReductionType.hasQualifiers()) { |
| 12625 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 12626 | return QualType(); |
| 12627 | } |
| 12628 | |
| 12629 | if (ReductionType->isFunctionType()) { |
| 12630 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 12631 | return QualType(); |
| 12632 | } |
| 12633 | if (ReductionType->isReferenceType()) { |
| 12634 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 12635 | return QualType(); |
| 12636 | } |
| 12637 | if (ReductionType->isArrayType()) { |
| 12638 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 12639 | return QualType(); |
| 12640 | } |
| 12641 | return ReductionType; |
| 12642 | } |
| 12643 | |
| 12644 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 12645 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 12646 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 12647 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 12648 | SmallVector<Decl *, 8> Decls; |
| 12649 | Decls.reserve(ReductionTypes.size()); |
| 12650 | |
| 12651 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| Richard Smith | becb92d | 2017-10-10 22:33:17 +0000 | [diff] [blame] | 12652 | forRedeclarationInCurContext()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12653 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 12654 | // A reduction-identifier may not be re-declared in the current scope for the |
| 12655 | // same type or for a type that is compatible according to the base language |
| 12656 | // rules. |
| 12657 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 12658 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 12659 | bool InCompoundScope = true; |
| 12660 | if (S != nullptr) { |
| 12661 | // Find previous declaration with the same name not referenced in other |
| 12662 | // declarations. |
| 12663 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 12664 | InCompoundScope = |
| 12665 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 12666 | LookupName(Lookup, S); |
| 12667 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 12668 | /*AllowInlineNamespace=*/false); |
| 12669 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12670 | LookupResult::Filter Filter = Lookup.makeFilter(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12671 | while (Filter.hasNext()) { |
| 12672 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 12673 | if (InCompoundScope) { |
| 12674 | auto I = UsedAsPrevious.find(PrevDecl); |
| 12675 | if (I == UsedAsPrevious.end()) |
| 12676 | UsedAsPrevious[PrevDecl] = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12677 | if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope()) |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12678 | UsedAsPrevious[D] = true; |
| 12679 | } |
| 12680 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 12681 | PrevDecl->getLocation(); |
| 12682 | } |
| 12683 | Filter.done(); |
| 12684 | if (InCompoundScope) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12685 | for (const auto &PrevData : UsedAsPrevious) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12686 | if (!PrevData.second) { |
| 12687 | PrevDRD = PrevData.first; |
| 12688 | break; |
| 12689 | } |
| 12690 | } |
| 12691 | } |
| 12692 | } else if (PrevDeclInScope != nullptr) { |
| 12693 | auto *PrevDRDInScope = PrevDRD = |
| 12694 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 12695 | do { |
| 12696 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 12697 | PrevDRDInScope->getLocation(); |
| 12698 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 12699 | } while (PrevDRDInScope != nullptr); |
| 12700 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12701 | for (const auto &TyData : ReductionTypes) { |
| 12702 | const auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12703 | bool Invalid = false; |
| 12704 | if (I != PreviousRedeclTypes.end()) { |
| 12705 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 12706 | << TyData.first; |
| 12707 | Diag(I->second, diag::note_previous_definition); |
| 12708 | Invalid = true; |
| 12709 | } |
| 12710 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 12711 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 12712 | Name, TyData.first, PrevDRD); |
| 12713 | DC->addDecl(DRD); |
| 12714 | DRD->setAccess(AS); |
| 12715 | Decls.push_back(DRD); |
| 12716 | if (Invalid) |
| 12717 | DRD->setInvalidDecl(); |
| 12718 | else |
| 12719 | PrevDRD = DRD; |
| 12720 | } |
| 12721 | |
| 12722 | return DeclGroupPtrTy::make( |
| 12723 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 12724 | } |
| 12725 | |
| 12726 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 12727 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 12728 | |
| 12729 | // Enter new function scope. |
| 12730 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 12731 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12732 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 12733 | |
| 12734 | if (S != nullptr) |
| 12735 | PushDeclContext(S, DRD); |
| 12736 | else |
| 12737 | CurContext = DRD; |
| 12738 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 12739 | PushExpressionEvaluationContext( |
| 12740 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12741 | |
| 12742 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 12743 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 12744 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 12745 | // uses semantics of argument handles by value, but it should be passed by |
| 12746 | // reference. C lang does not support references, so pass all parameters as |
| 12747 | // pointers. |
| 12748 | // Create 'T omp_in;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12749 | VarDecl *OmpInParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 12750 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12751 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 12752 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 12753 | // uses semantics of argument handles by value, but it should be passed by |
| 12754 | // reference. C lang does not support references, so pass all parameters as |
| 12755 | // pointers. |
| 12756 | // Create 'T omp_out;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12757 | VarDecl *OmpOutParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12758 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 12759 | if (S != nullptr) { |
| 12760 | PushOnScopeChains(OmpInParm, S); |
| 12761 | PushOnScopeChains(OmpOutParm, S); |
| 12762 | } else { |
| 12763 | DRD->addDecl(OmpInParm); |
| 12764 | DRD->addDecl(OmpOutParm); |
| 12765 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 12766 | Expr *InE = |
| 12767 | ::buildDeclRefExpr(*this, OmpInParm, ReductionType, D->getLocation()); |
| 12768 | Expr *OutE = |
| 12769 | ::buildDeclRefExpr(*this, OmpOutParm, ReductionType, D->getLocation()); |
| 12770 | DRD->setCombinerData(InE, OutE); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12771 | } |
| 12772 | |
| 12773 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 12774 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 12775 | DiscardCleanupsInEvaluationContext(); |
| 12776 | PopExpressionEvaluationContext(); |
| 12777 | |
| 12778 | PopDeclContext(); |
| 12779 | PopFunctionScopeInfo(); |
| 12780 | |
| 12781 | if (Combiner != nullptr) |
| 12782 | DRD->setCombiner(Combiner); |
| 12783 | else |
| 12784 | DRD->setInvalidDecl(); |
| 12785 | } |
| 12786 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 12787 | VarDecl *Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12788 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 12789 | |
| 12790 | // Enter new function scope. |
| 12791 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 12792 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12793 | |
| 12794 | if (S != nullptr) |
| 12795 | PushDeclContext(S, DRD); |
| 12796 | else |
| 12797 | CurContext = DRD; |
| 12798 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 12799 | PushExpressionEvaluationContext( |
| 12800 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12801 | |
| 12802 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12803 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 12804 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 12805 | // uses semantics of argument handles by value, but it should be passed by |
| 12806 | // reference. C lang does not support references, so pass all parameters as |
| 12807 | // pointers. |
| 12808 | // Create 'T omp_priv;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12809 | VarDecl *OmpPrivParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12810 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 12811 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 12812 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 12813 | // uses semantics of argument handles by value, but it should be passed by |
| 12814 | // reference. C lang does not support references, so pass all parameters as |
| 12815 | // pointers. |
| 12816 | // Create 'T omp_orig;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12817 | VarDecl *OmpOrigParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 12818 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12819 | if (S != nullptr) { |
| 12820 | PushOnScopeChains(OmpPrivParm, S); |
| 12821 | PushOnScopeChains(OmpOrigParm, S); |
| 12822 | } else { |
| 12823 | DRD->addDecl(OmpPrivParm); |
| 12824 | DRD->addDecl(OmpOrigParm); |
| 12825 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 12826 | Expr *OrigE = |
| 12827 | ::buildDeclRefExpr(*this, OmpOrigParm, ReductionType, D->getLocation()); |
| 12828 | Expr *PrivE = |
| 12829 | ::buildDeclRefExpr(*this, OmpPrivParm, ReductionType, D->getLocation()); |
| 12830 | DRD->setInitializerData(OrigE, PrivE); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 12831 | return OmpPrivParm; |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12832 | } |
| 12833 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 12834 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
| 12835 | VarDecl *OmpPrivParm) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12836 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 12837 | DiscardCleanupsInEvaluationContext(); |
| 12838 | PopExpressionEvaluationContext(); |
| 12839 | |
| 12840 | PopDeclContext(); |
| 12841 | PopFunctionScopeInfo(); |
| 12842 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 12843 | if (Initializer != nullptr) { |
| 12844 | DRD->setInitializer(Initializer, OMPDeclareReductionDecl::CallInit); |
| 12845 | } else if (OmpPrivParm->hasInit()) { |
| 12846 | DRD->setInitializer(OmpPrivParm->getInit(), |
| 12847 | OmpPrivParm->isDirectInit() |
| 12848 | ? OMPDeclareReductionDecl::DirectInit |
| 12849 | : OMPDeclareReductionDecl::CopyInit); |
| 12850 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12851 | DRD->setInvalidDecl(); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 12852 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12853 | } |
| 12854 | |
| 12855 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 12856 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12857 | for (Decl *D : DeclReductions.get()) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12858 | if (IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12859 | if (S) |
| 12860 | PushOnScopeChains(cast<OMPDeclareReductionDecl>(D), S, |
| 12861 | /*AddToContext=*/false); |
| 12862 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12863 | D->setInvalidDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12864 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 12865 | } |
| 12866 | return DeclReductions; |
| 12867 | } |
| 12868 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12869 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12870 | SourceLocation StartLoc, |
| 12871 | SourceLocation LParenLoc, |
| 12872 | SourceLocation EndLoc) { |
| 12873 | Expr *ValExpr = NumTeams; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 12874 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12875 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12876 | // OpenMP [teams Constrcut, Restrictions] |
| 12877 | // The num_teams expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12878 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12879 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12880 | return nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12881 | |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 12882 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 12883 | OpenMPDirectiveKind CaptureRegion = |
| 12884 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams); |
| 12885 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 12886 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12887 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 12888 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 12889 | HelperValStmt = buildPreInits(Context, Captures); |
| 12890 | } |
| 12891 | |
| 12892 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 12893 | StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 12894 | } |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12895 | |
| 12896 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 12897 | SourceLocation StartLoc, |
| 12898 | SourceLocation LParenLoc, |
| 12899 | SourceLocation EndLoc) { |
| 12900 | Expr *ValExpr = ThreadLimit; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 12901 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12902 | |
| 12903 | // OpenMP [teams Constrcut, Restrictions] |
| 12904 | // The thread_limit expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12905 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12906 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12907 | return nullptr; |
| 12908 | |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 12909 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 12910 | OpenMPDirectiveKind CaptureRegion = |
| 12911 | getOpenMPCaptureRegionForClause(DKind, OMPC_thread_limit); |
| 12912 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 12913 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12914 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 12915 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 12916 | HelperValStmt = buildPreInits(Context, Captures); |
| 12917 | } |
| 12918 | |
| 12919 | return new (Context) OMPThreadLimitClause( |
| 12920 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12921 | } |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12922 | |
| 12923 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 12924 | SourceLocation StartLoc, |
| 12925 | SourceLocation LParenLoc, |
| 12926 | SourceLocation EndLoc) { |
| 12927 | Expr *ValExpr = Priority; |
| 12928 | |
| 12929 | // OpenMP [2.9.1, task Constrcut] |
| 12930 | // The priority-value is a non-negative numerical scalar expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12931 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12932 | /*StrictlyPositive=*/false)) |
| 12933 | return nullptr; |
| 12934 | |
| 12935 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 12936 | } |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 12937 | |
| 12938 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 12939 | SourceLocation StartLoc, |
| 12940 | SourceLocation LParenLoc, |
| 12941 | SourceLocation EndLoc) { |
| 12942 | Expr *ValExpr = Grainsize; |
| 12943 | |
| 12944 | // OpenMP [2.9.2, taskloop Constrcut] |
| 12945 | // The parameter of the grainsize clause must be a positive integer |
| 12946 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12947 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 12948 | /*StrictlyPositive=*/true)) |
| 12949 | return nullptr; |
| 12950 | |
| 12951 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 12952 | } |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 12953 | |
| 12954 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 12955 | SourceLocation StartLoc, |
| 12956 | SourceLocation LParenLoc, |
| 12957 | SourceLocation EndLoc) { |
| 12958 | Expr *ValExpr = NumTasks; |
| 12959 | |
| 12960 | // OpenMP [2.9.2, taskloop Constrcut] |
| 12961 | // The parameter of the num_tasks clause must be a positive integer |
| 12962 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12963 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 12964 | /*StrictlyPositive=*/true)) |
| 12965 | return nullptr; |
| 12966 | |
| 12967 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 12968 | } |
| 12969 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 12970 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 12971 | SourceLocation LParenLoc, |
| 12972 | SourceLocation EndLoc) { |
| 12973 | // OpenMP [2.13.2, critical construct, Description] |
| 12974 | // ... where hint-expression is an integer constant expression that evaluates |
| 12975 | // to a valid lock hint. |
| 12976 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 12977 | if (HintExpr.isInvalid()) |
| 12978 | return nullptr; |
| 12979 | return new (Context) |
| 12980 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 12981 | } |
| 12982 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 12983 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 12984 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 12985 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 12986 | SourceLocation EndLoc) { |
| 12987 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 12988 | std::string Values; |
| 12989 | Values += "'"; |
| 12990 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 12991 | Values += "'"; |
| 12992 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 12993 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 12994 | return nullptr; |
| 12995 | } |
| 12996 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 12997 | Stmt *HelperValStmt = nullptr; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 12998 | if (ChunkSize) { |
| 12999 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 13000 | !ChunkSize->isInstantiationDependent() && |
| 13001 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13002 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13003 | ExprResult Val = |
| 13004 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 13005 | if (Val.isInvalid()) |
| 13006 | return nullptr; |
| 13007 | |
| 13008 | ValExpr = Val.get(); |
| 13009 | |
| 13010 | // OpenMP [2.7.1, Restrictions] |
| 13011 | // chunk_size must be a loop invariant integer expression with a positive |
| 13012 | // value. |
| 13013 | llvm::APSInt Result; |
| 13014 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 13015 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 13016 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 13017 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 13018 | return nullptr; |
| 13019 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 13020 | } else if (getOpenMPCaptureRegionForClause( |
| 13021 | DSAStack->getCurrentDirective(), OMPC_dist_schedule) != |
| 13022 | OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 13023 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 13024 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13025 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 13026 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 13027 | HelperValStmt = buildPreInits(Context, Captures); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13028 | } |
| 13029 | } |
| 13030 | } |
| 13031 | |
| 13032 | return new (Context) |
| 13033 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 13034 | Kind, ValExpr, HelperValStmt); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13035 | } |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13036 | |
| 13037 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 13038 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 13039 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 13040 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 13041 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13042 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13043 | std::string Value; |
| 13044 | SourceLocation Loc; |
| 13045 | Value += "'"; |
| 13046 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 13047 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13048 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13049 | Loc = MLoc; |
| 13050 | } else { |
| 13051 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13052 | OMPC_DEFAULTMAP_scalar); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13053 | Loc = KindLoc; |
| 13054 | } |
| 13055 | Value += "'"; |
| 13056 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 13057 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 13058 | return nullptr; |
| 13059 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 13060 | DSAStack->setDefaultDMAToFromScalar(StartLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13061 | |
| 13062 | return new (Context) |
| 13063 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 13064 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13065 | |
| 13066 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 13067 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 13068 | if (!CurLexicalContext->isFileContext() && |
| 13069 | !CurLexicalContext->isExternCContext() && |
| Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 13070 | !CurLexicalContext->isExternCXXContext() && |
| 13071 | !isa<CXXRecordDecl>(CurLexicalContext) && |
| 13072 | !isa<ClassTemplateDecl>(CurLexicalContext) && |
| 13073 | !isa<ClassTemplatePartialSpecializationDecl>(CurLexicalContext) && |
| 13074 | !isa<ClassTemplateSpecializationDecl>(CurLexicalContext)) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13075 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 13076 | return false; |
| 13077 | } |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 13078 | ++DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13079 | return true; |
| 13080 | } |
| 13081 | |
| 13082 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 13083 | assert(DeclareTargetNestingLevel > 0 && |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13084 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 13085 | --DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13086 | } |
| 13087 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13088 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 13089 | CXXScopeSpec &ScopeSpec, |
| 13090 | const DeclarationNameInfo &Id, |
| 13091 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 13092 | NamedDeclSetType &SameDirectiveDecls) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13093 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 13094 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 13095 | |
| 13096 | if (Lookup.isAmbiguous()) |
| 13097 | return; |
| 13098 | Lookup.suppressDiagnostics(); |
| 13099 | |
| 13100 | if (!Lookup.isSingleResult()) { |
| 13101 | if (TypoCorrection Corrected = |
| 13102 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 13103 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 13104 | CTK_ErrorRecovery)) { |
| 13105 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 13106 | << Id.getName()); |
| 13107 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 13108 | return; |
| 13109 | } |
| 13110 | |
| 13111 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 13112 | return; |
| 13113 | } |
| 13114 | |
| 13115 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13116 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND) || |
| 13117 | isa<FunctionTemplateDecl>(ND)) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13118 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 13119 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13120 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 13121 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( |
| 13122 | cast<ValueDecl>(ND)); |
| 13123 | if (!Res) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13124 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13125 | ND->addAttr(A); |
| 13126 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 13127 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 13128 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Id.getLoc()); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13129 | } else if (*Res != MT) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13130 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 13131 | << Id.getName(); |
| 13132 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13133 | } else { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13134 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13135 | } |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 13136 | } |
| 13137 | |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13138 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 13139 | Sema &SemaRef, Decl *D) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13140 | if (!D || !isa<VarDecl>(D)) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13141 | return; |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13142 | auto *VD = cast<VarDecl>(D); |
| 13143 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| 13144 | return; |
| 13145 | SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_target_context); |
| 13146 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13147 | } |
| 13148 | |
| 13149 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 13150 | Sema &SemaRef, DSAStackTy *Stack, |
| 13151 | ValueDecl *VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13152 | return VD->hasAttr<OMPDeclareTargetDeclAttr>() || |
| 13153 | checkTypeMappable(SL, SR, SemaRef, Stack, VD->getType(), |
| 13154 | /*FullCheck=*/false); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13155 | } |
| 13156 | |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 13157 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
| 13158 | SourceLocation IdLoc) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13159 | if (!D || D->isInvalidDecl()) |
| 13160 | return; |
| 13161 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13162 | SourceLocation SL = E ? E->getBeginLoc() : D->getLocation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13163 | if (auto *VD = dyn_cast<VarDecl>(D)) { |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 13164 | // Only global variables can be marked as declare target. |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13165 | if (!VD->isFileVarDecl() && !VD->isStaticLocal() && |
| 13166 | !VD->isStaticDataMember()) |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 13167 | return; |
| 13168 | // 2.10.6: threadprivate variable cannot appear in a declare target |
| 13169 | // directive. |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13170 | if (DSAStack->isThreadPrivate(VD)) { |
| 13171 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13172 | reportOriginalDsa(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13173 | return; |
| 13174 | } |
| 13175 | } |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 13176 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 13177 | D = FTD->getTemplatedDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13178 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13179 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 13180 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD); |
| 13181 | if (Res && *Res == OMPDeclareTargetDeclAttr::MT_Link) { |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 13182 | assert(IdLoc.isValid() && "Source location is expected"); |
| 13183 | Diag(IdLoc, diag::err_omp_function_in_link_clause); |
| 13184 | Diag(FD->getLocation(), diag::note_defined_here) << FD; |
| 13185 | return; |
| 13186 | } |
| 13187 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13188 | if (auto *VD = dyn_cast<ValueDecl>(D)) { |
| 13189 | // Problem if any with var declared with incomplete type will be reported |
| 13190 | // as normal, so no need to check it here. |
| 13191 | if ((E || !VD->getType()->isIncompleteType()) && |
| 13192 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) |
| 13193 | return; |
| 13194 | if (!E && !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) { |
| 13195 | // Checking declaration inside declare target region. |
| 13196 | if (isa<VarDecl>(D) || isa<FunctionDecl>(D) || |
| 13197 | isa<FunctionTemplateDecl>(D)) { |
| 13198 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 13199 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 13200 | D->addAttr(A); |
| 13201 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 13202 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
| 13203 | } |
| 13204 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13205 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13206 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 13207 | if (!E) |
| 13208 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 13209 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 13210 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13211 | |
| 13212 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 13213 | SourceLocation StartLoc, |
| 13214 | SourceLocation LParenLoc, |
| 13215 | SourceLocation EndLoc) { |
| 13216 | MappableVarListInfo MVLI(VarList); |
| 13217 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 13218 | if (MVLI.ProcessedVarList.empty()) |
| 13219 | return nullptr; |
| 13220 | |
| 13221 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 13222 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 13223 | MVLI.VarComponents); |
| 13224 | } |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 13225 | |
| 13226 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 13227 | SourceLocation StartLoc, |
| 13228 | SourceLocation LParenLoc, |
| 13229 | SourceLocation EndLoc) { |
| 13230 | MappableVarListInfo MVLI(VarList); |
| 13231 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 13232 | if (MVLI.ProcessedVarList.empty()) |
| 13233 | return nullptr; |
| 13234 | |
| 13235 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 13236 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 13237 | MVLI.VarComponents); |
| 13238 | } |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13239 | |
| 13240 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 13241 | SourceLocation StartLoc, |
| 13242 | SourceLocation LParenLoc, |
| 13243 | SourceLocation EndLoc) { |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13244 | MappableVarListInfo MVLI(VarList); |
| 13245 | SmallVector<Expr *, 8> PrivateCopies; |
| 13246 | SmallVector<Expr *, 8> Inits; |
| 13247 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13248 | for (Expr *RefExpr : VarList) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13249 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 13250 | SourceLocation ELoc; |
| 13251 | SourceRange ERange; |
| 13252 | Expr *SimpleRefExpr = RefExpr; |
| 13253 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 13254 | if (Res.second) { |
| 13255 | // It will be analyzed later. |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13256 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 13257 | PrivateCopies.push_back(nullptr); |
| 13258 | Inits.push_back(nullptr); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13259 | } |
| 13260 | ValueDecl *D = Res.first; |
| 13261 | if (!D) |
| 13262 | continue; |
| 13263 | |
| 13264 | QualType Type = D->getType(); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13265 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 13266 | |
| 13267 | auto *VD = dyn_cast<VarDecl>(D); |
| 13268 | |
| 13269 | // Item should be a pointer or reference to pointer. |
| 13270 | if (!Type->isPointerType()) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13271 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 13272 | << 0 << RefExpr->getSourceRange(); |
| 13273 | continue; |
| 13274 | } |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13275 | |
| 13276 | // Build the private variable and the expression that refers to it. |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 13277 | auto VDPrivate = |
| 13278 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 13279 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 13280 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13281 | if (VDPrivate->isInvalidDecl()) |
| 13282 | continue; |
| 13283 | |
| 13284 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13285 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13286 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 13287 | |
| 13288 | // Add temporary variable to initialize the private copy of the pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13289 | VarDecl *VDInit = |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13290 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13291 | DeclRefExpr *VDInitRefExpr = buildDeclRefExpr( |
| 13292 | *this, VDInit, RefExpr->getType(), RefExpr->getExprLoc()); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13293 | AddInitializerToDecl(VDPrivate, |
| 13294 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 13295 | /*DirectInit=*/false); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13296 | |
| 13297 | // If required, build a capture to implement the privatization initialized |
| 13298 | // with the current list item value. |
| 13299 | DeclRefExpr *Ref = nullptr; |
| 13300 | if (!VD) |
| 13301 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 13302 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 13303 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 13304 | Inits.push_back(VDInitRefExpr); |
| 13305 | |
| 13306 | // We need to add a data sharing attribute for this variable to make sure it |
| 13307 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 13308 | // similar properties of a first private variable. |
| 13309 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 13310 | |
| 13311 | // Create a mappable component for the list item. List items in this clause |
| 13312 | // only need a component. |
| 13313 | MVLI.VarBaseDeclarations.push_back(D); |
| 13314 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 13315 | MVLI.VarComponents.back().push_back( |
| 13316 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13317 | } |
| 13318 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13319 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13320 | return nullptr; |
| 13321 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 13322 | return OMPUseDevicePtrClause::Create( |
| 13323 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 13324 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 13325 | } |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13326 | |
| 13327 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 13328 | SourceLocation StartLoc, |
| 13329 | SourceLocation LParenLoc, |
| 13330 | SourceLocation EndLoc) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13331 | MappableVarListInfo MVLI(VarList); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13332 | for (Expr *RefExpr : VarList) { |
| Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 13333 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13334 | SourceLocation ELoc; |
| 13335 | SourceRange ERange; |
| 13336 | Expr *SimpleRefExpr = RefExpr; |
| 13337 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 13338 | if (Res.second) { |
| 13339 | // It will be analyzed later. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13340 | MVLI.ProcessedVarList.push_back(RefExpr); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13341 | } |
| 13342 | ValueDecl *D = Res.first; |
| 13343 | if (!D) |
| 13344 | continue; |
| 13345 | |
| 13346 | QualType Type = D->getType(); |
| 13347 | // item should be a pointer or array or reference to pointer or array |
| 13348 | if (!Type.getNonReferenceType()->isPointerType() && |
| 13349 | !Type.getNonReferenceType()->isArrayType()) { |
| 13350 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 13351 | << 0 << RefExpr->getSourceRange(); |
| 13352 | continue; |
| 13353 | } |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13354 | |
| 13355 | // Check if the declaration in the clause does not show up in any data |
| 13356 | // sharing attribute. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13357 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13358 | if (isOpenMPPrivate(DVar.CKind)) { |
| 13359 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 13360 | << getOpenMPClauseName(DVar.CKind) |
| 13361 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 13362 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13363 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13364 | continue; |
| 13365 | } |
| 13366 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13367 | const Expr *ConflictExpr; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13368 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13369 | D, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13370 | [&ConflictExpr]( |
| 13371 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 13372 | OpenMPClauseKind) -> bool { |
| 13373 | ConflictExpr = R.front().getAssociatedExpression(); |
| 13374 | return true; |
| 13375 | })) { |
| 13376 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 13377 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 13378 | << ConflictExpr->getSourceRange(); |
| 13379 | continue; |
| 13380 | } |
| 13381 | |
| 13382 | // Store the components in the stack so that they can be used to check |
| 13383 | // against other clauses later on. |
| 13384 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 13385 | DSAStack->addMappableExpressionComponents( |
| 13386 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 13387 | |
| 13388 | // Record the expression we've just processed. |
| 13389 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 13390 | |
| 13391 | // Create a mappable component for the list item. List items in this clause |
| 13392 | // only need a component. We use a null declaration to signal fields in |
| 13393 | // 'this'. |
| 13394 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 13395 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 13396 | "Unexpected device pointer expression!"); |
| 13397 | MVLI.VarBaseDeclarations.push_back( |
| 13398 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 13399 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 13400 | MVLI.VarComponents.back().push_back(MC); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13401 | } |
| 13402 | |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13403 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13404 | return nullptr; |
| 13405 | |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13406 | return OMPIsDevicePtrClause::Create( |
| 13407 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 13408 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 13409 | } |