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 |
| 10 | /// \brief 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 | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeOrdering.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 27 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Scope.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 34 | #include "llvm/ADT/PointerEmbeddedInt.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 35 | using namespace clang; |
| 36 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 37 | //===----------------------------------------------------------------------===// |
| 38 | // Stack of data-sharing attributes for variables |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | |
| 41 | namespace { |
| 42 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 43 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 44 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 45 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 46 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 47 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 48 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 49 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 50 | /// clauses and their data-sharing attributes. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 51 | class DSAStackTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 52 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 53 | struct DSAVarData final { |
| 54 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 55 | OpenMPClauseKind CKind = OMPC_unknown; |
| 56 | Expr *RefExpr = nullptr; |
| 57 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 58 | SourceLocation ImplicitDSALoc; |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 59 | DSAVarData() = default; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 60 | }; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 61 | typedef llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4> |
| 62 | OperatorOffsetTy; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 63 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 64 | private: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 65 | struct DSAInfo final { |
| 66 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 67 | /// Pointer to a reference expression and a flag which shows that the |
| 68 | /// variable is marked as lastprivate(true) or not (false). |
| 69 | llvm::PointerIntPair<Expr *, 1, bool> RefExpr; |
| 70 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 71 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 72 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 73 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 74 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; |
| 75 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 76 | /// Struct that associates a component with the clause kind where they are |
| 77 | /// found. |
| 78 | struct MappedExprComponentTy { |
| 79 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 80 | OpenMPClauseKind Kind = OMPC_unknown; |
| 81 | }; |
| 82 | typedef llvm::DenseMap<ValueDecl *, MappedExprComponentTy> |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 83 | MappedExprComponentsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 84 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 85 | CriticalsWithHintsTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 86 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> |
| 87 | DoacrossDependMapTy; |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 88 | struct ReductionData { |
| 89 | SourceRange ReductionRange; |
| 90 | llvm::PointerUnion<const Expr *, |
| 91 | llvm::PointerEmbeddedInt<BinaryOperatorKind>> |
| 92 | ReductionOp; |
| 93 | ReductionData() = default; |
| 94 | void set(BinaryOperatorKind BO, SourceRange RR) { |
| 95 | ReductionRange = RR; |
| 96 | ReductionOp = BO; |
| 97 | } |
| 98 | void set(const Expr *RefExpr, SourceRange RR) { |
| 99 | ReductionRange = RR; |
| 100 | ReductionOp = RefExpr; |
| 101 | } |
| 102 | }; |
| 103 | typedef llvm::DenseMap<ValueDecl *, ReductionData> DeclReductionMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 104 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 105 | struct SharingMapTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 106 | DeclSAMapTy SharingMap; |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 107 | DeclReductionMapTy ReductionMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 108 | AlignedMapTy AlignedMap; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 109 | MappedExprComponentsTy MappedExprComponents; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 110 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 111 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 112 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 113 | OpenMPDirectiveKind Directive = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 114 | DeclarationNameInfo DirectiveName; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 115 | Scope *CurScope = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 116 | SourceLocation ConstructLoc; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 117 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 118 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 119 | /// This data is required during codegen. |
| 120 | DoacrossDependMapTy DoacrossDepends; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 121 | /// \brief first argument (Expr *) contains optional argument of the |
| 122 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 123 | /// clause, false otherwise. |
| 124 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 125 | bool NowaitRegion = false; |
| 126 | bool CancelRegion = false; |
| 127 | unsigned AssociatedLoops = 1; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 128 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 129 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 130 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 131 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 132 | ConstructLoc(Loc) {} |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 133 | SharingMapTy() = default; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 136 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 137 | |
| 138 | /// \brief Stack of used declaration and their data-sharing attributes. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 139 | DeclSAMapTy Threadprivates; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 140 | const FunctionScopeInfo *CurrentNonCapturingFunctionScope = nullptr; |
| 141 | SmallVector<std::pair<StackTy, const FunctionScopeInfo *>, 4> Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 142 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 143 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 144 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 145 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 146 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 147 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 148 | |
| 149 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 150 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 151 | DSAVarData getDSA(StackTy::reverse_iterator &Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 152 | |
| 153 | /// \brief Checks if the variable is a local for OpenMP region. |
| 154 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 155 | |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 156 | bool isStackEmpty() const { |
| 157 | return Stack.empty() || |
| 158 | Stack.back().second != CurrentNonCapturingFunctionScope || |
| 159 | Stack.back().first.empty(); |
| 160 | } |
| 161 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 162 | public: |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 163 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 164 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 165 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 166 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 167 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 168 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 169 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 170 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 171 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 172 | Scope *CurScope, SourceLocation Loc) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 173 | if (Stack.empty() || |
| 174 | Stack.back().second != CurrentNonCapturingFunctionScope) |
| 175 | Stack.emplace_back(StackTy(), CurrentNonCapturingFunctionScope); |
| 176 | Stack.back().first.emplace_back(DKind, DirName, CurScope, Loc); |
| 177 | Stack.back().first.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void pop() { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 181 | assert(!Stack.back().first.empty() && |
| 182 | "Data-sharing attributes stack is empty!"); |
| 183 | Stack.back().first.pop_back(); |
| 184 | } |
| 185 | |
| 186 | /// Start new OpenMP region stack in new non-capturing function. |
| 187 | void pushFunction() { |
| 188 | const FunctionScopeInfo *CurFnScope = SemaRef.getCurFunction(); |
| 189 | assert(!isa<CapturingScopeInfo>(CurFnScope)); |
| 190 | CurrentNonCapturingFunctionScope = CurFnScope; |
| 191 | } |
| 192 | /// Pop region stack for non-capturing function. |
| 193 | void popFunction(const FunctionScopeInfo *OldFSI) { |
| 194 | if (!Stack.empty() && Stack.back().second == OldFSI) { |
| 195 | assert(Stack.back().first.empty()); |
| 196 | Stack.pop_back(); |
| 197 | } |
| 198 | CurrentNonCapturingFunctionScope = nullptr; |
| 199 | for (const FunctionScopeInfo *FSI : llvm::reverse(SemaRef.FunctionScopes)) { |
| 200 | if (!isa<CapturingScopeInfo>(FSI)) { |
| 201 | CurrentNonCapturingFunctionScope = FSI; |
| 202 | break; |
| 203 | } |
| 204 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 207 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 208 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 209 | } |
| 210 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 211 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 212 | auto I = Criticals.find(Name.getAsString()); |
| 213 | if (I != Criticals.end()) |
| 214 | return I->second; |
| 215 | return std::make_pair(nullptr, llvm::APSInt()); |
| 216 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 217 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 218 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 219 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 220 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 221 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 222 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 223 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 224 | /// \brief Check if the specified variable is a loop control variable for |
| 225 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 226 | /// \return The index of the loop control variable in the list of associated |
| 227 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 228 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 229 | /// \brief Check if the specified variable is a loop control variable for |
| 230 | /// parent region. |
| 231 | /// \return The index of the loop control variable in the list of associated |
| 232 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 233 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 234 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 235 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 236 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 237 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 239 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 240 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 241 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 242 | /// Adds additional information for the reduction items with the reduction id |
| 243 | /// represented as an operator. |
| 244 | void addReductionData(ValueDecl *D, SourceRange SR, BinaryOperatorKind BOK); |
| 245 | /// Adds additional information for the reduction items with the reduction id |
| 246 | /// represented as reduction identifier. |
| 247 | void addReductionData(ValueDecl *D, SourceRange SR, const Expr *ReductionRef); |
| 248 | /// Returns the location and reduction operation from the innermost parent |
| 249 | /// region for the given \p D. |
| 250 | bool getTopMostReductionData(ValueDecl *D, SourceRange &SR, |
| 251 | BinaryOperatorKind &BOK); |
| 252 | /// Returns the location and reduction operation from the innermost parent |
| 253 | /// region for the given \p D. |
| 254 | bool getTopMostReductionData(ValueDecl *D, SourceRange &SR, |
| 255 | const Expr *&ReductionRef); |
| 256 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 257 | /// \brief Returns data sharing attributes from top of the stack for the |
| 258 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 259 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 260 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 261 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 262 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 263 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 264 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 265 | DSAVarData hasDSA(ValueDecl *D, |
| 266 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 267 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 268 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 269 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 270 | /// match specified \a CPred predicate in any innermost directive which |
| 271 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 272 | DSAVarData |
| 273 | hasInnermostDSA(ValueDecl *D, |
| 274 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 275 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 276 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 277 | /// \brief Checks if the specified variables has explicit data-sharing |
| 278 | /// attributes which match specified \a CPred predicate at the specified |
| 279 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 280 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 281 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 282 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 283 | |
| 284 | /// \brief Returns true if the directive at level \Level matches in the |
| 285 | /// specified \a DPred predicate. |
| 286 | bool hasExplicitDirective( |
| 287 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 288 | unsigned Level); |
| 289 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 290 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 291 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 292 | const DeclarationNameInfo &, |
| 293 | SourceLocation)> &DPred, |
| 294 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 295 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 296 | /// \brief Returns currently analyzed directive. |
| 297 | OpenMPDirectiveKind getCurrentDirective() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 298 | return isStackEmpty() ? OMPD_unknown : Stack.back().first.back().Directive; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 299 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 300 | /// \brief Returns parent directive. |
| 301 | OpenMPDirectiveKind getParentDirective() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 302 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 303 | return OMPD_unknown; |
| 304 | return std::next(Stack.back().first.rbegin())->Directive; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 305 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 306 | |
| 307 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 308 | void setDefaultDSANone(SourceLocation Loc) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 309 | assert(!isStackEmpty()); |
| 310 | Stack.back().first.back().DefaultAttr = DSA_none; |
| 311 | Stack.back().first.back().DefaultAttrLoc = Loc; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 312 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 313 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 314 | void setDefaultDSAShared(SourceLocation Loc) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 315 | assert(!isStackEmpty()); |
| 316 | Stack.back().first.back().DefaultAttr = DSA_shared; |
| 317 | Stack.back().first.back().DefaultAttrLoc = Loc; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 318 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 319 | |
| 320 | DefaultDataSharingAttributes getDefaultDSA() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 321 | return isStackEmpty() ? DSA_unspecified |
| 322 | : Stack.back().first.back().DefaultAttr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 324 | SourceLocation getDefaultDSALocation() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 325 | return isStackEmpty() ? SourceLocation() |
| 326 | : Stack.back().first.back().DefaultAttrLoc; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 327 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 328 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 329 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 330 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 331 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 332 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 335 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 336 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 337 | assert(!isStackEmpty()); |
| 338 | Stack.back().first.back().OrderedRegion.setInt(IsOrdered); |
| 339 | Stack.back().first.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 340 | } |
| 341 | /// \brief Returns true, if parent region is ordered (has associated |
| 342 | /// 'ordered' clause), false - otherwise. |
| 343 | bool isParentOrderedRegion() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 344 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 345 | return false; |
| 346 | return std::next(Stack.back().first.rbegin())->OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 347 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 348 | /// \brief Returns optional parameter for the ordered region. |
| 349 | Expr *getParentOrderedRegionParam() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 350 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 351 | return nullptr; |
| 352 | return std::next(Stack.back().first.rbegin())->OrderedRegion.getPointer(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 353 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 354 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 355 | void setNowaitRegion(bool IsNowait = true) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 356 | assert(!isStackEmpty()); |
| 357 | Stack.back().first.back().NowaitRegion = IsNowait; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 358 | } |
| 359 | /// \brief Returns true, if parent region is nowait (has associated |
| 360 | /// 'nowait' clause), false - otherwise. |
| 361 | bool isParentNowaitRegion() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 362 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 363 | return false; |
| 364 | return std::next(Stack.back().first.rbegin())->NowaitRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 365 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 366 | /// \brief Marks parent region as cancel region. |
| 367 | void setParentCancelRegion(bool Cancel = true) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 368 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 369 | auto &StackElemRef = *std::next(Stack.back().first.rbegin()); |
| 370 | StackElemRef.CancelRegion |= StackElemRef.CancelRegion || Cancel; |
| 371 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 372 | } |
| 373 | /// \brief Return true if current region has inner cancel construct. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 374 | bool isCancelRegion() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 375 | return isStackEmpty() ? false : Stack.back().first.back().CancelRegion; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 376 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 377 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 378 | /// \brief Set collapse value for the region. |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 379 | void setAssociatedLoops(unsigned Val) { |
| 380 | assert(!isStackEmpty()); |
| 381 | Stack.back().first.back().AssociatedLoops = Val; |
| 382 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 383 | /// \brief Return collapse value for region. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 384 | unsigned getAssociatedLoops() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 385 | return isStackEmpty() ? 0 : Stack.back().first.back().AssociatedLoops; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 386 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 387 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 388 | /// \brief Marks current target region as one with closely nested teams |
| 389 | /// region. |
| 390 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 391 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 392 | std::next(Stack.back().first.rbegin())->InnerTeamsRegionLoc = |
| 393 | TeamsRegionLoc; |
| 394 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 395 | } |
| 396 | /// \brief Returns true, if current region has closely nested teams region. |
| 397 | bool hasInnerTeamsRegion() const { |
| 398 | return getInnerTeamsRegionLoc().isValid(); |
| 399 | } |
| 400 | /// \brief Returns location of the nested teams region (if any). |
| 401 | SourceLocation getInnerTeamsRegionLoc() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 402 | return isStackEmpty() ? SourceLocation() |
| 403 | : Stack.back().first.back().InnerTeamsRegionLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 406 | Scope *getCurScope() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 407 | return isStackEmpty() ? nullptr : Stack.back().first.back().CurScope; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 408 | } |
| 409 | Scope *getCurScope() { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 410 | return isStackEmpty() ? nullptr : Stack.back().first.back().CurScope; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 411 | } |
| 412 | SourceLocation getConstructLoc() { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 413 | return isStackEmpty() ? SourceLocation() |
| 414 | : Stack.back().first.back().ConstructLoc; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 415 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 416 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 417 | /// Do the check specified in \a Check to all component lists and return true |
| 418 | /// if any issue is found. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 419 | bool checkMappableExprComponentListsForDecl( |
| 420 | ValueDecl *VD, bool CurrentRegionOnly, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 421 | const llvm::function_ref< |
| 422 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 423 | OpenMPClauseKind)> &Check) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 424 | if (isStackEmpty()) |
| 425 | return false; |
| 426 | auto SI = Stack.back().first.rbegin(); |
| 427 | auto SE = Stack.back().first.rend(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 428 | |
| 429 | if (SI == SE) |
| 430 | return false; |
| 431 | |
| 432 | if (CurrentRegionOnly) { |
| 433 | SE = std::next(SI); |
| 434 | } else { |
| 435 | ++SI; |
| 436 | } |
| 437 | |
| 438 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 439 | auto MI = SI->MappedExprComponents.find(VD); |
| 440 | if (MI != SI->MappedExprComponents.end()) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 441 | for (auto &L : MI->second.Components) |
| 442 | if (Check(L, MI->second.Kind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 443 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 444 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 445 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 448 | /// Do the check specified in \a Check to all component lists at a given level |
| 449 | /// and return true if any issue is found. |
| 450 | bool checkMappableExprComponentListsForDeclAtLevel( |
| 451 | ValueDecl *VD, unsigned Level, |
| 452 | const llvm::function_ref< |
| 453 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 454 | OpenMPClauseKind)> &Check) { |
| 455 | if (isStackEmpty()) |
| 456 | return false; |
| 457 | |
| 458 | auto StartI = Stack.back().first.begin(); |
| 459 | auto EndI = Stack.back().first.end(); |
| 460 | if (std::distance(StartI, EndI) <= (int)Level) |
| 461 | return false; |
| 462 | std::advance(StartI, Level); |
| 463 | |
| 464 | auto MI = StartI->MappedExprComponents.find(VD); |
| 465 | if (MI != StartI->MappedExprComponents.end()) |
| 466 | for (auto &L : MI->second.Components) |
| 467 | if (Check(L, MI->second.Kind)) |
| 468 | return true; |
| 469 | return false; |
| 470 | } |
| 471 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 472 | /// Create a new mappable expression component list associated with a given |
| 473 | /// declaration and initialize it with the provided list of components. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 474 | void addMappableExpressionComponents( |
| 475 | ValueDecl *VD, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 476 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 477 | OpenMPClauseKind WhereFoundClauseKind) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 478 | assert(!isStackEmpty() && |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 479 | "Not expecting to retrieve components from a empty stack!"); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 480 | auto &MEC = Stack.back().first.back().MappedExprComponents[VD]; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 481 | // Create new entry and append the new components there. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 482 | MEC.Components.resize(MEC.Components.size() + 1); |
| 483 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 484 | MEC.Kind = WhereFoundClauseKind; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 485 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 486 | |
| 487 | unsigned getNestingLevel() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 488 | assert(!isStackEmpty()); |
| 489 | return Stack.back().first.size() - 1; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 490 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 491 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 492 | assert(!isStackEmpty() && Stack.back().first.size() > 1); |
| 493 | auto &StackElem = *std::next(Stack.back().first.rbegin()); |
| 494 | assert(isOpenMPWorksharingDirective(StackElem.Directive)); |
| 495 | StackElem.DoacrossDepends.insert({C, OpsOffs}); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 496 | } |
| 497 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 498 | getDoacrossDependClauses() const { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 499 | assert(!isStackEmpty()); |
| 500 | auto &StackElem = Stack.back().first.back(); |
| 501 | if (isOpenMPWorksharingDirective(StackElem.Directive)) { |
| 502 | auto &Ref = StackElem.DoacrossDepends; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 503 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 504 | } |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 505 | return llvm::make_range(StackElem.DoacrossDepends.end(), |
| 506 | StackElem.DoacrossDepends.end()); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 507 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 509 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 510 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 511 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 512 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 513 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 514 | |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 515 | static Expr *getExprAsWritten(Expr *E) { |
| 516 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 517 | E = ExprTemp->getSubExpr(); |
| 518 | |
| 519 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 520 | E = MTE->GetTemporaryExpr(); |
| 521 | |
| 522 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 523 | E = Binder->getSubExpr(); |
| 524 | |
| 525 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 526 | E = ICE->getSubExprAsWritten(); |
| 527 | return E->IgnoreParens(); |
| 528 | } |
| 529 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 530 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 531 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) |
| 532 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 533 | D = ME->getMemberDecl(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 534 | auto *VD = dyn_cast<VarDecl>(D); |
| 535 | auto *FD = dyn_cast<FieldDecl>(D); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 536 | if (VD != nullptr) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | VD = VD->getCanonicalDecl(); |
| 538 | D = VD; |
| 539 | } else { |
| 540 | assert(FD); |
| 541 | FD = FD->getCanonicalDecl(); |
| 542 | D = FD; |
| 543 | } |
| 544 | return D; |
| 545 | } |
| 546 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 547 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator &Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 548 | ValueDecl *D) { |
| 549 | D = getCanonicalDecl(D); |
| 550 | auto *VD = dyn_cast<VarDecl>(D); |
| 551 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 552 | DSAVarData DVar; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 553 | if (isStackEmpty() || Iter == Stack.back().first.rend()) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 554 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 555 | // in a region but not in construct] |
| 556 | // File-scope or namespace-scope variables referenced in called routines |
| 557 | // in the region are shared unless they appear in a threadprivate |
| 558 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 559 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 560 | DVar.CKind = OMPC_shared; |
| 561 | |
| 562 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 563 | // in a region but not in construct] |
| 564 | // Variables with static storage duration that are declared in called |
| 565 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 566 | if (VD && VD->hasGlobalStorage()) |
| 567 | DVar.CKind = OMPC_shared; |
| 568 | |
| 569 | // Non-static data members are shared by default. |
| 570 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 571 | DVar.CKind = OMPC_shared; |
| 572 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 573 | return DVar; |
| 574 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 575 | |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 576 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 577 | // in a Construct, C/C++, predetermined, p.1] |
| 578 | // Variables with automatic storage duration that are declared in a scope |
| 579 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 580 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 581 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 582 | DVar.CKind = OMPC_private; |
| 583 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 586 | DVar.DKind = Iter->Directive; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 587 | // Explicitly specified attributes and local variables with predetermined |
| 588 | // attributes. |
| 589 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 590 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 591 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 592 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 593 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | return DVar; |
| 595 | } |
| 596 | |
| 597 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 598 | // in a Construct, C/C++, implicitly determined, p.1] |
| 599 | // In a parallel or task construct, the data-sharing attributes of these |
| 600 | // variables are determined by the default clause, if present. |
| 601 | switch (Iter->DefaultAttr) { |
| 602 | case DSA_shared: |
| 603 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 604 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 605 | return DVar; |
| 606 | case DSA_none: |
| 607 | return DVar; |
| 608 | case DSA_unspecified: |
| 609 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 610 | // in a Construct, implicitly determined, p.2] |
| 611 | // In a parallel construct, if no default clause is present, these |
| 612 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 613 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 614 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 615 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | DVar.CKind = OMPC_shared; |
| 617 | return DVar; |
| 618 | } |
| 619 | |
| 620 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 621 | // in a Construct, implicitly determined, p.4] |
| 622 | // In a task construct, if no default clause is present, a variable that in |
| 623 | // the enclosing context is determined to be shared by all implicit tasks |
| 624 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 625 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 626 | DSAVarData DVarTemp; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 627 | auto I = Iter, E = Stack.back().first.rend(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 628 | do { |
| 629 | ++I; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 630 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 631 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 632 | // In a task construct, if no default clause is present, a variable |
| 633 | // whose data-sharing attribute is not determined by the rules above is |
| 634 | // firstprivate. |
| 635 | DVarTemp = getDSA(I, D); |
| 636 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 637 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 638 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 639 | return DVar; |
| 640 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 641 | } while (I != E && !isParallelOrTaskRegion(I->Directive)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 642 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 643 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 644 | return DVar; |
| 645 | } |
| 646 | } |
| 647 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 648 | // in a Construct, implicitly determined, p.3] |
| 649 | // For constructs other than task, if no default clause is present, these |
| 650 | // variables inherit their data-sharing attributes from the enclosing |
| 651 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 652 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 655 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 656 | assert(!isStackEmpty() && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 657 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 658 | auto &StackElem = Stack.back().first.back(); |
| 659 | auto It = StackElem.AlignedMap.find(D); |
| 660 | if (It == StackElem.AlignedMap.end()) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 661 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 662 | StackElem.AlignedMap[D] = NewDE; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 663 | return nullptr; |
| 664 | } else { |
| 665 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 666 | return It->second; |
| 667 | } |
| 668 | return nullptr; |
| 669 | } |
| 670 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 671 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 672 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 673 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 674 | auto &StackElem = Stack.back().first.back(); |
| 675 | StackElem.LCVMap.insert( |
| 676 | {D, LCDeclInfo(StackElem.LCVMap.size() + 1, Capture)}); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 679 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 680 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 681 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 682 | auto &StackElem = Stack.back().first.back(); |
| 683 | auto It = StackElem.LCVMap.find(D); |
| 684 | if (It != StackElem.LCVMap.end()) |
| 685 | return It->second; |
| 686 | return {0, nullptr}; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 689 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 690 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 691 | "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 692 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 693 | auto &StackElem = *std::next(Stack.back().first.rbegin()); |
| 694 | auto It = StackElem.LCVMap.find(D); |
| 695 | if (It != StackElem.LCVMap.end()) |
| 696 | return It->second; |
| 697 | return {0, nullptr}; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 700 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 701 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 702 | "Data-sharing attributes stack is empty"); |
| 703 | auto &StackElem = *std::next(Stack.back().first.rbegin()); |
| 704 | if (StackElem.LCVMap.size() < I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 705 | return nullptr; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 706 | for (auto &Pair : StackElem.LCVMap) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 707 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 708 | return Pair.first; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 709 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 712 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 713 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 714 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 715 | if (A == OMPC_threadprivate) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 716 | auto &Data = Threadprivates[D]; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 717 | Data.Attributes = A; |
| 718 | Data.RefExpr.setPointer(E); |
| 719 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 720 | } else { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 721 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| 722 | auto &Data = Stack.back().first.back().SharingMap[D]; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 723 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 724 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 725 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 726 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 727 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 728 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 729 | return; |
| 730 | } |
| 731 | const bool IsLastprivate = |
| 732 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 733 | Data.Attributes = A; |
| 734 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 735 | Data.PrivateCopy = PrivateCopy; |
| 736 | if (PrivateCopy) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 737 | auto &Data = Stack.back().first.back().SharingMap[PrivateCopy->getDecl()]; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 738 | Data.Attributes = A; |
| 739 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 740 | Data.PrivateCopy = nullptr; |
| 741 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 745 | void DSAStackTy::addReductionData(ValueDecl *D, SourceRange SR, |
| 746 | BinaryOperatorKind BOK) { |
| 747 | D = getCanonicalDecl(D); |
| 748 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| 749 | auto &Data = Stack.back().first.back().SharingMap[D]; |
| 750 | assert( |
| 751 | Data.Attributes == OMPC_reduction && |
| 752 | "Additional reduction info may be specified only for reduction items."); |
| 753 | auto &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| 754 | assert(ReductionData.ReductionRange.isInvalid() && |
| 755 | "Additional reduction info may be specified only once for reduction " |
| 756 | "items."); |
| 757 | ReductionData.set(BOK, SR); |
| 758 | } |
| 759 | |
| 760 | void DSAStackTy::addReductionData(ValueDecl *D, SourceRange SR, |
| 761 | const Expr *ReductionRef) { |
| 762 | D = getCanonicalDecl(D); |
| 763 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| 764 | auto &Data = Stack.back().first.back().SharingMap[D]; |
| 765 | assert( |
| 766 | Data.Attributes == OMPC_reduction && |
| 767 | "Additional reduction info may be specified only for reduction items."); |
| 768 | auto &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| 769 | assert(ReductionData.ReductionRange.isInvalid() && |
| 770 | "Additional reduction info may be specified only once for reduction " |
| 771 | "items."); |
| 772 | ReductionData.set(ReductionRef, SR); |
| 773 | } |
| 774 | |
| 775 | bool DSAStackTy::getTopMostReductionData(ValueDecl *D, SourceRange &SR, |
| 776 | BinaryOperatorKind &BOK) { |
| 777 | D = getCanonicalDecl(D); |
| 778 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 779 | "Data-sharing attributes stack is empty or has only 1 region."); |
| 780 | for (auto I = std::next(Stack.back().first.rbegin(), 0), |
| 781 | E = Stack.back().first.rend(); |
| 782 | I != E; std::advance(I, 1)) { |
| 783 | auto &Data = I->SharingMap[D]; |
| 784 | if (Data.Attributes != OMPC_reduction) |
| 785 | continue; |
| 786 | auto &ReductionData = I->ReductionMap[D]; |
| 787 | if (!ReductionData.ReductionOp || |
| 788 | ReductionData.ReductionOp.is<const Expr *>()) |
| 789 | return false; |
| 790 | SR = ReductionData.ReductionRange; |
| 791 | BOK = ReductionData.ReductionOp |
| 792 | .get<llvm::PointerEmbeddedInt<BinaryOperatorKind>>(); |
| 793 | return true; |
| 794 | } |
| 795 | return false; |
| 796 | } |
| 797 | |
| 798 | bool DSAStackTy::getTopMostReductionData(ValueDecl *D, SourceRange &SR, |
| 799 | const Expr *&ReductionRef) { |
| 800 | D = getCanonicalDecl(D); |
| 801 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 802 | "Data-sharing attributes stack is empty or has only 1 region."); |
| 803 | for (auto I = std::next(Stack.back().first.rbegin(), 0), |
| 804 | E = Stack.back().first.rend(); |
| 805 | I != E; std::advance(I, 1)) { |
| 806 | auto &Data = I->SharingMap[D]; |
| 807 | if (Data.Attributes != OMPC_reduction) |
| 808 | continue; |
| 809 | auto &ReductionData = I->ReductionMap[D]; |
| 810 | if (!ReductionData.ReductionOp || |
| 811 | !ReductionData.ReductionOp.is<const Expr *>()) |
| 812 | return false; |
| 813 | SR = ReductionData.ReductionRange; |
| 814 | ReductionRef = ReductionData.ReductionOp.get<const Expr *>(); |
| 815 | return true; |
| 816 | } |
| 817 | return false; |
| 818 | } |
| 819 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 820 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 821 | D = D->getCanonicalDecl(); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 822 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 823 | reverse_iterator I = Iter, E = Stack.back().first.rend(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 824 | Scope *TopScope = nullptr; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 825 | while (I != E && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 826 | ++I; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 827 | if (I == E) |
| 828 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 829 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 830 | Scope *CurScope = getCurScope(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 831 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 832 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 833 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 834 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 835 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 838 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 839 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 840 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 841 | DeclContext *DC = SemaRef.CurContext; |
| 842 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 843 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 844 | VarDecl *Decl = |
| 845 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 846 | if (Attrs) { |
| 847 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 848 | I != E; ++I) |
| 849 | Decl->addAttr(*I); |
| 850 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 851 | Decl->setImplicit(); |
| 852 | return Decl; |
| 853 | } |
| 854 | |
| 855 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 856 | SourceLocation Loc, |
| 857 | bool RefersToCapture = false) { |
| 858 | D->setReferenced(); |
| 859 | D->markUsed(S.Context); |
| 860 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 861 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 862 | VK_LValue); |
| 863 | } |
| 864 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 865 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 866 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 867 | DSAVarData DVar; |
| 868 | |
| 869 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 870 | // in a Construct, C/C++, predetermined, p.1] |
| 871 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 872 | auto *VD = dyn_cast<VarDecl>(D); |
| 873 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 874 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 875 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 876 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 877 | (VD && VD->getStorageClass() == SC_Register && |
| 878 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 879 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 880 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 881 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 882 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 883 | auto TI = Threadprivates.find(D); |
| 884 | if (TI != Threadprivates.end()) { |
| 885 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 886 | DVar.CKind = OMPC_threadprivate; |
| 887 | return DVar; |
| 888 | } |
| 889 | |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 890 | if (isStackEmpty()) |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 891 | // Not in OpenMP execution region and top scope was already checked. |
| 892 | return DVar; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 893 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 894 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 895 | // in a Construct, C/C++, predetermined, p.4] |
| 896 | // Static data members are shared. |
| 897 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 898 | // in a Construct, C/C++, predetermined, p.7] |
| 899 | // Variables with static storage duration that are declared in a scope |
| 900 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 901 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 902 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 903 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 904 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 905 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 906 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 907 | DVar.CKind = OMPC_shared; |
| 908 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 912 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 913 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 914 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 915 | // in a Construct, C/C++, predetermined, p.6] |
| 916 | // Variables with const qualified type having no mutable member are |
| 917 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 918 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 919 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 920 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 921 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 922 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 923 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 924 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 925 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 926 | // Variables with const-qualified type having no mutable member may be |
| 927 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 928 | DSAVarData DVarTemp = hasDSA( |
| 929 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 930 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 931 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 932 | return DVar; |
| 933 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 934 | DVar.CKind = OMPC_shared; |
| 935 | return DVar; |
| 936 | } |
| 937 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 938 | // Explicitly specified attributes and local variables with predetermined |
| 939 | // attributes. |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 940 | auto I = Stack.back().first.rbegin(); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 941 | auto EndI = Stack.back().first.rend(); |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 942 | if (FromParent && I != EndI) |
| 943 | std::advance(I, 1); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 944 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 945 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 946 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 947 | DVar.CKind = I->SharingMap[D].Attributes; |
| 948 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 949 | DVar.DKind = I->Directive; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return DVar; |
| 953 | } |
| 954 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 955 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 956 | bool FromParent) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 957 | if (isStackEmpty()) { |
| 958 | StackTy::reverse_iterator I; |
| 959 | return getDSA(I, D); |
| 960 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 961 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 962 | auto StartI = Stack.back().first.rbegin(); |
| 963 | auto EndI = Stack.back().first.rend(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 964 | if (FromParent && StartI != EndI) |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 965 | std::advance(StartI, 1); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 966 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 969 | DSAStackTy::DSAVarData |
| 970 | DSAStackTy::hasDSA(ValueDecl *D, |
| 971 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 972 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 973 | bool FromParent) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 974 | if (isStackEmpty()) |
| 975 | return {}; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 976 | D = getCanonicalDecl(D); |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 977 | auto I = Stack.back().first.rbegin(); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 978 | auto EndI = Stack.back().first.rend(); |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 979 | if (FromParent && I != EndI) |
Alexey Bataev | 0e6fc1c | 2017-04-27 14:46:26 +0000 | [diff] [blame] | 980 | std::advance(I, 1); |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 981 | for (; I != EndI; std::advance(I, 1)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 982 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 983 | continue; |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 984 | auto NewI = I; |
| 985 | DSAVarData DVar = getDSA(NewI, D); |
| 986 | if (I == NewI && CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 987 | return DVar; |
Alexey Bataev | 60859c0 | 2017-04-27 15:10:33 +0000 | [diff] [blame] | 988 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 989 | return {}; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 992 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 993 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 994 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 995 | bool FromParent) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 996 | if (isStackEmpty()) |
| 997 | return {}; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 998 | D = getCanonicalDecl(D); |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 999 | auto StartI = Stack.back().first.rbegin(); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1000 | auto EndI = Stack.back().first.rend(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1001 | if (FromParent && StartI != EndI) |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1002 | std::advance(StartI, 1); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1003 | if (StartI == EndI || !DPred(StartI->Directive)) |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1004 | return {}; |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1005 | auto NewI = StartI; |
| 1006 | DSAVarData DVar = getDSA(NewI, D); |
| 1007 | return (NewI == StartI && CPred(DVar.CKind)) ? DVar : DSAVarData(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1010 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1011 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1012 | unsigned Level, bool NotLastprivate) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1013 | if (CPred(ClauseKindMode)) |
| 1014 | return true; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1015 | if (isStackEmpty()) |
| 1016 | return false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1017 | D = getCanonicalDecl(D); |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1018 | auto StartI = Stack.back().first.begin(); |
| 1019 | auto EndI = Stack.back().first.end(); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 1020 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1021 | return false; |
| 1022 | std::advance(StartI, Level); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1023 | return (StartI->SharingMap.count(D) > 0) && |
| 1024 | StartI->SharingMap[D].RefExpr.getPointer() && |
| 1025 | CPred(StartI->SharingMap[D].Attributes) && |
| 1026 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1029 | bool DSAStackTy::hasExplicitDirective( |
| 1030 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 1031 | unsigned Level) { |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1032 | if (isStackEmpty()) |
| 1033 | return false; |
| 1034 | auto StartI = Stack.back().first.begin(); |
| 1035 | auto EndI = Stack.back().first.end(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1036 | if (std::distance(StartI, EndI) <= (int)Level) |
| 1037 | return false; |
| 1038 | std::advance(StartI, Level); |
| 1039 | return DPred(StartI->Directive); |
| 1040 | } |
| 1041 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1042 | bool DSAStackTy::hasDirective( |
| 1043 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 1044 | const DeclarationNameInfo &, SourceLocation)> |
| 1045 | &DPred, |
| 1046 | bool FromParent) { |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1047 | // We look only in the enclosing region. |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1048 | if (isStackEmpty()) |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1049 | return false; |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1050 | auto StartI = std::next(Stack.back().first.rbegin()); |
| 1051 | auto EndI = Stack.back().first.rend(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1052 | if (FromParent && StartI != EndI) |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1053 | StartI = std::next(StartI); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1054 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 1055 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 1056 | return true; |
| 1057 | } |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1061 | void Sema::InitDataSharingAttributesStack() { |
| 1062 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 1063 | } |
| 1064 | |
| 1065 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 1066 | |
Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1067 | void Sema::pushOpenMPFunctionRegion() { |
| 1068 | DSAStack->pushFunction(); |
| 1069 | } |
| 1070 | |
| 1071 | void Sema::popOpenMPFunctionRegion(const FunctionScopeInfo *OldFSI) { |
| 1072 | DSAStack->popFunction(OldFSI); |
| 1073 | } |
| 1074 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1075 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1076 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1077 | |
| 1078 | auto &Ctx = getASTContext(); |
| 1079 | bool IsByRef = true; |
| 1080 | |
| 1081 | // Find the directive that is associated with the provided scope. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1082 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1083 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1084 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1085 | // This table summarizes how a given variable should be passed to the device |
| 1086 | // given its type and the clauses where it appears. This table is based on |
| 1087 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 1088 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 1089 | // |
| 1090 | // ========================================================================= |
| 1091 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 1092 | // | |(tofrom:scalar)| | pvt | | | | |
| 1093 | // ========================================================================= |
| 1094 | // | scl | | | | - | | bycopy| |
| 1095 | // | scl | | - | x | - | - | bycopy| |
| 1096 | // | scl | | x | - | - | - | null | |
| 1097 | // | scl | x | | | - | | byref | |
| 1098 | // | scl | x | - | x | - | - | bycopy| |
| 1099 | // | scl | x | x | - | - | - | null | |
| 1100 | // | scl | | - | - | - | x | byref | |
| 1101 | // | scl | x | - | - | - | x | byref | |
| 1102 | // |
| 1103 | // | agg | n.a. | | | - | | byref | |
| 1104 | // | agg | n.a. | - | x | - | - | byref | |
| 1105 | // | agg | n.a. | x | - | - | - | null | |
| 1106 | // | agg | n.a. | - | - | - | x | byref | |
| 1107 | // | agg | n.a. | - | - | - | x[] | byref | |
| 1108 | // |
| 1109 | // | ptr | n.a. | | | - | | bycopy| |
| 1110 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 1111 | // | ptr | n.a. | x | - | - | - | null | |
| 1112 | // | ptr | n.a. | - | - | - | x | byref | |
| 1113 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 1114 | // | ptr | n.a. | - | - | x | | bycopy| |
| 1115 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 1116 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 1117 | // ========================================================================= |
| 1118 | // Legend: |
| 1119 | // scl - scalar |
| 1120 | // ptr - pointer |
| 1121 | // agg - aggregate |
| 1122 | // x - applies |
| 1123 | // - - invalid in this combination |
| 1124 | // [] - mapped with an array section |
| 1125 | // byref - should be mapped by reference |
| 1126 | // byval - should be mapped by value |
| 1127 | // null - initialize a local variable to null on the device |
| 1128 | // |
| 1129 | // Observations: |
| 1130 | // - All scalar declarations that show up in a map clause have to be passed |
| 1131 | // by reference, because they may have been mapped in the enclosing data |
| 1132 | // environment. |
| 1133 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 1134 | // passed by reference, regardless the result in the table above. |
| 1135 | // - For pointers mapped by value that have either an implicit map or an |
| 1136 | // array section, the runtime library may pass the NULL value to the |
| 1137 | // device instead of the value passed to it by the compiler. |
| 1138 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1139 | if (Ty->isReferenceType()) |
| 1140 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1141 | |
| 1142 | // Locate map clauses and see if the variable being captured is referred to |
| 1143 | // in any of those clauses. Here we only care about variables, not fields, |
| 1144 | // because fields are part of aggregates. |
| 1145 | bool IsVariableUsedInMapClause = false; |
| 1146 | bool IsVariableAssociatedWithSection = false; |
| 1147 | |
Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 1148 | DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| 1149 | D, Level, [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1150 | MapExprComponents, |
| 1151 | OpenMPClauseKind WhereFoundClauseKind) { |
| 1152 | // Only the map clause information influences how a variable is |
| 1153 | // captured. E.g. is_device_ptr does not require changing the default |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 1154 | // behavior. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1155 | if (WhereFoundClauseKind != OMPC_map) |
| 1156 | return false; |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1157 | |
| 1158 | auto EI = MapExprComponents.rbegin(); |
| 1159 | auto EE = MapExprComponents.rend(); |
| 1160 | |
| 1161 | assert(EI != EE && "Invalid map expression!"); |
| 1162 | |
| 1163 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 1164 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 1165 | |
| 1166 | ++EI; |
| 1167 | if (EI == EE) |
| 1168 | return false; |
| 1169 | |
| 1170 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 1171 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 1172 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 1173 | IsVariableAssociatedWithSection = true; |
| 1174 | // There is nothing more we need to know about this variable. |
| 1175 | return true; |
| 1176 | } |
| 1177 | |
| 1178 | // Keep looking for more map info. |
| 1179 | return false; |
| 1180 | }); |
| 1181 | |
| 1182 | if (IsVariableUsedInMapClause) { |
| 1183 | // If variable is identified in a map clause it is always captured by |
| 1184 | // reference except if it is a pointer that is dereferenced somehow. |
| 1185 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 1186 | } else { |
| 1187 | // By default, all the data that has a scalar type is mapped by copy. |
| 1188 | IsByRef = !Ty->isScalarType(); |
| 1189 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1192 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 1193 | IsByRef = !DSAStack->hasExplicitDSA( |
| 1194 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 1195 | Level, /*NotLastprivate=*/true); |
| 1196 | } |
| 1197 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1198 | // 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] | 1199 | // and alignment, because the runtime library only deals with uintptr types. |
| 1200 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 1201 | // instead. |
| 1202 | if (!IsByRef && |
| 1203 | (Ctx.getTypeSizeInChars(Ty) > |
| 1204 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1205 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1206 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1207 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1208 | |
| 1209 | return IsByRef; |
| 1210 | } |
| 1211 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1212 | unsigned Sema::getOpenMPNestingLevel() const { |
| 1213 | assert(getLangOpts().OpenMP); |
| 1214 | return DSAStack->getNestingLevel(); |
| 1215 | } |
| 1216 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1217 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1218 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1219 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1220 | |
| 1221 | // If we are attempting to capture a global variable in a directive with |
| 1222 | // 'target' we return true so that this global is also mapped to the device. |
| 1223 | // |
| 1224 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 1225 | // then it should not be captured. Therefore, an extra check has to be |
| 1226 | // inserted here once support for 'declare target' is added. |
| 1227 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1228 | auto *VD = dyn_cast<VarDecl>(D); |
| 1229 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1230 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1231 | !DSAStack->isClauseParsingMode()) |
| 1232 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1233 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1234 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1235 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1236 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1237 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1238 | false)) |
| 1239 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1242 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1243 | (!DSAStack->isClauseParsingMode() || |
| 1244 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1245 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1246 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1247 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1248 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1249 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1250 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1251 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1252 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1253 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1254 | DVarPrivate = DSAStack->hasDSA( |
| 1255 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1256 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1257 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1258 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1259 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1260 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1263 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1264 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1265 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1266 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1269 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1270 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1271 | // Return true if the current level is no longer enclosed in a target region. |
| 1272 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1273 | auto *VD = dyn_cast<VarDecl>(D); |
| 1274 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1275 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1276 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1279 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1280 | |
| 1281 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1282 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1283 | Scope *CurScope, SourceLocation Loc) { |
| 1284 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 1285 | PushExpressionEvaluationContext( |
| 1286 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1289 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1290 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1293 | void Sema::EndOpenMPClause() { |
| 1294 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1297 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1298 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1299 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1300 | // clause requires an accessible, unambiguous default constructor for the |
| 1301 | // class type, unless the list item is also specified in a firstprivate |
| 1302 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1303 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1304 | for (auto *C : D->clauses()) { |
| 1305 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1306 | SmallVector<Expr *, 8> PrivateCopies; |
| 1307 | for (auto *DE : Clause->varlists()) { |
| 1308 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1309 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1310 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1311 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1312 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1313 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1314 | QualType Type = VD->getType().getNonReferenceType(); |
| 1315 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1316 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1317 | // Generate helper private variable and initialize it with the |
| 1318 | // default value. The address of the original variable is replaced |
| 1319 | // by the address of the new private variable in CodeGen. This new |
| 1320 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1321 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1322 | auto *VDPrivate = buildVarDecl( |
| 1323 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1324 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1325 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1326 | if (VDPrivate->isInvalidDecl()) |
| 1327 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1328 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1329 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1330 | } else { |
| 1331 | // The variable is also a firstprivate, so initialization sequence |
| 1332 | // for private copy is generated already. |
| 1333 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1334 | } |
| 1335 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1336 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1337 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1338 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1343 | DSAStack->pop(); |
| 1344 | DiscardCleanupsInEvaluationContext(); |
| 1345 | PopExpressionEvaluationContext(); |
| 1346 | } |
| 1347 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1348 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1349 | Expr *NumIterations, Sema &SemaRef, |
| 1350 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1351 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1352 | namespace { |
| 1353 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1354 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1355 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1356 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1357 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1358 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1359 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1360 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1361 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1362 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1363 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1364 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1365 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1366 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1367 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1368 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1369 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1370 | |
| 1371 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1372 | private: |
| 1373 | Sema &SemaRef; |
| 1374 | |
| 1375 | public: |
| 1376 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1377 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1378 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1379 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1380 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1381 | SemaRef.getCurScope()); |
| 1382 | } |
| 1383 | return false; |
| 1384 | } |
| 1385 | }; |
| 1386 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1387 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1388 | |
| 1389 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1390 | CXXScopeSpec &ScopeSpec, |
| 1391 | const DeclarationNameInfo &Id) { |
| 1392 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1393 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1394 | |
| 1395 | if (Lookup.isAmbiguous()) |
| 1396 | return ExprError(); |
| 1397 | |
| 1398 | VarDecl *VD; |
| 1399 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1400 | if (TypoCorrection Corrected = CorrectTypo( |
| 1401 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1402 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1403 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1404 | PDiag(Lookup.empty() |
| 1405 | ? diag::err_undeclared_var_use_suggest |
| 1406 | : diag::err_omp_expected_var_arg_suggest) |
| 1407 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1408 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1409 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1410 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1411 | : diag::err_omp_expected_var_arg) |
| 1412 | << Id.getName(); |
| 1413 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1414 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1415 | } else { |
| 1416 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1417 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1418 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1419 | return ExprError(); |
| 1420 | } |
| 1421 | } |
| 1422 | Lookup.suppressDiagnostics(); |
| 1423 | |
| 1424 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1425 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1426 | if (!VD->hasGlobalStorage()) { |
| 1427 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1428 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1429 | bool IsDecl = |
| 1430 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1431 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1432 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1433 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1434 | return ExprError(); |
| 1435 | } |
| 1436 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1437 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1438 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1439 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1440 | // A threadprivate directive for file-scope variables must appear outside |
| 1441 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1442 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1443 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1444 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1445 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1446 | bool IsDecl = |
| 1447 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1448 | Diag(VD->getLocation(), |
| 1449 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1450 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1451 | return ExprError(); |
| 1452 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1453 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1454 | // A threadprivate directive for static class member variables must appear |
| 1455 | // in the class definition, in the same scope in which the member |
| 1456 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1457 | if (CanonicalVD->isStaticDataMember() && |
| 1458 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1459 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1460 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1461 | bool IsDecl = |
| 1462 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1463 | Diag(VD->getLocation(), |
| 1464 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1465 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1466 | return ExprError(); |
| 1467 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1468 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1469 | // A threadprivate directive for namespace-scope variables must appear |
| 1470 | // outside any definition or declaration other than the namespace |
| 1471 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1472 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1473 | (!getCurLexicalContext()->isFileContext() || |
| 1474 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1475 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1476 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1477 | bool IsDecl = |
| 1478 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1479 | Diag(VD->getLocation(), |
| 1480 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1481 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1482 | return ExprError(); |
| 1483 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1484 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1485 | // A threadprivate directive for static block-scope variables must appear |
| 1486 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1487 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1488 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1489 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1490 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1491 | bool IsDecl = |
| 1492 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1493 | Diag(VD->getLocation(), |
| 1494 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1495 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1496 | return ExprError(); |
| 1497 | } |
| 1498 | |
| 1499 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1500 | // A threadprivate directive must lexically precede all references to any |
| 1501 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1502 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1503 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1504 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1505 | return ExprError(); |
| 1506 | } |
| 1507 | |
| 1508 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1509 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1510 | SourceLocation(), VD, |
| 1511 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1512 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1515 | Sema::DeclGroupPtrTy |
| 1516 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1517 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1518 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1519 | CurContext->addDecl(D); |
| 1520 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1521 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1522 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1525 | namespace { |
| 1526 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1527 | Sema &SemaRef; |
| 1528 | |
| 1529 | public: |
| 1530 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1531 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1532 | if (VD->hasLocalStorage()) { |
| 1533 | SemaRef.Diag(E->getLocStart(), |
| 1534 | diag::err_omp_local_var_in_threadprivate_init) |
| 1535 | << E->getSourceRange(); |
| 1536 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1537 | << VD << VD->getSourceRange(); |
| 1538 | return true; |
| 1539 | } |
| 1540 | } |
| 1541 | return false; |
| 1542 | } |
| 1543 | bool VisitStmt(const Stmt *S) { |
| 1544 | for (auto Child : S->children()) { |
| 1545 | if (Child && Visit(Child)) |
| 1546 | return true; |
| 1547 | } |
| 1548 | return false; |
| 1549 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1550 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1551 | }; |
| 1552 | } // namespace |
| 1553 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1554 | OMPThreadPrivateDecl * |
| 1555 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1556 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1557 | for (auto &RefExpr : VarList) { |
| 1558 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1559 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1560 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1561 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1562 | // Mark variable as used. |
| 1563 | VD->setReferenced(); |
| 1564 | VD->markUsed(Context); |
| 1565 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1566 | QualType QType = VD->getType(); |
| 1567 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1568 | // It will be analyzed later. |
| 1569 | Vars.push_back(DE); |
| 1570 | continue; |
| 1571 | } |
| 1572 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1573 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1574 | // A threadprivate variable must not have an incomplete type. |
| 1575 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1576 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1577 | continue; |
| 1578 | } |
| 1579 | |
| 1580 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1581 | // A threadprivate variable must not have a reference type. |
| 1582 | if (VD->getType()->isReferenceType()) { |
| 1583 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1584 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1585 | bool IsDecl = |
| 1586 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1587 | Diag(VD->getLocation(), |
| 1588 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1589 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1590 | continue; |
| 1591 | } |
| 1592 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1593 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1594 | // the corresponding diagnostic. |
| 1595 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1596 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1597 | getLangOpts().OpenMPUseTLS && |
| 1598 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1599 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1600 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1601 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1602 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1603 | bool IsDecl = |
| 1604 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1605 | Diag(VD->getLocation(), |
| 1606 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1607 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1608 | continue; |
| 1609 | } |
| 1610 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1611 | // Check if initial value of threadprivate variable reference variable with |
| 1612 | // local storage (it is not supported by runtime). |
| 1613 | if (auto Init = VD->getAnyInitializer()) { |
| 1614 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1615 | if (Checker.Visit(Init)) |
| 1616 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1619 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1620 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1621 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1622 | Context, SourceRange(Loc, Loc))); |
| 1623 | if (auto *ML = Context.getASTMutationListener()) |
| 1624 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1625 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1626 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1627 | if (!Vars.empty()) { |
| 1628 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1629 | Vars); |
| 1630 | D->setAccess(AS_public); |
| 1631 | } |
| 1632 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1633 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1634 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1635 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1636 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1637 | bool IsLoopIterVar = false) { |
| 1638 | if (DVar.RefExpr) { |
| 1639 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1640 | << getOpenMPClauseName(DVar.CKind); |
| 1641 | return; |
| 1642 | } |
| 1643 | enum { |
| 1644 | PDSA_StaticMemberShared, |
| 1645 | PDSA_StaticLocalVarShared, |
| 1646 | PDSA_LoopIterVarPrivate, |
| 1647 | PDSA_LoopIterVarLinear, |
| 1648 | PDSA_LoopIterVarLastprivate, |
| 1649 | PDSA_ConstVarShared, |
| 1650 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1651 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1652 | PDSA_LocalVarPrivate, |
| 1653 | PDSA_Implicit |
| 1654 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1655 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1656 | auto ReportLoc = D->getLocation(); |
| 1657 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1658 | if (IsLoopIterVar) { |
| 1659 | if (DVar.CKind == OMPC_private) |
| 1660 | Reason = PDSA_LoopIterVarPrivate; |
| 1661 | else if (DVar.CKind == OMPC_lastprivate) |
| 1662 | Reason = PDSA_LoopIterVarLastprivate; |
| 1663 | else |
| 1664 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1665 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1666 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1667 | Reason = PDSA_TaskVarFirstprivate; |
| 1668 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1669 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1670 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1671 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1672 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1673 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1674 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1675 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1676 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1677 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1678 | ReportHint = true; |
| 1679 | Reason = PDSA_LocalVarPrivate; |
| 1680 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1681 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1682 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1683 | << Reason << ReportHint |
| 1684 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1685 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1686 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1687 | << getOpenMPClauseName(DVar.CKind); |
| 1688 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1691 | namespace { |
| 1692 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1693 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1694 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1695 | bool ErrorFound; |
| 1696 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1697 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1698 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1699 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1700 | public: |
| 1701 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1702 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1703 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1704 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1705 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1706 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1707 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1708 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1709 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1710 | auto DVar = Stack->getTopDSA(VD, false); |
| 1711 | // Check if the variable has explicit DSA set and stop analysis if it so. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1712 | if (DVar.RefExpr) |
| 1713 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1714 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1715 | auto ELoc = E->getExprLoc(); |
| 1716 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1717 | // The default(none) clause requires that each variable that is referenced |
| 1718 | // in the construct, and does not have a predetermined data-sharing |
| 1719 | // attribute, must have its data-sharing attribute explicitly determined |
| 1720 | // by being listed in a data-sharing attribute clause. |
| 1721 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1722 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1723 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1724 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1725 | return; |
| 1726 | } |
| 1727 | |
| 1728 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1729 | // A list item that appears in a reduction clause of the innermost |
| 1730 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1731 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1732 | DVar = Stack->hasInnermostDSA( |
| 1733 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1734 | [](OpenMPDirectiveKind K) -> bool { |
| 1735 | return isOpenMPParallelDirective(K) || |
| 1736 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1737 | }, |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1738 | /*FromParent=*/true); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1739 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1740 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1741 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1742 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1743 | return; |
| 1744 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1745 | |
| 1746 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1747 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1748 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1749 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1750 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1751 | } |
| 1752 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1753 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1754 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1755 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1756 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1757 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1758 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1759 | auto DVar = Stack->getTopDSA(FD, false); |
| 1760 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1761 | // so. |
| 1762 | if (DVar.RefExpr) |
| 1763 | return; |
| 1764 | |
| 1765 | auto ELoc = E->getExprLoc(); |
| 1766 | auto DKind = Stack->getCurrentDirective(); |
| 1767 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1768 | // A list item that appears in a reduction clause of the innermost |
| 1769 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1770 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1771 | DVar = Stack->hasInnermostDSA( |
| 1772 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1773 | [](OpenMPDirectiveKind K) -> bool { |
| 1774 | return isOpenMPParallelDirective(K) || |
| 1775 | isOpenMPWorksharingDirective(K) || |
| 1776 | isOpenMPTeamsDirective(K); |
| 1777 | }, |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1778 | /*FromParent=*/true); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1779 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1780 | ErrorFound = true; |
| 1781 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1782 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1783 | return; |
| 1784 | } |
| 1785 | |
| 1786 | // Define implicit data-sharing attributes for task. |
| 1787 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1788 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1789 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1790 | ImplicitFirstprivate.push_back(E); |
| 1791 | } |
Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 1792 | } else |
| 1793 | Visit(E->getBase()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1794 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1795 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1796 | for (auto *C : S->clauses()) { |
| 1797 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1798 | // for task directives. |
| 1799 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1800 | for (auto *CC : C->children()) { |
| 1801 | if (CC) |
| 1802 | Visit(CC); |
| 1803 | } |
| 1804 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1805 | } |
| 1806 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1807 | for (auto *C : S->children()) { |
| 1808 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1809 | Visit(C); |
| 1810 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1811 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1812 | |
| 1813 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1814 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1815 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1816 | return VarsWithInheritedDSA; |
| 1817 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1818 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1819 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1820 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1821 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1822 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1823 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1824 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1825 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1826 | case OMPD_parallel: |
| 1827 | case OMPD_parallel_for: |
| 1828 | case OMPD_parallel_for_simd: |
| 1829 | case OMPD_parallel_sections: |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1830 | case OMPD_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1831 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1832 | QualType KmpInt32PtrTy = |
| 1833 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1834 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1835 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1836 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1837 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1838 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1839 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1840 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1841 | break; |
| 1842 | } |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1843 | case OMPD_target_teams: |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1844 | case OMPD_target_parallel: { |
| 1845 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 1846 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1847 | }; |
| 1848 | // Start a captured region for 'target' with no implicit parameters. |
| 1849 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1850 | ParamsTarget); |
| 1851 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1852 | QualType KmpInt32PtrTy = |
| 1853 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1854 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1855 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1856 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1857 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1858 | }; |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1859 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 1860 | // the same implicit parameters. |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1861 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1862 | ParamsTeamsOrParallel); |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1863 | break; |
| 1864 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1865 | case OMPD_simd: |
| 1866 | case OMPD_for: |
| 1867 | case OMPD_for_simd: |
| 1868 | case OMPD_sections: |
| 1869 | case OMPD_section: |
| 1870 | case OMPD_single: |
| 1871 | case OMPD_master: |
| 1872 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1873 | case OMPD_taskgroup: |
| 1874 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1875 | case OMPD_ordered: |
| 1876 | case OMPD_atomic: |
| 1877 | case OMPD_target_data: |
| 1878 | case OMPD_target: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1879 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1880 | case OMPD_target_parallel_for_simd: |
| 1881 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1882 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1883 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1884 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1885 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1886 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1887 | break; |
| 1888 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1889 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1890 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1891 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1892 | FunctionProtoType::ExtProtoInfo EPI; |
| 1893 | EPI.Variadic = true; |
| 1894 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1895 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1896 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1897 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1898 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1899 | std::make_pair(".copy_fn.", |
| 1900 | Context.getPointerType(CopyFnType).withConst()), |
| 1901 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1902 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1903 | }; |
| 1904 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1905 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1906 | // Mark this captured region as inlined, because we don't use outlined |
| 1907 | // function directly. |
| 1908 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1909 | AlwaysInlineAttr::CreateImplicit( |
| 1910 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1913 | case OMPD_taskloop: |
| 1914 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1915 | QualType KmpInt32Ty = |
| 1916 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1917 | QualType KmpUInt64Ty = |
| 1918 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1919 | QualType KmpInt64Ty = |
| 1920 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1921 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1922 | FunctionProtoType::ExtProtoInfo EPI; |
| 1923 | EPI.Variadic = true; |
| 1924 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1925 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1926 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1927 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1928 | std::make_pair(".privates.", |
| 1929 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1930 | std::make_pair( |
| 1931 | ".copy_fn.", |
| 1932 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1933 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1934 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1935 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1936 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 1937 | std::make_pair(".reductions.", |
| 1938 | Context.VoidPtrTy.withConst().withRestrict()), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1939 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1940 | }; |
| 1941 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1942 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1943 | // Mark this captured region as inlined, because we don't use outlined |
| 1944 | // function directly. |
| 1945 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1946 | AlwaysInlineAttr::CreateImplicit( |
| 1947 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1948 | break; |
| 1949 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1950 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1951 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1952 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1953 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1954 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1955 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1956 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1957 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1958 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1959 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1960 | case OMPD_target_teams_distribute_simd: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1961 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1962 | QualType KmpInt32PtrTy = |
| 1963 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1964 | Sema::CapturedParamNameType Params[] = { |
| 1965 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1966 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1967 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1968 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1969 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1970 | }; |
| 1971 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1972 | Params); |
| 1973 | break; |
| 1974 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1975 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1976 | case OMPD_taskyield: |
| 1977 | case OMPD_barrier: |
| 1978 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1979 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1980 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1981 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1982 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1983 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1984 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1985 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1986 | case OMPD_declare_target: |
| 1987 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1988 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1989 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1990 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1991 | llvm_unreachable("Unknown OpenMP directive"); |
| 1992 | } |
| 1993 | } |
| 1994 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1995 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 1996 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1997 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 1998 | return CaptureRegions.size(); |
| 1999 | } |
| 2000 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2001 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2002 | Expr *CaptureExpr, bool WithInit, |
| 2003 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2004 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2005 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2006 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2007 | QualType Ty = Init->getType(); |
| 2008 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 2009 | if (S.getLangOpts().CPlusPlus) |
| 2010 | Ty = C.getLValueReferenceType(Ty); |
| 2011 | else { |
| 2012 | Ty = C.getPointerType(Ty); |
| 2013 | ExprResult Res = |
| 2014 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 2015 | if (!Res.isUsable()) |
| 2016 | return nullptr; |
| 2017 | Init = Res.get(); |
| 2018 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2019 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2020 | } |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 2021 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| 2022 | CaptureExpr->getLocStart()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2023 | if (!WithInit) |
| 2024 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2025 | S.CurContext->addHiddenDecl(CED); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 2026 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2027 | return CED; |
| 2028 | } |
| 2029 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2030 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 2031 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 2032 | OMPCapturedExprDecl *CD; |
| 2033 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 2034 | CD = cast<OMPCapturedExprDecl>(VD); |
| 2035 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2036 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 2037 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2038 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 2039 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2042 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 2043 | if (!Ref) { |
| 2044 | auto *CD = |
| 2045 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 2046 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 2047 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 2048 | CaptureExpr->getExprLoc()); |
| 2049 | } |
| 2050 | ExprResult Res = Ref; |
| 2051 | if (!S.getLangOpts().CPlusPlus && |
| 2052 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 2053 | Ref->getType()->isPointerType()) |
| 2054 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 2055 | if (!Res.isUsable()) |
| 2056 | return ExprError(); |
| 2057 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2060 | namespace { |
| 2061 | // OpenMP directives parsed in this section are represented as a |
| 2062 | // CapturedStatement with an associated statement. If a syntax error |
| 2063 | // is detected during the parsing of the associated statement, the |
| 2064 | // compiler must abort processing and close the CapturedStatement. |
| 2065 | // |
| 2066 | // Combined directives such as 'target parallel' have more than one |
| 2067 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 2068 | // of all the nested CapturedStatements when an error is found. |
| 2069 | class CaptureRegionUnwinderRAII { |
| 2070 | private: |
| 2071 | Sema &S; |
| 2072 | bool &ErrorFound; |
| 2073 | OpenMPDirectiveKind DKind; |
| 2074 | |
| 2075 | public: |
| 2076 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 2077 | OpenMPDirectiveKind DKind) |
| 2078 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 2079 | ~CaptureRegionUnwinderRAII() { |
| 2080 | if (ErrorFound) { |
| 2081 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 2082 | while (--ThisCaptureLevel >= 0) |
| 2083 | S.ActOnCapturedRegionError(); |
| 2084 | } |
| 2085 | } |
| 2086 | }; |
| 2087 | } // namespace |
| 2088 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2089 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 2090 | ArrayRef<OMPClause *> Clauses) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2091 | bool ErrorFound = false; |
| 2092 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 2093 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2094 | if (!S.isUsable()) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2095 | ErrorFound = true; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2096 | return StmtError(); |
| 2097 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2098 | |
| 2099 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2100 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2101 | SmallVector<OMPLinearClause *, 4> LCs; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2102 | SmallVector<OMPClauseWithPreInit *, 8> PICs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 2103 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2104 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 2105 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 2106 | Clause->getClauseKind() == OMPC_copyprivate || |
| 2107 | (getLangOpts().OpenMPUseTLS && |
| 2108 | getASTContext().getTargetInfo().isTLSSupported() && |
| 2109 | Clause->getClauseKind() == OMPC_copyin)) { |
| 2110 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 2111 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2112 | for (auto *VarRef : Clause->children()) { |
| 2113 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 2114 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2115 | } |
| 2116 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 2117 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2118 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2119 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 2120 | PICs.push_back(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2121 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 2122 | if (auto *E = C->getPostUpdateExpr()) |
| 2123 | MarkDeclarationsReferencedInExpr(E); |
| 2124 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2125 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2126 | if (Clause->getClauseKind() == OMPC_schedule) |
| 2127 | SC = cast<OMPScheduleClause>(Clause); |
| 2128 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2129 | OC = cast<OMPOrderedClause>(Clause); |
| 2130 | else if (Clause->getClauseKind() == OMPC_linear) |
| 2131 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 2132 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2133 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 2134 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 2135 | // specified. |
| 2136 | if (SC && |
| 2137 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 2138 | SC->getSecondScheduleModifier() == |
| 2139 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 2140 | OC) { |
| 2141 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 2142 | ? SC->getFirstScheduleModifierLoc() |
| 2143 | : SC->getSecondScheduleModifierLoc(), |
| 2144 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 2145 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 2146 | ErrorFound = true; |
| 2147 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2148 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 2149 | for (auto *C : LCs) { |
| 2150 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 2151 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 2152 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2153 | ErrorFound = true; |
| 2154 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 2155 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 2156 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 2157 | OC->getNumForLoops()) { |
| 2158 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 2159 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 2160 | ErrorFound = true; |
| 2161 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2162 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2163 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2164 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2165 | StmtResult SR = S; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2166 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 2167 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| 2168 | for (auto ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| 2169 | // Mark all variables in private list clauses as used in inner region. |
| 2170 | // Required for proper codegen of combined directives. |
| 2171 | // TODO: add processing for other clauses. |
| 2172 | if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 2173 | for (auto *C : PICs) { |
| 2174 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 2175 | // Find the particular capture region for the clause if the |
| 2176 | // directive is a combined one with multiple capture regions. |
| 2177 | // If the directive is not a combined one, the capture region |
| 2178 | // associated with the clause is OMPD_unknown and is generated |
| 2179 | // only once. |
| 2180 | if (CaptureRegion == ThisCaptureRegion || |
| 2181 | CaptureRegion == OMPD_unknown) { |
| 2182 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 2183 | for (auto *D : DS->decls()) |
| 2184 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2189 | SR = ActOnCapturedRegionEnd(SR.get()); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 2190 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2191 | return SR; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 2194 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 2195 | OpenMPDirectiveKind CancelRegion, |
| 2196 | SourceLocation StartLoc) { |
| 2197 | // CancelRegion is only needed for cancel and cancellation_point. |
| 2198 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 2199 | return false; |
| 2200 | |
| 2201 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 2202 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 2203 | return false; |
| 2204 | |
| 2205 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 2206 | << getOpenMPDirectiveName(CancelRegion); |
| 2207 | return true; |
| 2208 | } |
| 2209 | |
| 2210 | static bool checkNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2211 | OpenMPDirectiveKind CurrentRegion, |
| 2212 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2213 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2214 | SourceLocation StartLoc) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2215 | if (Stack->getCurScope()) { |
| 2216 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2217 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2218 | bool NestingProhibited = false; |
| 2219 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2220 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2221 | enum { |
| 2222 | NoRecommend, |
| 2223 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2224 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2225 | ShouldBeInTargetRegion, |
| 2226 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2227 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2228 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2229 | // OpenMP [2.16, Nesting of Regions] |
| 2230 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2231 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2232 | // An ordered construct with the simd clause is the only OpenMP |
| 2233 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2234 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2235 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 2236 | // message. |
| 2237 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 2238 | ? diag::err_omp_prohibited_region_simd |
| 2239 | : diag::warn_omp_nesting_simd); |
| 2240 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2241 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2242 | if (ParentRegion == OMPD_atomic) { |
| 2243 | // OpenMP [2.16, Nesting of Regions] |
| 2244 | // OpenMP constructs may not be nested inside an atomic region. |
| 2245 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2246 | return true; |
| 2247 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2248 | if (CurrentRegion == OMPD_section) { |
| 2249 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2250 | // Orphaned section directives are prohibited. That is, the section |
| 2251 | // directives must appear within the sections construct and must not be |
| 2252 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2253 | if (ParentRegion != OMPD_sections && |
| 2254 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2255 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2256 | << (ParentRegion != OMPD_unknown) |
| 2257 | << getOpenMPDirectiveName(ParentRegion); |
| 2258 | return true; |
| 2259 | } |
| 2260 | return false; |
| 2261 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2262 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2263 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2264 | // preconditions). |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2265 | if (ParentRegion == OMPD_unknown && |
| 2266 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2267 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2268 | if (CurrentRegion == OMPD_cancellation_point || |
| 2269 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2270 | // OpenMP [2.16, Nesting of Regions] |
| 2271 | // A cancellation point construct for which construct-type-clause is |
| 2272 | // taskgroup must be nested inside a task construct. A cancellation |
| 2273 | // point construct for which construct-type-clause is not taskgroup must |
| 2274 | // be closely nested inside an OpenMP construct that matches the type |
| 2275 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2276 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2277 | // nested inside a task construct. A cancel construct for which |
| 2278 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2279 | // OpenMP construct that matches the type specified in |
| 2280 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2281 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2282 | !((CancelRegion == OMPD_parallel && |
| 2283 | (ParentRegion == OMPD_parallel || |
| 2284 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2285 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2286 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2287 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2288 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2289 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2290 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2291 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2292 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2293 | // OpenMP [2.16, Nesting of Regions] |
| 2294 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2295 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2296 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2297 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2298 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2299 | // OpenMP [2.16, Nesting of Regions] |
| 2300 | // A critical region may not be nested (closely or otherwise) inside a |
| 2301 | // critical region with the same name. Note that this restriction is not |
| 2302 | // sufficient to prevent deadlock. |
| 2303 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2304 | bool DeadLock = Stack->hasDirective( |
| 2305 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2306 | const DeclarationNameInfo &DNI, |
| 2307 | SourceLocation Loc) -> bool { |
| 2308 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2309 | PreviousCriticalLoc = Loc; |
| 2310 | return true; |
| 2311 | } else |
| 2312 | return false; |
| 2313 | }, |
| 2314 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2315 | if (DeadLock) { |
| 2316 | SemaRef.Diag(StartLoc, |
| 2317 | diag::err_omp_prohibited_region_critical_same_name) |
| 2318 | << CurrentName.getName(); |
| 2319 | if (PreviousCriticalLoc.isValid()) |
| 2320 | SemaRef.Diag(PreviousCriticalLoc, |
| 2321 | diag::note_omp_previous_critical_region); |
| 2322 | return true; |
| 2323 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2324 | } else if (CurrentRegion == OMPD_barrier) { |
| 2325 | // OpenMP [2.16, Nesting of Regions] |
| 2326 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2327 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2328 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2329 | isOpenMPTaskingDirective(ParentRegion) || |
| 2330 | ParentRegion == OMPD_master || |
| 2331 | ParentRegion == OMPD_critical || |
| 2332 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2333 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2334 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2335 | !isOpenMPTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2336 | // OpenMP [2.16, Nesting of Regions] |
| 2337 | // A worksharing region may not be closely nested inside a worksharing, |
| 2338 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2339 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2340 | isOpenMPTaskingDirective(ParentRegion) || |
| 2341 | ParentRegion == OMPD_master || |
| 2342 | ParentRegion == OMPD_critical || |
| 2343 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2344 | Recommend = ShouldBeInParallelRegion; |
| 2345 | } else if (CurrentRegion == OMPD_ordered) { |
| 2346 | // OpenMP [2.16, Nesting of Regions] |
| 2347 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2348 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2349 | // An ordered region must be closely nested inside a loop region (or |
| 2350 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2351 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2352 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2353 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2354 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2355 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2356 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2357 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2358 | Recommend = ShouldBeInOrderedRegion; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2359 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2360 | // OpenMP [2.16, Nesting of Regions] |
| 2361 | // If specified, a teams construct must be contained within a target |
| 2362 | // construct. |
| 2363 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2364 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2365 | Recommend = ShouldBeInTargetRegion; |
| 2366 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2367 | } |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2368 | if (!NestingProhibited && |
| 2369 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2370 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2371 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2372 | // OpenMP [2.16, Nesting of Regions] |
| 2373 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2374 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2375 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2376 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2377 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2378 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2379 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2380 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2381 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2382 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2383 | // The region associated with the distribute construct must be strictly |
| 2384 | // nested inside a teams region |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2385 | NestingProhibited = |
| 2386 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2387 | Recommend = ShouldBeInTeamsRegion; |
| 2388 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2389 | if (!NestingProhibited && |
| 2390 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2391 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2392 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2393 | // If a target, target update, target data, target enter data, or |
| 2394 | // target exit data construct is encountered during execution of a |
| 2395 | // target region, the behavior is unspecified. |
| 2396 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2397 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 2398 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2399 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2400 | OffendingRegion = K; |
| 2401 | return true; |
| 2402 | } else |
| 2403 | return false; |
| 2404 | }, |
| 2405 | false /* don't skip top directive */); |
| 2406 | CloseNesting = false; |
| 2407 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2408 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2409 | if (OrphanSeen) { |
| 2410 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2411 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2412 | } else { |
| 2413 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2414 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2415 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2416 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2417 | return true; |
| 2418 | } |
| 2419 | } |
| 2420 | return false; |
| 2421 | } |
| 2422 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2423 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2424 | ArrayRef<OMPClause *> Clauses, |
| 2425 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2426 | bool ErrorFound = false; |
| 2427 | unsigned NamedModifiersNumber = 0; |
| 2428 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2429 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2430 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2431 | for (const auto *C : Clauses) { |
| 2432 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2433 | // At most one if clause without a directive-name-modifier can appear on |
| 2434 | // the directive. |
| 2435 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2436 | if (FoundNameModifiers[CurNM]) { |
| 2437 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2438 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2439 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2440 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2441 | } else if (CurNM != OMPD_unknown) { |
| 2442 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2443 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2444 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2445 | FoundNameModifiers[CurNM] = IC; |
| 2446 | if (CurNM == OMPD_unknown) |
| 2447 | continue; |
| 2448 | // Check if the specified name modifier is allowed for the current |
| 2449 | // directive. |
| 2450 | // At most one if clause with the particular directive-name-modifier can |
| 2451 | // appear on the directive. |
| 2452 | bool MatchFound = false; |
| 2453 | for (auto NM : AllowedNameModifiers) { |
| 2454 | if (CurNM == NM) { |
| 2455 | MatchFound = true; |
| 2456 | break; |
| 2457 | } |
| 2458 | } |
| 2459 | if (!MatchFound) { |
| 2460 | S.Diag(IC->getNameModifierLoc(), |
| 2461 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2462 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2463 | ErrorFound = true; |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | // If any if clause on the directive includes a directive-name-modifier then |
| 2468 | // all if clauses on the directive must include a directive-name-modifier. |
| 2469 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2470 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2471 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2472 | diag::err_omp_no_more_if_clause); |
| 2473 | } else { |
| 2474 | std::string Values; |
| 2475 | std::string Sep(", "); |
| 2476 | unsigned AllowedCnt = 0; |
| 2477 | unsigned TotalAllowedNum = |
| 2478 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2479 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2480 | ++Cnt) { |
| 2481 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2482 | if (!FoundNameModifiers[NM]) { |
| 2483 | Values += "'"; |
| 2484 | Values += getOpenMPDirectiveName(NM); |
| 2485 | Values += "'"; |
| 2486 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2487 | Values += " or "; |
| 2488 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2489 | Values += Sep; |
| 2490 | ++AllowedCnt; |
| 2491 | } |
| 2492 | } |
| 2493 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2494 | diag::err_omp_unnamed_if_clause) |
| 2495 | << (TotalAllowedNum > 1) << Values; |
| 2496 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2497 | for (auto Loc : NameModifierLoc) { |
| 2498 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2499 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2500 | ErrorFound = true; |
| 2501 | } |
| 2502 | return ErrorFound; |
| 2503 | } |
| 2504 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2505 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2506 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2507 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2508 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2509 | StmtResult Res = StmtError(); |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 2510 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 2511 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 2512 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2513 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2514 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2515 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2516 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2517 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2518 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2519 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2520 | if (AStmt) { |
| 2521 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2522 | |
| 2523 | // Check default data sharing attributes for referenced variables. |
| 2524 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 2525 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 2526 | Stmt *S = AStmt; |
| 2527 | while (--ThisCaptureLevel >= 0) |
| 2528 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 2529 | DSAChecker.Visit(S); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2530 | if (DSAChecker.isErrorFound()) |
| 2531 | return StmtError(); |
| 2532 | // Generate list of implicitly defined firstprivate variables. |
| 2533 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2534 | |
| 2535 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2536 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2537 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2538 | SourceLocation(), SourceLocation())) { |
| 2539 | ClausesWithImplicit.push_back(Implicit); |
| 2540 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2541 | DSAChecker.getImplicitFirstprivate().size(); |
| 2542 | } else |
| 2543 | ErrorFound = true; |
| 2544 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2545 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2546 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2547 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2548 | switch (Kind) { |
| 2549 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2550 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2551 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2552 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2553 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2554 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2555 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2556 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2557 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2558 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2559 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2560 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2561 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2562 | case OMPD_for_simd: |
| 2563 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2564 | EndLoc, VarsWithInheritedDSA); |
| 2565 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2566 | case OMPD_sections: |
| 2567 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2568 | EndLoc); |
| 2569 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2570 | case OMPD_section: |
| 2571 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2572 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2573 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2574 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2575 | case OMPD_single: |
| 2576 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2577 | EndLoc); |
| 2578 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2579 | case OMPD_master: |
| 2580 | assert(ClausesWithImplicit.empty() && |
| 2581 | "No clauses are allowed for 'omp master' directive"); |
| 2582 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2583 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2584 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2585 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2586 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2587 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2588 | case OMPD_parallel_for: |
| 2589 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2590 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2591 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2592 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2593 | case OMPD_parallel_for_simd: |
| 2594 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2595 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2596 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2597 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2598 | case OMPD_parallel_sections: |
| 2599 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2600 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2601 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2602 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2603 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2604 | Res = |
| 2605 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2606 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2607 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2608 | case OMPD_taskyield: |
| 2609 | assert(ClausesWithImplicit.empty() && |
| 2610 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2611 | assert(AStmt == nullptr && |
| 2612 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2613 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2614 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2615 | case OMPD_barrier: |
| 2616 | assert(ClausesWithImplicit.empty() && |
| 2617 | "No clauses are allowed for 'omp barrier' directive"); |
| 2618 | assert(AStmt == nullptr && |
| 2619 | "No associated statement allowed for 'omp barrier' directive"); |
| 2620 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2621 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2622 | case OMPD_taskwait: |
| 2623 | assert(ClausesWithImplicit.empty() && |
| 2624 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2625 | assert(AStmt == nullptr && |
| 2626 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2627 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2628 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2629 | case OMPD_taskgroup: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2630 | Res = ActOnOpenMPTaskgroupDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2631 | EndLoc); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2632 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2633 | case OMPD_flush: |
| 2634 | assert(AStmt == nullptr && |
| 2635 | "No associated statement allowed for 'omp flush' directive"); |
| 2636 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2637 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2638 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2639 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2640 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2641 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2642 | case OMPD_atomic: |
| 2643 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2644 | EndLoc); |
| 2645 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2646 | case OMPD_teams: |
| 2647 | Res = |
| 2648 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2649 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2650 | case OMPD_target: |
| 2651 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2652 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2653 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2654 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2655 | case OMPD_target_parallel: |
| 2656 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2657 | StartLoc, EndLoc); |
| 2658 | AllowedNameModifiers.push_back(OMPD_target); |
| 2659 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2660 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2661 | case OMPD_target_parallel_for: |
| 2662 | Res = ActOnOpenMPTargetParallelForDirective( |
| 2663 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2664 | AllowedNameModifiers.push_back(OMPD_target); |
| 2665 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2666 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2667 | case OMPD_cancellation_point: |
| 2668 | assert(ClausesWithImplicit.empty() && |
| 2669 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2670 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2671 | "cancellation point' directive"); |
| 2672 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2673 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2674 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2675 | assert(AStmt == nullptr && |
| 2676 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2677 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2678 | CancelRegion); |
| 2679 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2680 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2681 | case OMPD_target_data: |
| 2682 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2683 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2684 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2685 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2686 | case OMPD_target_enter_data: |
| 2687 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2688 | EndLoc); |
| 2689 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2690 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2691 | case OMPD_target_exit_data: |
| 2692 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2693 | EndLoc); |
| 2694 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2695 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2696 | case OMPD_taskloop: |
| 2697 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2698 | EndLoc, VarsWithInheritedDSA); |
| 2699 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2700 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2701 | case OMPD_taskloop_simd: |
| 2702 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2703 | EndLoc, VarsWithInheritedDSA); |
| 2704 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2705 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2706 | case OMPD_distribute: |
| 2707 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2708 | EndLoc, VarsWithInheritedDSA); |
| 2709 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 2710 | case OMPD_target_update: |
| 2711 | assert(!AStmt && "Statement is not allowed for target update"); |
| 2712 | Res = |
| 2713 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2714 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 2715 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2716 | case OMPD_distribute_parallel_for: |
| 2717 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 2718 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2719 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2720 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2721 | case OMPD_distribute_parallel_for_simd: |
| 2722 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 2723 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2724 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2725 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2726 | case OMPD_distribute_simd: |
| 2727 | Res = ActOnOpenMPDistributeSimdDirective( |
| 2728 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2729 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2730 | case OMPD_target_parallel_for_simd: |
| 2731 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 2732 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2733 | AllowedNameModifiers.push_back(OMPD_target); |
| 2734 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2735 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2736 | case OMPD_target_simd: |
| 2737 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2738 | EndLoc, VarsWithInheritedDSA); |
| 2739 | AllowedNameModifiers.push_back(OMPD_target); |
| 2740 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2741 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2742 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 2743 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2744 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2745 | case OMPD_teams_distribute_simd: |
| 2746 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 2747 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2748 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2749 | case OMPD_teams_distribute_parallel_for_simd: |
| 2750 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 2751 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2752 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2753 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2754 | case OMPD_teams_distribute_parallel_for: |
| 2755 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 2756 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2757 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2758 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2759 | case OMPD_target_teams: |
| 2760 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2761 | EndLoc); |
| 2762 | AllowedNameModifiers.push_back(OMPD_target); |
| 2763 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2764 | case OMPD_target_teams_distribute: |
| 2765 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 2766 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2767 | AllowedNameModifiers.push_back(OMPD_target); |
| 2768 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2769 | case OMPD_target_teams_distribute_parallel_for: |
| 2770 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 2771 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2772 | AllowedNameModifiers.push_back(OMPD_target); |
| 2773 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2774 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2775 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 2776 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 2777 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2778 | AllowedNameModifiers.push_back(OMPD_target); |
| 2779 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2780 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2781 | case OMPD_target_teams_distribute_simd: |
| 2782 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 2783 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2784 | AllowedNameModifiers.push_back(OMPD_target); |
| 2785 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2786 | case OMPD_declare_target: |
| 2787 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2788 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2789 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2790 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2791 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2792 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2793 | llvm_unreachable("Unknown OpenMP directive"); |
| 2794 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2795 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2796 | for (auto P : VarsWithInheritedDSA) { |
| 2797 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2798 | << P.first << P.second->getSourceRange(); |
| 2799 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2800 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2801 | |
| 2802 | if (!AllowedNameModifiers.empty()) |
| 2803 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2804 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2805 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2806 | if (ErrorFound) |
| 2807 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2808 | return Res; |
| 2809 | } |
| 2810 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2811 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 2812 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2813 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2814 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 2815 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2816 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2817 | assert(Linears.size() == LinModifiers.size()); |
| 2818 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2819 | if (!DG || DG.get().isNull()) |
| 2820 | return DeclGroupPtrTy(); |
| 2821 | |
| 2822 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 2823 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2824 | return DG; |
| 2825 | } |
| 2826 | auto *ADecl = DG.get().getSingleDecl(); |
| 2827 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 2828 | ADecl = FTD->getTemplatedDecl(); |
| 2829 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2830 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 2831 | if (!FD) { |
| 2832 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2833 | return DeclGroupPtrTy(); |
| 2834 | } |
| 2835 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2836 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2837 | // The parameter of the simdlen clause must be a constant positive integer |
| 2838 | // expression. |
| 2839 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2840 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2841 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2842 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2843 | // The special this pointer can be used as if was one of the arguments to the |
| 2844 | // function in any of the linear, aligned, or uniform clauses. |
| 2845 | // The uniform clause declares one or more arguments to have an invariant |
| 2846 | // value for all concurrent invocations of the function in the execution of a |
| 2847 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2848 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 2849 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2850 | for (auto *E : Uniforms) { |
| 2851 | E = E->IgnoreParenImpCasts(); |
| 2852 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2853 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 2854 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2855 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2856 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 2857 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2858 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2859 | } |
| 2860 | if (isa<CXXThisExpr>(E)) { |
| 2861 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2862 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2863 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2864 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2865 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2866 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2867 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2868 | // The aligned clause declares that the object to which each list item points |
| 2869 | // is aligned to the number of bytes expressed in the optional parameter of |
| 2870 | // the aligned clause. |
| 2871 | // The special this pointer can be used as if was one of the arguments to the |
| 2872 | // function in any of the linear, aligned, or uniform clauses. |
| 2873 | // The type of list items appearing in the aligned clause must be array, |
| 2874 | // pointer, reference to array, or reference to pointer. |
| 2875 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 2876 | Expr *AlignedThis = nullptr; |
| 2877 | for (auto *E : Aligneds) { |
| 2878 | E = E->IgnoreParenImpCasts(); |
| 2879 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2880 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2881 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2882 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2883 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2884 | ->getCanonicalDecl() == CanonPVD) { |
| 2885 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2886 | // A list-item cannot appear in more than one aligned clause. |
| 2887 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 2888 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2889 | << 1 << E->getSourceRange(); |
| 2890 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 2891 | diag::note_omp_explicit_dsa) |
| 2892 | << getOpenMPClauseName(OMPC_aligned); |
| 2893 | continue; |
| 2894 | } |
| 2895 | AlignedArgs[CanonPVD] = E; |
| 2896 | QualType QTy = PVD->getType() |
| 2897 | .getNonReferenceType() |
| 2898 | .getUnqualifiedType() |
| 2899 | .getCanonicalType(); |
| 2900 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 2901 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 2902 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 2903 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 2904 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 2905 | } |
| 2906 | continue; |
| 2907 | } |
| 2908 | } |
| 2909 | if (isa<CXXThisExpr>(E)) { |
| 2910 | if (AlignedThis) { |
| 2911 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2912 | << 2 << E->getSourceRange(); |
| 2913 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2914 | << getOpenMPClauseName(OMPC_aligned); |
| 2915 | } |
| 2916 | AlignedThis = E; |
| 2917 | continue; |
| 2918 | } |
| 2919 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2920 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2921 | } |
| 2922 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 2923 | // positive integer expression. If no optional parameter is specified, |
| 2924 | // implementation-defined default alignments for SIMD instructions on the |
| 2925 | // target platforms are assumed. |
| 2926 | SmallVector<Expr *, 4> NewAligns; |
| 2927 | for (auto *E : Alignments) { |
| 2928 | ExprResult Align; |
| 2929 | if (E) |
| 2930 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 2931 | NewAligns.push_back(Align.get()); |
| 2932 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2933 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2934 | // The linear clause declares one or more list items to be private to a SIMD |
| 2935 | // lane and to have a linear relationship with respect to the iteration space |
| 2936 | // of a loop. |
| 2937 | // The special this pointer can be used as if was one of the arguments to the |
| 2938 | // function in any of the linear, aligned, or uniform clauses. |
| 2939 | // When a linear-step expression is specified in a linear clause it must be |
| 2940 | // either a constant integer expression or an integer-typed parameter that is |
| 2941 | // specified in a uniform clause on the directive. |
| 2942 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 2943 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 2944 | auto MI = LinModifiers.begin(); |
| 2945 | for (auto *E : Linears) { |
| 2946 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 2947 | ++MI; |
| 2948 | E = E->IgnoreParenImpCasts(); |
| 2949 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2950 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2951 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2952 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2953 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2954 | ->getCanonicalDecl() == CanonPVD) { |
| 2955 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 2956 | // A list-item cannot appear in more than one linear clause. |
| 2957 | if (LinearArgs.count(CanonPVD) > 0) { |
| 2958 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2959 | << getOpenMPClauseName(OMPC_linear) |
| 2960 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 2961 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 2962 | diag::note_omp_explicit_dsa) |
| 2963 | << getOpenMPClauseName(OMPC_linear); |
| 2964 | continue; |
| 2965 | } |
| 2966 | // Each argument can appear in at most one uniform or linear clause. |
| 2967 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 2968 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2969 | << getOpenMPClauseName(OMPC_linear) |
| 2970 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 2971 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 2972 | diag::note_omp_explicit_dsa) |
| 2973 | << getOpenMPClauseName(OMPC_uniform); |
| 2974 | continue; |
| 2975 | } |
| 2976 | LinearArgs[CanonPVD] = E; |
| 2977 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2978 | E->isInstantiationDependent() || |
| 2979 | E->containsUnexpandedParameterPack()) |
| 2980 | continue; |
| 2981 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 2982 | PVD->getOriginalType()); |
| 2983 | continue; |
| 2984 | } |
| 2985 | } |
| 2986 | if (isa<CXXThisExpr>(E)) { |
| 2987 | if (UniformedLinearThis) { |
| 2988 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2989 | << getOpenMPClauseName(OMPC_linear) |
| 2990 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 2991 | << E->getSourceRange(); |
| 2992 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2993 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 2994 | : OMPC_linear); |
| 2995 | continue; |
| 2996 | } |
| 2997 | UniformedLinearThis = E; |
| 2998 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2999 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3000 | continue; |
| 3001 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3002 | E->getType()); |
| 3003 | continue; |
| 3004 | } |
| 3005 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3006 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3007 | } |
| 3008 | Expr *Step = nullptr; |
| 3009 | Expr *NewStep = nullptr; |
| 3010 | SmallVector<Expr *, 4> NewSteps; |
| 3011 | for (auto *E : Steps) { |
| 3012 | // Skip the same step expression, it was checked already. |
| 3013 | if (Step == E || !E) { |
| 3014 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3015 | continue; |
| 3016 | } |
| 3017 | Step = E; |
| 3018 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3019 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3020 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3021 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3022 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3023 | << Step->getSourceRange(); |
| 3024 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3025 | E->isInstantiationDependent() || |
| 3026 | E->containsUnexpandedParameterPack() || |
| 3027 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 3028 | NewSteps.push_back(Step); |
| 3029 | else { |
| 3030 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3031 | << Step->getSourceRange(); |
| 3032 | } |
| 3033 | continue; |
| 3034 | } |
| 3035 | NewStep = Step; |
| 3036 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3037 | !Step->isInstantiationDependent() && |
| 3038 | !Step->containsUnexpandedParameterPack()) { |
| 3039 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3040 | .get(); |
| 3041 | if (NewStep) |
| 3042 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3043 | } |
| 3044 | NewSteps.push_back(NewStep); |
| 3045 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3046 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3047 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3048 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3049 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3050 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3051 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3052 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3053 | ADecl->addAttr(NewAttr); |
| 3054 | return ConvertDeclToDeclGroup(ADecl); |
| 3055 | } |
| 3056 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3057 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3058 | Stmt *AStmt, |
| 3059 | SourceLocation StartLoc, |
| 3060 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3061 | if (!AStmt) |
| 3062 | return StmtError(); |
| 3063 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3064 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3065 | // 1.2.2 OpenMP Language Terminology |
| 3066 | // Structured block - An executable statement with a single entry at the |
| 3067 | // top and a single exit at the bottom. |
| 3068 | // The point of exit cannot be a branch out of the structured block. |
| 3069 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3070 | CS->getCapturedDecl()->setNothrow(); |
| 3071 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3072 | getCurFunction()->setHasBranchProtectedScope(); |
| 3073 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3074 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3075 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3078 | namespace { |
| 3079 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3080 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3081 | /// for IR generation. |
| 3082 | class OpenMPIterationSpaceChecker { |
| 3083 | /// \brief Reference to Sema. |
| 3084 | Sema &SemaRef; |
| 3085 | /// \brief A location for diagnostics (when there is no some better location). |
| 3086 | SourceLocation DefaultLoc; |
| 3087 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3088 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3089 | /// \brief A source location for referring to loop init later. |
| 3090 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3091 | /// \brief A source location for referring to condition later. |
| 3092 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3093 | /// \brief A source location for referring to increment later. |
| 3094 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3095 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3096 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3097 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3098 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3099 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3100 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3101 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3102 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3103 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3104 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3105 | /// \brief This flag is true when condition is one of: |
| 3106 | /// Var < UB |
| 3107 | /// Var <= UB |
| 3108 | /// UB > Var |
| 3109 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3110 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3111 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3112 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3113 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3114 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3115 | |
| 3116 | public: |
| 3117 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3118 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3119 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3120 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3121 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3122 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3123 | /// for less/greater and for strict/non-strict comparison. |
| 3124 | bool CheckCond(Expr *S); |
| 3125 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3126 | /// does not conform, otherwise save loop step (#Step). |
| 3127 | bool CheckInc(Expr *S); |
| 3128 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3129 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3130 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3131 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3132 | /// \brief Source range of the loop init. |
| 3133 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3134 | /// \brief Source range of the loop condition. |
| 3135 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3136 | /// \brief Source range of the loop increment. |
| 3137 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3138 | /// \brief True if the step should be subtracted. |
| 3139 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3140 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3141 | Expr * |
| 3142 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 3143 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3144 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3145 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 3146 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3147 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3148 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 3149 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3150 | /// \brief Build reference expression to the private counter be used for |
| 3151 | /// codegen. |
| 3152 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3153 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3154 | Expr *BuildCounterInit() const; |
| 3155 | /// \brief Build step of the counter be used for codegen. |
| 3156 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3157 | /// \brief Return true if any expression is dependent. |
| 3158 | bool Dependent() const; |
| 3159 | |
| 3160 | private: |
| 3161 | /// \brief Check the right-hand side of an assignment in the increment |
| 3162 | /// expression. |
| 3163 | bool CheckIncRHS(Expr *RHS); |
| 3164 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3165 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3166 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3167 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3168 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3169 | /// \brief Helper to set loop increment. |
| 3170 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3171 | }; |
| 3172 | |
| 3173 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3174 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3175 | assert(!LB && !UB && !Step); |
| 3176 | return false; |
| 3177 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3178 | return LCDecl->getType()->isDependentType() || |
| 3179 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 3180 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3183 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 3184 | Expr *NewLCRefExpr, |
| 3185 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3187 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3188 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3189 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3190 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3191 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 3192 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3193 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3194 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3195 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3196 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3197 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3198 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | LB = NewLB; |
| 3200 | return false; |
| 3201 | } |
| 3202 | |
| 3203 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3204 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3205 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3206 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 3207 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3208 | if (!NewUB) |
| 3209 | return true; |
| 3210 | UB = NewUB; |
| 3211 | TestIsLessOp = LessOp; |
| 3212 | TestIsStrictOp = StrictOp; |
| 3213 | ConditionSrcRange = SR; |
| 3214 | ConditionLoc = SL; |
| 3215 | return false; |
| 3216 | } |
| 3217 | |
| 3218 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3219 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3220 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3221 | if (!NewStep) |
| 3222 | return true; |
| 3223 | if (!NewStep->isValueDependent()) { |
| 3224 | // Check that the step is integer expression. |
| 3225 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3226 | ExprResult Val = |
| 3227 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3228 | if (Val.isInvalid()) |
| 3229 | return true; |
| 3230 | NewStep = Val.get(); |
| 3231 | |
| 3232 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3233 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3234 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3235 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3236 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3237 | // the loop. |
| 3238 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3239 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3240 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3241 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3242 | // the loop. |
| 3243 | llvm::APSInt Result; |
| 3244 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3245 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3246 | bool IsConstNeg = |
| 3247 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3248 | bool IsConstPos = |
| 3249 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3250 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3251 | if (UB && (IsConstZero || |
| 3252 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3253 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3254 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3255 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3256 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3257 | SemaRef.Diag(ConditionLoc, |
| 3258 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3259 | << TestIsLessOp << ConditionSrcRange; |
| 3260 | return true; |
| 3261 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3262 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3263 | NewStep = |
| 3264 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3265 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3266 | Subtract = !Subtract; |
| 3267 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | Step = NewStep; |
| 3271 | SubtractStep = Subtract; |
| 3272 | return false; |
| 3273 | } |
| 3274 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3275 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3276 | // Check init-expr for canonical loop form and save loop counter |
| 3277 | // variable - #Var and its initialization value - #LB. |
| 3278 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3279 | // var = lb |
| 3280 | // integer-type var = lb |
| 3281 | // random-access-iterator-type var = lb |
| 3282 | // pointer-type var = lb |
| 3283 | // |
| 3284 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3285 | if (EmitDiags) { |
| 3286 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3287 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3288 | return true; |
| 3289 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3290 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3291 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3292 | S = ExprTemp->getSubExpr(); |
| 3293 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3294 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3295 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3296 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3297 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3298 | if (BO->getOpcode() == BO_Assign) { |
| 3299 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3300 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3301 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3302 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3303 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3304 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3305 | } |
| 3306 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3307 | if (ME->isArrow() && |
| 3308 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3309 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3310 | } |
| 3311 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3312 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3313 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3314 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3315 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3316 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3317 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3318 | SemaRef.Diag(S->getLocStart(), |
| 3319 | diag::ext_omp_loop_not_canonical_init) |
| 3320 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3321 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3325 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3326 | if (CE->getOperator() == OO_Equal) { |
| 3327 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3328 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3329 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3330 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3331 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3332 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3333 | } |
| 3334 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3335 | if (ME->isArrow() && |
| 3336 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3337 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3338 | } |
| 3339 | } |
| 3340 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3341 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3342 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3343 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3344 | if (EmitDiags) { |
| 3345 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3346 | << S->getSourceRange(); |
| 3347 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3348 | return true; |
| 3349 | } |
| 3350 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3351 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3352 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3353 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3354 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3355 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3356 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3357 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3358 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3359 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3360 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3361 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3362 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3363 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 3364 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3365 | return getCanonicalDecl(VD); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3366 | } |
| 3367 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3368 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3369 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3370 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3374 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3375 | // less/greater and for strict/non-strict comparison. |
| 3376 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3377 | // var relational-op b |
| 3378 | // b relational-op var |
| 3379 | // |
| 3380 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3381 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3382 | return true; |
| 3383 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3384 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3385 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3386 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3387 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3388 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3389 | return SetUB(BO->getRHS(), |
| 3390 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3391 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3392 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3393 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3394 | return SetUB(BO->getLHS(), |
| 3395 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3396 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3397 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3398 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3399 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3400 | if (CE->getNumArgs() == 2) { |
| 3401 | auto Op = CE->getOperator(); |
| 3402 | switch (Op) { |
| 3403 | case OO_Greater: |
| 3404 | case OO_GreaterEqual: |
| 3405 | case OO_Less: |
| 3406 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3407 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3408 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3409 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3410 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3411 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3412 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3413 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3414 | CE->getOperatorLoc()); |
| 3415 | break; |
| 3416 | default: |
| 3417 | break; |
| 3418 | } |
| 3419 | } |
| 3420 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3421 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3422 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3423 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3424 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3425 | return true; |
| 3426 | } |
| 3427 | |
| 3428 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3429 | // RHS of canonical loop form increment can be: |
| 3430 | // var + incr |
| 3431 | // incr + var |
| 3432 | // var - incr |
| 3433 | // |
| 3434 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3435 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3436 | if (BO->isAdditiveOp()) { |
| 3437 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3438 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3439 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3440 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3441 | return SetStep(BO->getLHS(), false); |
| 3442 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3443 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3444 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3445 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3446 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3447 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3448 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3449 | return SetStep(CE->getArg(0), false); |
| 3450 | } |
| 3451 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3452 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3453 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3454 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3455 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3456 | return true; |
| 3457 | } |
| 3458 | |
| 3459 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3460 | // Check incr-expr for canonical loop form and return true if it |
| 3461 | // does not conform. |
| 3462 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3463 | // ++var |
| 3464 | // var++ |
| 3465 | // --var |
| 3466 | // var-- |
| 3467 | // var += incr |
| 3468 | // var -= incr |
| 3469 | // var = var + incr |
| 3470 | // var = incr + var |
| 3471 | // var = var - incr |
| 3472 | // |
| 3473 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3474 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3475 | return true; |
| 3476 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3477 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3478 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3479 | S = ExprTemp->getSubExpr(); |
| 3480 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3481 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3482 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3483 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3484 | if (UO->isIncrementDecrementOp() && |
| 3485 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3486 | return SetStep(SemaRef |
| 3487 | .ActOnIntegerConstant(UO->getLocStart(), |
| 3488 | (UO->isDecrementOp() ? -1 : 1)) |
| 3489 | .get(), |
| 3490 | false); |
| 3491 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3492 | switch (BO->getOpcode()) { |
| 3493 | case BO_AddAssign: |
| 3494 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3495 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3496 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3497 | break; |
| 3498 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3499 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3500 | return CheckIncRHS(BO->getRHS()); |
| 3501 | break; |
| 3502 | default: |
| 3503 | break; |
| 3504 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3505 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3506 | switch (CE->getOperator()) { |
| 3507 | case OO_PlusPlus: |
| 3508 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3509 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3510 | return SetStep(SemaRef |
| 3511 | .ActOnIntegerConstant( |
| 3512 | CE->getLocStart(), |
| 3513 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 3514 | .get(), |
| 3515 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | case OO_PlusEqual: |
| 3518 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3519 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3520 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3521 | break; |
| 3522 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3523 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3524 | return CheckIncRHS(CE->getArg(1)); |
| 3525 | break; |
| 3526 | default: |
| 3527 | break; |
| 3528 | } |
| 3529 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3530 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3531 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3532 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3533 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3534 | return true; |
| 3535 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3536 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3537 | static ExprResult |
| 3538 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3539 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 3540 | if (SemaRef.CurContext->isDependentContext()) |
| 3541 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3542 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3543 | return SemaRef.PerformImplicitConversion( |
| 3544 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3545 | /*AllowExplicit=*/true); |
| 3546 | auto I = Captures.find(Capture); |
| 3547 | if (I != Captures.end()) |
| 3548 | return buildCapture(SemaRef, Capture, I->second); |
| 3549 | DeclRefExpr *Ref = nullptr; |
| 3550 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3551 | Captures[Capture] = Ref; |
| 3552 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3555 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3556 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3557 | Scope *S, const bool LimitedType, |
| 3558 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3559 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3560 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3561 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3562 | SemaRef.getLangOpts().CPlusPlus) { |
| 3563 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3564 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3565 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3566 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3567 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3568 | if (!Upper || !Lower) |
| 3569 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3570 | |
| 3571 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3572 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3573 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3574 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3575 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3576 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3577 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3578 | return nullptr; |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | if (!Diff.isUsable()) |
| 3583 | return nullptr; |
| 3584 | |
| 3585 | // Upper - Lower [- 1] |
| 3586 | if (TestIsStrictOp) |
| 3587 | Diff = SemaRef.BuildBinOp( |
| 3588 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3589 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3590 | if (!Diff.isUsable()) |
| 3591 | return nullptr; |
| 3592 | |
| 3593 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3594 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3595 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3596 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3597 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3598 | if (!Diff.isUsable()) |
| 3599 | return nullptr; |
| 3600 | |
| 3601 | // Parentheses (for dumping/debugging purposes only). |
| 3602 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3603 | if (!Diff.isUsable()) |
| 3604 | return nullptr; |
| 3605 | |
| 3606 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3607 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3608 | if (!Diff.isUsable()) |
| 3609 | return nullptr; |
| 3610 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3611 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3612 | QualType Type = Diff.get()->getType(); |
| 3613 | auto &C = SemaRef.Context; |
| 3614 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3615 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3616 | if (!Type->isIntegerType() || UseVarType) { |
| 3617 | unsigned NewSize = |
| 3618 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3619 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3620 | : Type->hasSignedIntegerRepresentation(); |
| 3621 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3622 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3623 | Diff = SemaRef.PerformImplicitConversion( |
| 3624 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3625 | if (!Diff.isUsable()) |
| 3626 | return nullptr; |
| 3627 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3628 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3629 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3630 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3631 | if (NewSize != C.getTypeSize(Type)) { |
| 3632 | if (NewSize < C.getTypeSize(Type)) { |
| 3633 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3634 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3635 | << InitSrcRange << ConditionSrcRange; |
| 3636 | } |
| 3637 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3638 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3639 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3640 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3641 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3642 | Sema::AA_Converting, true); |
| 3643 | if (!Diff.isUsable()) |
| 3644 | return nullptr; |
| 3645 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3649 | return Diff.get(); |
| 3650 | } |
| 3651 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3652 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3653 | Scope *S, Expr *Cond, |
| 3654 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3655 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3656 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3657 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3658 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3659 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3660 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3661 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3662 | return nullptr; |
| 3663 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3664 | auto CondExpr = SemaRef.BuildBinOp( |
| 3665 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3666 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3667 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3668 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3669 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3670 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3671 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3672 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3673 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3674 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3675 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3676 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3677 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3678 | } |
| 3679 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3680 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3681 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3682 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3683 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3684 | if (!VD) { |
| 3685 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3686 | auto *Ref = buildDeclRefExpr( |
| 3687 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3688 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 3689 | // If the loop control decl is explicitly marked as private, do not mark it |
| 3690 | // as captured again. |
| 3691 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 3692 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3693 | return Ref; |
| 3694 | } |
| 3695 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3696 | DefaultLoc); |
| 3697 | } |
| 3698 | |
| 3699 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3700 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3701 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3702 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3703 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3704 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3705 | if (PrivateVar->isInvalidDecl()) |
| 3706 | return nullptr; |
| 3707 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3708 | } |
| 3709 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 3712 | /// \brief Build initialization of the counter to be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3713 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3714 | |
| 3715 | /// \brief Build step of the counter be used for codegen. |
| 3716 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3717 | |
| 3718 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3719 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3720 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3721 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3722 | /// \brief This expression calculates the number of iterations in the loop. |
| 3723 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3724 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3725 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3726 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3727 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3728 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3729 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3730 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3731 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3732 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3733 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3734 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3735 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3736 | /// \brief Source range of the loop init. |
| 3737 | SourceRange InitSrcRange; |
| 3738 | /// \brief Source range of the loop condition. |
| 3739 | SourceRange CondSrcRange; |
| 3740 | /// \brief Source range of the loop increment. |
| 3741 | SourceRange IncSrcRange; |
| 3742 | }; |
| 3743 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3744 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3745 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3746 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3747 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3748 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3749 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3750 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3751 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3752 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3753 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3754 | if (auto *D = ISC.GetLoopDecl()) { |
| 3755 | auto *VD = dyn_cast<VarDecl>(D); |
| 3756 | if (!VD) { |
| 3757 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3758 | VD = Private; |
| 3759 | else { |
| 3760 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3761 | /*WithInit=*/false); |
| 3762 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3763 | } |
| 3764 | } |
| 3765 | DSAStack->addLoopControlVariable(D, VD); |
| 3766 | } |
| 3767 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3768 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3769 | } |
| 3770 | } |
| 3771 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3772 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3773 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3774 | static bool CheckOpenMPIterationSpace( |
| 3775 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3776 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3777 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3778 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3779 | LoopIterationSpace &ResultIterSpace, |
| 3780 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3781 | // OpenMP [2.6, Canonical Loop Form] |
| 3782 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3783 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3784 | if (!For) { |
| 3785 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3786 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3787 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3788 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3789 | if (NestedLoopCount > 1) { |
| 3790 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3791 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3792 | diag::note_omp_collapse_ordered_expr) |
| 3793 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3794 | << OrderedLoopCountExpr->getSourceRange(); |
| 3795 | else if (CollapseLoopCountExpr) |
| 3796 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3797 | diag::note_omp_collapse_ordered_expr) |
| 3798 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3799 | else |
| 3800 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3801 | diag::note_omp_collapse_ordered_expr) |
| 3802 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3803 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3804 | return true; |
| 3805 | } |
| 3806 | assert(For->getBody()); |
| 3807 | |
| 3808 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3809 | |
| 3810 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3811 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3812 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3813 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3814 | |
| 3815 | bool HasErrors = false; |
| 3816 | |
| 3817 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3818 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3819 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3820 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3821 | // OpenMP [2.6, Canonical Loop Form] |
| 3822 | // Var is one of the following: |
| 3823 | // A variable of signed or unsigned integer type. |
| 3824 | // For C++, a variable of a random access iterator type. |
| 3825 | // For C, a variable of a pointer type. |
| 3826 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3827 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3828 | !VarType->isPointerType() && |
| 3829 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3830 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3831 | << SemaRef.getLangOpts().CPlusPlus; |
| 3832 | HasErrors = true; |
| 3833 | } |
| 3834 | |
| 3835 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3836 | // a Construct |
| 3837 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3838 | // parallel for construct is (are) private. |
| 3839 | // The loop iteration variable in the associated for-loop of a simd |
| 3840 | // construct with just one associated for-loop is linear with a |
| 3841 | // constant-linear-step that is the increment of the associated for-loop. |
| 3842 | // Exclude loop var from the list of variables with implicitly defined data |
| 3843 | // sharing attributes. |
| 3844 | VarsWithImplicitDSA.erase(LCDecl); |
| 3845 | |
| 3846 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 3847 | // in a Construct, C/C++]. |
| 3848 | // The loop iteration variable in the associated for-loop of a simd |
| 3849 | // construct with just one associated for-loop may be listed in a linear |
| 3850 | // clause with a constant-linear-step that is the increment of the |
| 3851 | // associated for-loop. |
| 3852 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3853 | // parallel for construct may be listed in a private or lastprivate clause. |
| 3854 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 3855 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3856 | // declared in the loop and it is predetermined as a private. |
| 3857 | auto PredeterminedCKind = |
| 3858 | isOpenMPSimdDirective(DKind) |
| 3859 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3860 | : OMPC_private; |
| 3861 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3862 | DVar.CKind != PredeterminedCKind) || |
| 3863 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3864 | isOpenMPDistributeDirective(DKind)) && |
| 3865 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3866 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3867 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 3868 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 3869 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3870 | << getOpenMPClauseName(PredeterminedCKind); |
| 3871 | if (DVar.RefExpr == nullptr) |
| 3872 | DVar.CKind = PredeterminedCKind; |
| 3873 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 3874 | HasErrors = true; |
| 3875 | } else if (LoopDeclRefExpr != nullptr) { |
| 3876 | // Make the loop iteration variable private (for worksharing constructs), |
| 3877 | // linear (for simd directives with the only one associated loop) or |
| 3878 | // lastprivate (for simd directives with several collapsed or ordered |
| 3879 | // loops). |
| 3880 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3881 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 3882 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3883 | /*FromParent=*/false); |
| 3884 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 3885 | } |
| 3886 | |
| 3887 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 3888 | |
| 3889 | // Check test-expr. |
| 3890 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3891 | |
| 3892 | // Check incr-expr. |
| 3893 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3896 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3897 | return HasErrors; |
| 3898 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3899 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3900 | ResultIterSpace.PreCond = |
| 3901 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3902 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3903 | DSA.getCurScope(), |
| 3904 | (isOpenMPWorksharingDirective(DKind) || |
| 3905 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3906 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3907 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3908 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3909 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3910 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3911 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3912 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3913 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3914 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3915 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3916 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3917 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3918 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3919 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3920 | ResultIterSpace.CounterInit == nullptr || |
| 3921 | ResultIterSpace.CounterStep == nullptr); |
| 3922 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3923 | return HasErrors; |
| 3924 | } |
| 3925 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3926 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3927 | static ExprResult |
| 3928 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3929 | ExprResult Start, |
| 3930 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3931 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3932 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3933 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3934 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3935 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3936 | VarRef.get()->getType())) { |
| 3937 | NewStart = SemaRef.PerformImplicitConversion( |
| 3938 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3939 | /*AllowExplicit=*/true); |
| 3940 | if (!NewStart.isUsable()) |
| 3941 | return ExprError(); |
| 3942 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3943 | |
| 3944 | auto Init = |
| 3945 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3946 | return Init; |
| 3947 | } |
| 3948 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3949 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3950 | static ExprResult |
| 3951 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3952 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 3953 | ExprResult Step, bool Subtract, |
| 3954 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3955 | // Add parentheses (for debugging purposes only). |
| 3956 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3957 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3958 | !Step.isUsable()) |
| 3959 | return ExprError(); |
| 3960 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3961 | ExprResult NewStep = Step; |
| 3962 | if (Captures) |
| 3963 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3964 | if (NewStep.isInvalid()) |
| 3965 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3966 | ExprResult Update = |
| 3967 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3968 | if (!Update.isUsable()) |
| 3969 | return ExprError(); |
| 3970 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3971 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 3972 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3973 | ExprResult NewStart = Start; |
| 3974 | if (Captures) |
| 3975 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3976 | if (NewStart.isInvalid()) |
| 3977 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3978 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3979 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 3980 | ExprResult SavedUpdate = Update; |
| 3981 | ExprResult UpdateVal; |
| 3982 | if (VarRef.get()->getType()->isOverloadableType() || |
| 3983 | NewStart.get()->getType()->isOverloadableType() || |
| 3984 | Update.get()->getType()->isOverloadableType()) { |
| 3985 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3986 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 3987 | Update = |
| 3988 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3989 | if (Update.isUsable()) { |
| 3990 | UpdateVal = |
| 3991 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 3992 | VarRef.get(), SavedUpdate.get()); |
| 3993 | if (UpdateVal.isUsable()) { |
| 3994 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 3995 | UpdateVal.get()); |
| 3996 | } |
| 3997 | } |
| 3998 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3999 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4000 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4001 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4002 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4003 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4004 | NewStart.get(), SavedUpdate.get()); |
| 4005 | if (!Update.isUsable()) |
| 4006 | return ExprError(); |
| 4007 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4008 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4009 | VarRef.get()->getType())) { |
| 4010 | Update = SemaRef.PerformImplicitConversion( |
| 4011 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4012 | if (!Update.isUsable()) |
| 4013 | return ExprError(); |
| 4014 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4015 | |
| 4016 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4017 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4018 | return Update; |
| 4019 | } |
| 4020 | |
| 4021 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4022 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4023 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4024 | if (E == nullptr) |
| 4025 | return ExprError(); |
| 4026 | auto &C = SemaRef.Context; |
| 4027 | QualType OldType = E->getType(); |
| 4028 | unsigned HasBits = C.getTypeSize(OldType); |
| 4029 | if (HasBits >= Bits) |
| 4030 | return ExprResult(E); |
| 4031 | // OK to convert to signed, because new type has more bits than old. |
| 4032 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4033 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4034 | true); |
| 4035 | } |
| 4036 | |
| 4037 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4038 | /// into \a Bits bits. |
| 4039 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4040 | if (E == nullptr) |
| 4041 | return false; |
| 4042 | llvm::APSInt Result; |
| 4043 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4044 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4045 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4046 | } |
| 4047 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4048 | /// Build preinits statement for the given declarations. |
| 4049 | static Stmt *buildPreInits(ASTContext &Context, |
| 4050 | SmallVectorImpl<Decl *> &PreInits) { |
| 4051 | if (!PreInits.empty()) { |
| 4052 | return new (Context) DeclStmt( |
| 4053 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4054 | SourceLocation(), SourceLocation()); |
| 4055 | } |
| 4056 | return nullptr; |
| 4057 | } |
| 4058 | |
| 4059 | /// Build preinits statement for the given declarations. |
| 4060 | static Stmt *buildPreInits(ASTContext &Context, |
| 4061 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4062 | if (!Captures.empty()) { |
| 4063 | SmallVector<Decl *, 16> PreInits; |
| 4064 | for (auto &Pair : Captures) |
| 4065 | PreInits.push_back(Pair.second->getDecl()); |
| 4066 | return buildPreInits(Context, PreInits); |
| 4067 | } |
| 4068 | return nullptr; |
| 4069 | } |
| 4070 | |
| 4071 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4072 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4073 | Expr *PostUpdate = nullptr; |
| 4074 | if (!PostUpdates.empty()) { |
| 4075 | for (auto *E : PostUpdates) { |
| 4076 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4077 | E->getExprLoc(), |
| 4078 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4079 | E->getExprLoc(), E) |
| 4080 | .get(); |
| 4081 | PostUpdate = PostUpdate |
| 4082 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4083 | PostUpdate, ConvE) |
| 4084 | .get() |
| 4085 | : ConvE; |
| 4086 | } |
| 4087 | } |
| 4088 | return PostUpdate; |
| 4089 | } |
| 4090 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4091 | /// \brief 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] | 4092 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4093 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4094 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4095 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4096 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4097 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4098 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4099 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4100 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4101 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4102 | // Found 'collapse' clause - calculate collapse number. |
| 4103 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4104 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4105 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4106 | } |
| 4107 | if (OrderedLoopCountExpr) { |
| 4108 | // Found 'ordered' clause - calculate collapse number. |
| 4109 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4110 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4111 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4112 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4113 | diag::err_omp_wrong_ordered_loop_count) |
| 4114 | << OrderedLoopCountExpr->getSourceRange(); |
| 4115 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4116 | diag::note_collapse_loop_count) |
| 4117 | << CollapseLoopCountExpr->getSourceRange(); |
| 4118 | } |
| 4119 | NestedLoopCount = Result.getLimitedValue(); |
| 4120 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4121 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4122 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4123 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4124 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4125 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4126 | IterSpaces.resize(NestedLoopCount); |
| 4127 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4128 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4129 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4130 | NestedLoopCount, CollapseLoopCountExpr, |
| 4131 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4132 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4133 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4134 | // 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] | 4135 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4136 | // All loops associated with the construct must be perfectly nested; that |
| 4137 | // is, there must be no intervening code nor any OpenMP directive between |
| 4138 | // any two loops. |
| 4139 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4142 | Built.clear(/* size */ NestedLoopCount); |
| 4143 | |
| 4144 | if (SemaRef.CurContext->isDependentContext()) |
| 4145 | return NestedLoopCount; |
| 4146 | |
| 4147 | // An example of what is generated for the following code: |
| 4148 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4149 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4150 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4151 | // for (k = 0; k < NK; ++k) |
| 4152 | // for (j = J0; j < NJ; j+=2) { |
| 4153 | // <loop body> |
| 4154 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4155 | // |
| 4156 | // We generate the code below. |
| 4157 | // Note: the loop body may be outlined in CodeGen. |
| 4158 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4159 | // iterations and operator+= to calculate counter value. |
| 4160 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4161 | // or i64 is currently supported). |
| 4162 | // |
| 4163 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4164 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4165 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4166 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4167 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4168 | // <loop body (using local i and j)> |
| 4169 | // } |
| 4170 | // i = NI; // assign final values of counters |
| 4171 | // j = NJ; |
| 4172 | // |
| 4173 | |
| 4174 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4175 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4176 | // Precondition tests if there is at least one iteration (all conditions are |
| 4177 | // true). |
| 4178 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4179 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4180 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4181 | 32 /* Bits */, SemaRef |
| 4182 | .PerformImplicitConversion( |
| 4183 | N0->IgnoreImpCasts(), N0->getType(), |
| 4184 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4185 | .get(), |
| 4186 | SemaRef); |
| 4187 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4188 | 64 /* Bits */, SemaRef |
| 4189 | .PerformImplicitConversion( |
| 4190 | N0->IgnoreImpCasts(), N0->getType(), |
| 4191 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4192 | .get(), |
| 4193 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4194 | |
| 4195 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4196 | return NestedLoopCount; |
| 4197 | |
| 4198 | auto &C = SemaRef.Context; |
| 4199 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4200 | |
| 4201 | Scope *CurScope = DSA.getCurScope(); |
| 4202 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4203 | if (PreCond.isUsable()) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4204 | PreCond = |
| 4205 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 4206 | PreCond.get(), IterSpaces[Cnt].PreCond); |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4207 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4208 | auto N = IterSpaces[Cnt].NumIterations; |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4209 | SourceLocation Loc = N->getExprLoc(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4210 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4211 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4212 | LastIteration32 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4213 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4214 | SemaRef |
| 4215 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4216 | Sema::AA_Converting, |
| 4217 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4218 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4219 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4220 | LastIteration64 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4221 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4222 | SemaRef |
| 4223 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4224 | Sema::AA_Converting, |
| 4225 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4226 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | // Choose either the 32-bit or 64-bit version. |
| 4230 | ExprResult LastIteration = LastIteration64; |
| 4231 | if (LastIteration32.isUsable() && |
| 4232 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4233 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4234 | FitsInto( |
| 4235 | 32 /* Bits */, |
| 4236 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4237 | LastIteration64.get(), SemaRef))) |
| 4238 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4239 | QualType VType = LastIteration.get()->getType(); |
| 4240 | QualType RealVType = VType; |
| 4241 | QualType StrideVType = VType; |
| 4242 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 4243 | VType = |
| 4244 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 4245 | StrideVType = |
| 4246 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 4247 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4248 | |
| 4249 | if (!LastIteration.isUsable()) |
| 4250 | return 0; |
| 4251 | |
| 4252 | // Save the number of iterations. |
| 4253 | ExprResult NumIterations = LastIteration; |
| 4254 | { |
| 4255 | LastIteration = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4256 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4257 | LastIteration.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4258 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4259 | if (!LastIteration.isUsable()) |
| 4260 | return 0; |
| 4261 | } |
| 4262 | |
| 4263 | // Calculate the last iteration number beforehand instead of doing this on |
| 4264 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4265 | llvm::APSInt Result; |
| 4266 | bool IsConstant = |
| 4267 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4268 | ExprResult CalcLastIteration; |
| 4269 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4270 | ExprResult SaveRef = |
| 4271 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4272 | LastIteration = SaveRef; |
| 4273 | |
| 4274 | // Prepare SaveRef + 1. |
| 4275 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4276 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4277 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4278 | if (!NumIterations.isUsable()) |
| 4279 | return 0; |
| 4280 | } |
| 4281 | |
| 4282 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4283 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4284 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4285 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4286 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4287 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4288 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4289 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4290 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4291 | SemaRef.AddInitializerToDecl(LBDecl, |
| 4292 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4293 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4294 | |
| 4295 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4296 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4297 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4298 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4299 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4300 | |
| 4301 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4302 | // This will be used to implement clause 'lastprivate'. |
| 4303 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4304 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4305 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4306 | SemaRef.AddInitializerToDecl(ILDecl, |
| 4307 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4308 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4309 | |
| 4310 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4311 | VarDecl *STDecl = |
| 4312 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4313 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4314 | SemaRef.AddInitializerToDecl(STDecl, |
| 4315 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4316 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4317 | |
| 4318 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4319 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4320 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4321 | UB.get(), LastIteration.get()); |
| 4322 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4323 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4324 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4325 | CondOp.get()); |
| 4326 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4327 | |
| 4328 | // If we have a combined directive that combines 'distribute', 'for' or |
| 4329 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 4330 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 4331 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 4332 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4333 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4334 | // Lower bound variable, initialized with zero. |
| 4335 | VarDecl *CombLBDecl = |
| 4336 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 4337 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 4338 | SemaRef.AddInitializerToDecl( |
| 4339 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4340 | /*DirectInit*/ false); |
| 4341 | |
| 4342 | // Upper bound variable, initialized with last iteration number. |
| 4343 | VarDecl *CombUBDecl = |
| 4344 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 4345 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 4346 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 4347 | /*DirectInit*/ false); |
| 4348 | |
| 4349 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 4350 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 4351 | ExprResult CombCondOp = |
| 4352 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 4353 | LastIteration.get(), CombUB.get()); |
| 4354 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 4355 | CombCondOp.get()); |
| 4356 | CombEUB = SemaRef.ActOnFinishFullExpr(CombEUB.get()); |
| 4357 | |
| 4358 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4359 | // We expect to have at least 2 more parameters than the 'parallel' |
| 4360 | // directive does - the lower and upper bounds of the previous schedule. |
| 4361 | assert(CD->getNumParams() >= 4 && |
| 4362 | "Unexpected number of parameters in loop combined directive"); |
| 4363 | |
| 4364 | // Set the proper type for the bounds given what we learned from the |
| 4365 | // enclosed loops. |
| 4366 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 4367 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 4368 | |
| 4369 | // Previous lower and upper bounds are obtained from the region |
| 4370 | // parameters. |
| 4371 | PrevLB = |
| 4372 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 4373 | PrevUB = |
| 4374 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 4375 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4379 | ExprResult IV; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4380 | ExprResult Init, CombInit; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4381 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4382 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4383 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4384 | Expr *RHS = |
| 4385 | (isOpenMPWorksharingDirective(DKind) || |
| 4386 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 4387 | ? LB.get() |
| 4388 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4389 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4390 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4391 | |
| 4392 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4393 | Expr *CombRHS = |
| 4394 | (isOpenMPWorksharingDirective(DKind) || |
| 4395 | isOpenMPTaskLoopDirective(DKind) || |
| 4396 | isOpenMPDistributeDirective(DKind)) |
| 4397 | ? CombLB.get() |
| 4398 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4399 | CombInit = |
| 4400 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| 4401 | CombInit = SemaRef.ActOnFinishFullExpr(CombInit.get()); |
| 4402 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4405 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4406 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4407 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4408 | (isOpenMPWorksharingDirective(DKind) || |
| 4409 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4410 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4411 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4412 | NumIterations.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4413 | ExprResult CombCond; |
| 4414 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4415 | CombCond = |
| 4416 | SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), CombUB.get()); |
| 4417 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4418 | // Loop increment (IV = IV + 1) |
| 4419 | SourceLocation IncLoc; |
| 4420 | ExprResult Inc = |
| 4421 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4422 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4423 | if (!Inc.isUsable()) |
| 4424 | return 0; |
| 4425 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4426 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4427 | if (!Inc.isUsable()) |
| 4428 | return 0; |
| 4429 | |
| 4430 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4431 | // Used for directives with static scheduling. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4432 | // In combined construct, add combined version that use CombLB and CombUB |
| 4433 | // base variables for the update |
| 4434 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4435 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4436 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4437 | // LB + ST |
| 4438 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4439 | if (!NextLB.isUsable()) |
| 4440 | return 0; |
| 4441 | // LB = LB + ST |
| 4442 | NextLB = |
| 4443 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4444 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4445 | if (!NextLB.isUsable()) |
| 4446 | return 0; |
| 4447 | // UB + ST |
| 4448 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4449 | if (!NextUB.isUsable()) |
| 4450 | return 0; |
| 4451 | // UB = UB + ST |
| 4452 | NextUB = |
| 4453 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4454 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4455 | if (!NextUB.isUsable()) |
| 4456 | return 0; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4457 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4458 | CombNextLB = |
| 4459 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 4460 | if (!NextLB.isUsable()) |
| 4461 | return 0; |
| 4462 | // LB = LB + ST |
| 4463 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 4464 | CombNextLB.get()); |
| 4465 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get()); |
| 4466 | if (!CombNextLB.isUsable()) |
| 4467 | return 0; |
| 4468 | // UB + ST |
| 4469 | CombNextUB = |
| 4470 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 4471 | if (!CombNextUB.isUsable()) |
| 4472 | return 0; |
| 4473 | // UB = UB + ST |
| 4474 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 4475 | CombNextUB.get()); |
| 4476 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get()); |
| 4477 | if (!CombNextUB.isUsable()) |
| 4478 | return 0; |
| 4479 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4480 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4481 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4482 | // Create increment expression for distribute loop when combined in a same |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4483 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 4484 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 4485 | // in combination with 'distribute', like in 'distribute parallel for' |
| 4486 | SourceLocation DistIncLoc; |
| 4487 | ExprResult DistCond, DistInc, PrevEUB; |
| 4488 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4489 | DistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()); |
| 4490 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 4491 | |
| 4492 | DistInc = |
| 4493 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 4494 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4495 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 4496 | DistInc.get()); |
| 4497 | DistInc = SemaRef.ActOnFinishFullExpr(DistInc.get()); |
| 4498 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4499 | |
| 4500 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 4501 | // construct |
| 4502 | SourceLocation DistEUBLoc; |
| 4503 | ExprResult IsUBGreater = |
| 4504 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 4505 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4506 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 4507 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 4508 | CondOp.get()); |
| 4509 | PrevEUB = SemaRef.ActOnFinishFullExpr(PrevEUB.get()); |
| 4510 | } |
| 4511 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4512 | // Build updates and final values of the loop counters. |
| 4513 | bool HasErrors = false; |
| 4514 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4515 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4516 | Built.Updates.resize(NestedLoopCount); |
| 4517 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4518 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4519 | { |
| 4520 | ExprResult Div; |
| 4521 | // Go from inner nested loop to outer. |
| 4522 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4523 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4524 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4525 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4526 | // where Div is product of previous iterations' IS.NumIters. |
| 4527 | ExprResult Iter; |
| 4528 | if (Div.isUsable()) { |
| 4529 | Iter = |
| 4530 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4531 | } else { |
| 4532 | Iter = IV; |
| 4533 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4534 | "unusable div expected on first iteration only"); |
| 4535 | } |
| 4536 | |
| 4537 | if (Cnt != 0 && Iter.isUsable()) |
| 4538 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4539 | IS.NumIterations); |
| 4540 | if (!Iter.isUsable()) { |
| 4541 | HasErrors = true; |
| 4542 | break; |
| 4543 | } |
| 4544 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4545 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4546 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4547 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4548 | IS.CounterVar->getExprLoc(), |
| 4549 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4550 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4551 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4552 | if (!Init.isUsable()) { |
| 4553 | HasErrors = true; |
| 4554 | break; |
| 4555 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4556 | ExprResult Update = BuildCounterUpdate( |
| 4557 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4558 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4559 | if (!Update.isUsable()) { |
| 4560 | HasErrors = true; |
| 4561 | break; |
| 4562 | } |
| 4563 | |
| 4564 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4565 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4566 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4567 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4568 | if (!Final.isUsable()) { |
| 4569 | HasErrors = true; |
| 4570 | break; |
| 4571 | } |
| 4572 | |
| 4573 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4574 | if (Cnt != 0) { |
| 4575 | if (Div.isUnset()) |
| 4576 | Div = IS.NumIterations; |
| 4577 | else |
| 4578 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4579 | IS.NumIterations); |
| 4580 | |
| 4581 | // Add parentheses (for debugging purposes only). |
| 4582 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4583 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4584 | if (!Div.isUsable()) { |
| 4585 | HasErrors = true; |
| 4586 | break; |
| 4587 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4588 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4589 | } |
| 4590 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4591 | HasErrors = true; |
| 4592 | break; |
| 4593 | } |
| 4594 | // Save results |
| 4595 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4596 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4597 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4598 | Built.Updates[Cnt] = Update.get(); |
| 4599 | Built.Finals[Cnt] = Final.get(); |
| 4600 | } |
| 4601 | } |
| 4602 | |
| 4603 | if (HasErrors) |
| 4604 | return 0; |
| 4605 | |
| 4606 | // Save results |
| 4607 | Built.IterationVarRef = IV.get(); |
| 4608 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4609 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4610 | Built.CalcLastIteration = |
| 4611 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4612 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4613 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4614 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4615 | Built.Init = Init.get(); |
| 4616 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4617 | Built.LB = LB.get(); |
| 4618 | Built.UB = UB.get(); |
| 4619 | Built.IL = IL.get(); |
| 4620 | Built.ST = ST.get(); |
| 4621 | Built.EUB = EUB.get(); |
| 4622 | Built.NLB = NextLB.get(); |
| 4623 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4624 | Built.PrevLB = PrevLB.get(); |
| 4625 | Built.PrevUB = PrevUB.get(); |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4626 | Built.DistInc = DistInc.get(); |
| 4627 | Built.PrevEUB = PrevEUB.get(); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4628 | Built.DistCombinedFields.LB = CombLB.get(); |
| 4629 | Built.DistCombinedFields.UB = CombUB.get(); |
| 4630 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 4631 | Built.DistCombinedFields.Init = CombInit.get(); |
| 4632 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 4633 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 4634 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4635 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4636 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 4637 | // Fill data for doacross depend clauses. |
| 4638 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 4639 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4640 | Pair.first->setCounterValue(CounterVal); |
| 4641 | else { |
| 4642 | if (NestedLoopCount != Pair.second.size() || |
| 4643 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 4644 | // Erroneous case - clause has some problems. |
| 4645 | Pair.first->setCounterValue(CounterVal); |
| 4646 | continue; |
| 4647 | } |
| 4648 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 4649 | auto I = Pair.second.rbegin(); |
| 4650 | auto IS = IterSpaces.rbegin(); |
| 4651 | auto ILM = LoopMultipliers.rbegin(); |
| 4652 | Expr *UpCounterVal = CounterVal; |
| 4653 | Expr *Multiplier = nullptr; |
| 4654 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4655 | if (I->first) { |
| 4656 | assert(IS->CounterStep); |
| 4657 | Expr *NormalizedOffset = |
| 4658 | SemaRef |
| 4659 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 4660 | I->first, IS->CounterStep) |
| 4661 | .get(); |
| 4662 | if (Multiplier) { |
| 4663 | NormalizedOffset = |
| 4664 | SemaRef |
| 4665 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 4666 | NormalizedOffset, Multiplier) |
| 4667 | .get(); |
| 4668 | } |
| 4669 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 4670 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4671 | UpCounterVal = SemaRef |
| 4672 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 4673 | UpCounterVal, NormalizedOffset) |
| 4674 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4675 | } |
| 4676 | Multiplier = *ILM; |
| 4677 | ++I; |
| 4678 | ++IS; |
| 4679 | ++ILM; |
| 4680 | } |
| 4681 | Pair.first->setCounterValue(UpCounterVal); |
| 4682 | } |
| 4683 | } |
| 4684 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4685 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4688 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4689 | auto CollapseClauses = |
| 4690 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4691 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4692 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4693 | return nullptr; |
| 4694 | } |
| 4695 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4696 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4697 | auto OrderedClauses = |
| 4698 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4699 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4700 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4701 | return nullptr; |
| 4702 | } |
| 4703 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4704 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 4705 | const ArrayRef<OMPClause *> Clauses) { |
| 4706 | OMPSafelenClause *Safelen = nullptr; |
| 4707 | OMPSimdlenClause *Simdlen = nullptr; |
| 4708 | |
| 4709 | for (auto *Clause : Clauses) { |
| 4710 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4711 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4712 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4713 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4714 | if (Safelen && Simdlen) |
| 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | if (Simdlen && Safelen) { |
| 4719 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4720 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 4721 | auto SafelenLength = Safelen->getSafelen(); |
| 4722 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 4723 | SimdlenLength->isInstantiationDependent() || |
| 4724 | SimdlenLength->containsUnexpandedParameterPack()) |
| 4725 | return false; |
| 4726 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 4727 | SafelenLength->isInstantiationDependent() || |
| 4728 | SafelenLength->containsUnexpandedParameterPack()) |
| 4729 | return false; |
| 4730 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 4731 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 4732 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 4733 | // If both simdlen and safelen clauses are specified, the value of the |
| 4734 | // simdlen parameter must be less than or equal to the value of the safelen |
| 4735 | // parameter. |
| 4736 | if (SimdlenRes > SafelenRes) { |
| 4737 | S.Diag(SimdlenLength->getExprLoc(), |
| 4738 | diag::err_omp_wrong_simdlen_safelen_values) |
| 4739 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 4740 | return true; |
| 4741 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4742 | } |
| 4743 | return false; |
| 4744 | } |
| 4745 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4746 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4747 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4748 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4749 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4750 | if (!AStmt) |
| 4751 | return StmtError(); |
| 4752 | |
| 4753 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4754 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4755 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4756 | // define the nested loops number. |
| 4757 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4758 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4759 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4760 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4761 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4762 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4763 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4764 | "omp simd loop exprs were not built"); |
| 4765 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4766 | if (!CurContext->isDependentContext()) { |
| 4767 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4768 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4769 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4770 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4771 | B.NumIterations, *this, CurScope, |
| 4772 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4773 | return StmtError(); |
| 4774 | } |
| 4775 | } |
| 4776 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4777 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4778 | return StmtError(); |
| 4779 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4780 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4781 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4782 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4785 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4786 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4787 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4788 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4789 | if (!AStmt) |
| 4790 | return StmtError(); |
| 4791 | |
| 4792 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4793 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4794 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4795 | // define the nested loops number. |
| 4796 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4797 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4798 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4799 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4800 | return StmtError(); |
| 4801 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4802 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4803 | "omp for loop exprs were not built"); |
| 4804 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4805 | if (!CurContext->isDependentContext()) { |
| 4806 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4807 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4808 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4809 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4810 | B.NumIterations, *this, CurScope, |
| 4811 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4812 | return StmtError(); |
| 4813 | } |
| 4814 | } |
| 4815 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4816 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4817 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4818 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4821 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4822 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4823 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4824 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4825 | if (!AStmt) |
| 4826 | return StmtError(); |
| 4827 | |
| 4828 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4829 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4830 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4831 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4832 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4833 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4834 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4835 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4836 | if (NestedLoopCount == 0) |
| 4837 | return StmtError(); |
| 4838 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4839 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4840 | "omp for simd loop exprs were not built"); |
| 4841 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4842 | if (!CurContext->isDependentContext()) { |
| 4843 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4844 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4845 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4846 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4847 | B.NumIterations, *this, CurScope, |
| 4848 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4849 | return StmtError(); |
| 4850 | } |
| 4851 | } |
| 4852 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4853 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4854 | return StmtError(); |
| 4855 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4856 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4857 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4858 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4861 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4862 | Stmt *AStmt, |
| 4863 | SourceLocation StartLoc, |
| 4864 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4865 | if (!AStmt) |
| 4866 | return StmtError(); |
| 4867 | |
| 4868 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4869 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4870 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4871 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4872 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4873 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4874 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4875 | return StmtError(); |
| 4876 | // All associated statements must be '#pragma omp section' except for |
| 4877 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4878 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4879 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4880 | if (SectionStmt) |
| 4881 | Diag(SectionStmt->getLocStart(), |
| 4882 | diag::err_omp_sections_substmt_not_section); |
| 4883 | return StmtError(); |
| 4884 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4885 | cast<OMPSectionDirective>(SectionStmt) |
| 4886 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4887 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4888 | } else { |
| 4889 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4890 | return StmtError(); |
| 4891 | } |
| 4892 | |
| 4893 | getCurFunction()->setHasBranchProtectedScope(); |
| 4894 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4895 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4896 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4897 | } |
| 4898 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4899 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4900 | SourceLocation StartLoc, |
| 4901 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4902 | if (!AStmt) |
| 4903 | return StmtError(); |
| 4904 | |
| 4905 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4906 | |
| 4907 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4908 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4909 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4910 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4911 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4914 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4915 | Stmt *AStmt, |
| 4916 | SourceLocation StartLoc, |
| 4917 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4918 | if (!AStmt) |
| 4919 | return StmtError(); |
| 4920 | |
| 4921 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4922 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4923 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4924 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4925 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4926 | // The copyprivate clause must not be used with the nowait clause. |
| 4927 | OMPClause *Nowait = nullptr; |
| 4928 | OMPClause *Copyprivate = nullptr; |
| 4929 | for (auto *Clause : Clauses) { |
| 4930 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4931 | Nowait = Clause; |
| 4932 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4933 | Copyprivate = Clause; |
| 4934 | if (Copyprivate && Nowait) { |
| 4935 | Diag(Copyprivate->getLocStart(), |
| 4936 | diag::err_omp_single_copyprivate_with_nowait); |
| 4937 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4938 | return StmtError(); |
| 4939 | } |
| 4940 | } |
| 4941 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4942 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4943 | } |
| 4944 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4945 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4946 | SourceLocation StartLoc, |
| 4947 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4948 | if (!AStmt) |
| 4949 | return StmtError(); |
| 4950 | |
| 4951 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4952 | |
| 4953 | getCurFunction()->setHasBranchProtectedScope(); |
| 4954 | |
| 4955 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4956 | } |
| 4957 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4958 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4959 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4960 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4961 | if (!AStmt) |
| 4962 | return StmtError(); |
| 4963 | |
| 4964 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4965 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4966 | bool ErrorFound = false; |
| 4967 | llvm::APSInt Hint; |
| 4968 | SourceLocation HintLoc; |
| 4969 | bool DependentHint = false; |
| 4970 | for (auto *C : Clauses) { |
| 4971 | if (C->getClauseKind() == OMPC_hint) { |
| 4972 | if (!DirName.getName()) { |
| 4973 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4974 | ErrorFound = true; |
| 4975 | } |
| 4976 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4977 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4978 | E->isInstantiationDependent()) |
| 4979 | DependentHint = true; |
| 4980 | else { |
| 4981 | Hint = E->EvaluateKnownConstInt(Context); |
| 4982 | HintLoc = C->getLocStart(); |
| 4983 | } |
| 4984 | } |
| 4985 | } |
| 4986 | if (ErrorFound) |
| 4987 | return StmtError(); |
| 4988 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4989 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4990 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4991 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4992 | if (HintLoc.isValid()) { |
| 4993 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4994 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4995 | } else |
| 4996 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4997 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4998 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4999 | << 1 |
| 5000 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5001 | /*Radix=*/10, /*Signed=*/false); |
| 5002 | } else |
| 5003 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 5004 | } |
| 5005 | } |
| 5006 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5007 | getCurFunction()->setHasBranchProtectedScope(); |
| 5008 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5009 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5010 | Clauses, AStmt); |
| 5011 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5012 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5013 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5016 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5017 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5018 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5019 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5020 | if (!AStmt) |
| 5021 | return StmtError(); |
| 5022 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5023 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5024 | // 1.2.2 OpenMP Language Terminology |
| 5025 | // Structured block - An executable statement with a single entry at the |
| 5026 | // top and a single exit at the bottom. |
| 5027 | // The point of exit cannot be a branch out of the structured block. |
| 5028 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5029 | CS->getCapturedDecl()->setNothrow(); |
| 5030 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5031 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5032 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5033 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5034 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5035 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5036 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5037 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5038 | if (NestedLoopCount == 0) |
| 5039 | return StmtError(); |
| 5040 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5041 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5042 | "omp parallel for loop exprs were not built"); |
| 5043 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5044 | if (!CurContext->isDependentContext()) { |
| 5045 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5046 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5047 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5048 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5049 | B.NumIterations, *this, CurScope, |
| 5050 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5051 | return StmtError(); |
| 5052 | } |
| 5053 | } |
| 5054 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5055 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5056 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5057 | NestedLoopCount, Clauses, AStmt, B, |
| 5058 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5061 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5062 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5063 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5064 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5065 | if (!AStmt) |
| 5066 | return StmtError(); |
| 5067 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5068 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5069 | // 1.2.2 OpenMP Language Terminology |
| 5070 | // Structured block - An executable statement with a single entry at the |
| 5071 | // top and a single exit at the bottom. |
| 5072 | // The point of exit cannot be a branch out of the structured block. |
| 5073 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5074 | CS->getCapturedDecl()->setNothrow(); |
| 5075 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5076 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5077 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5078 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5079 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5080 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5081 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5082 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5083 | if (NestedLoopCount == 0) |
| 5084 | return StmtError(); |
| 5085 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5086 | if (!CurContext->isDependentContext()) { |
| 5087 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5088 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5089 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5090 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5091 | B.NumIterations, *this, CurScope, |
| 5092 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5093 | return StmtError(); |
| 5094 | } |
| 5095 | } |
| 5096 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5097 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5098 | return StmtError(); |
| 5099 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5100 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5101 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5102 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5105 | StmtResult |
| 5106 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5107 | Stmt *AStmt, SourceLocation StartLoc, |
| 5108 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5109 | if (!AStmt) |
| 5110 | return StmtError(); |
| 5111 | |
| 5112 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5113 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5114 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5115 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5116 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5117 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5118 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5119 | return StmtError(); |
| 5120 | // All associated statements must be '#pragma omp section' except for |
| 5121 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5122 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5123 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5124 | if (SectionStmt) |
| 5125 | Diag(SectionStmt->getLocStart(), |
| 5126 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5127 | return StmtError(); |
| 5128 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5129 | cast<OMPSectionDirective>(SectionStmt) |
| 5130 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5131 | } |
| 5132 | } else { |
| 5133 | Diag(AStmt->getLocStart(), |
| 5134 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5135 | return StmtError(); |
| 5136 | } |
| 5137 | |
| 5138 | getCurFunction()->setHasBranchProtectedScope(); |
| 5139 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5140 | return OMPParallelSectionsDirective::Create( |
| 5141 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5144 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5145 | Stmt *AStmt, SourceLocation StartLoc, |
| 5146 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5147 | if (!AStmt) |
| 5148 | return StmtError(); |
| 5149 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5150 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5151 | // 1.2.2 OpenMP Language Terminology |
| 5152 | // Structured block - An executable statement with a single entry at the |
| 5153 | // top and a single exit at the bottom. |
| 5154 | // The point of exit cannot be a branch out of the structured block. |
| 5155 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5156 | CS->getCapturedDecl()->setNothrow(); |
| 5157 | |
| 5158 | getCurFunction()->setHasBranchProtectedScope(); |
| 5159 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5160 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5161 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5164 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5165 | SourceLocation EndLoc) { |
| 5166 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5167 | } |
| 5168 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5169 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5170 | SourceLocation EndLoc) { |
| 5171 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5172 | } |
| 5173 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5174 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5175 | SourceLocation EndLoc) { |
| 5176 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5177 | } |
| 5178 | |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 5179 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
| 5180 | Stmt *AStmt, |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5181 | SourceLocation StartLoc, |
| 5182 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5183 | if (!AStmt) |
| 5184 | return StmtError(); |
| 5185 | |
| 5186 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5187 | |
| 5188 | getCurFunction()->setHasBranchProtectedScope(); |
| 5189 | |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 5190 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5191 | AStmt); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5194 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5195 | SourceLocation StartLoc, |
| 5196 | SourceLocation EndLoc) { |
| 5197 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5198 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5199 | } |
| 5200 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5201 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5202 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5203 | SourceLocation StartLoc, |
| 5204 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5205 | OMPClause *DependFound = nullptr; |
| 5206 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5207 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5208 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5209 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5210 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5211 | for (auto *C : Clauses) { |
| 5212 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5213 | DependFound = C; |
| 5214 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5215 | if (DependSourceClause) { |
| 5216 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5217 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5218 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5219 | ErrorFound = true; |
| 5220 | } else |
| 5221 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5222 | if (DependSinkClause) { |
| 5223 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5224 | << 0; |
| 5225 | ErrorFound = true; |
| 5226 | } |
| 5227 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5228 | if (DependSourceClause) { |
| 5229 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5230 | << 1; |
| 5231 | ErrorFound = true; |
| 5232 | } |
| 5233 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5234 | } |
| 5235 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5236 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5237 | else if (C->getClauseKind() == OMPC_simd) |
| 5238 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5239 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5240 | if (!ErrorFound && !SC && |
| 5241 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5242 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5243 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5244 | // that can appear in the simd region. |
| 5245 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5246 | ErrorFound = true; |
| 5247 | } else if (DependFound && (TC || SC)) { |
| 5248 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5249 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5250 | ErrorFound = true; |
| 5251 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5252 | Diag(DependFound->getLocStart(), |
| 5253 | diag::err_omp_ordered_directive_without_param); |
| 5254 | ErrorFound = true; |
| 5255 | } else if (TC || Clauses.empty()) { |
| 5256 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5257 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5258 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5259 | << (TC != nullptr); |
| 5260 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5261 | ErrorFound = true; |
| 5262 | } |
| 5263 | } |
| 5264 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5265 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5266 | |
| 5267 | if (AStmt) { |
| 5268 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5269 | |
| 5270 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5271 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5272 | |
| 5273 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5276 | namespace { |
| 5277 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5278 | /// construct. |
| 5279 | class OpenMPAtomicUpdateChecker { |
| 5280 | /// \brief Error results for atomic update expressions. |
| 5281 | enum ExprAnalysisErrorCode { |
| 5282 | /// \brief A statement is not an expression statement. |
| 5283 | NotAnExpression, |
| 5284 | /// \brief Expression is not builtin binary or unary operation. |
| 5285 | NotABinaryOrUnaryExpression, |
| 5286 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5287 | NotAnUnaryIncDecExpression, |
| 5288 | /// \brief An expression is not of scalar type. |
| 5289 | NotAScalarType, |
| 5290 | /// \brief A binary operation is not an assignment operation. |
| 5291 | NotAnAssignmentOp, |
| 5292 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5293 | NotABinaryExpression, |
| 5294 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5295 | /// expression. |
| 5296 | NotABinaryOperator, |
| 5297 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5298 | /// part. |
| 5299 | NotAnUpdateExpression, |
| 5300 | /// \brief No errors is found. |
| 5301 | NoError |
| 5302 | }; |
| 5303 | /// \brief Reference to Sema. |
| 5304 | Sema &SemaRef; |
| 5305 | /// \brief A location for note diagnostics (when error is found). |
| 5306 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5307 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5308 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5309 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5310 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5311 | /// \brief Helper expression of the form |
| 5312 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5313 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5314 | Expr *UpdateExpr; |
| 5315 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5316 | /// important for non-associative operations. |
| 5317 | bool IsXLHSInRHSPart; |
| 5318 | BinaryOperatorKind Op; |
| 5319 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5320 | /// \brief true if the source expression is a postfix unary operation, false |
| 5321 | /// if it is a prefix unary operation. |
| 5322 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5323 | |
| 5324 | public: |
| 5325 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5326 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5327 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5328 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5329 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5330 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5331 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5332 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5333 | /// \param NoteId Diagnostic note for the main error message. |
| 5334 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5335 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5336 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5337 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5338 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5339 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5340 | /// \brief Return the update expression used in calculation of the updated |
| 5341 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5342 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5343 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5344 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5345 | /// false otherwise. |
| 5346 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5347 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5348 | /// \brief true if the source expression is a postfix unary operation, false |
| 5349 | /// if it is a prefix unary operation. |
| 5350 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5351 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5352 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5353 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5354 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5355 | }; |
| 5356 | } // namespace |
| 5357 | |
| 5358 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5359 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5360 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5361 | SourceLocation ErrorLoc, NoteLoc; |
| 5362 | SourceRange ErrorRange, NoteRange; |
| 5363 | // Allowed constructs are: |
| 5364 | // x = x binop expr; |
| 5365 | // x = expr binop x; |
| 5366 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5367 | X = AtomicBinOp->getLHS(); |
| 5368 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5369 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5370 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5371 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5372 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5373 | Op = AtomicInnerBinOp->getOpcode(); |
| 5374 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5375 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5376 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5377 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5378 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5379 | /*Canonical=*/true); |
| 5380 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5381 | /*Canonical=*/true); |
| 5382 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5383 | /*Canonical=*/true); |
| 5384 | if (XId == LHSId) { |
| 5385 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5386 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5387 | } else if (XId == RHSId) { |
| 5388 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5389 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5390 | } else { |
| 5391 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5392 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5393 | NoteLoc = X->getExprLoc(); |
| 5394 | NoteRange = X->getSourceRange(); |
| 5395 | ErrorFound = NotAnUpdateExpression; |
| 5396 | } |
| 5397 | } else { |
| 5398 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5399 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5400 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5401 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5402 | ErrorFound = NotABinaryOperator; |
| 5403 | } |
| 5404 | } else { |
| 5405 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5406 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5407 | ErrorFound = NotABinaryExpression; |
| 5408 | } |
| 5409 | } else { |
| 5410 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5411 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5412 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5413 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5414 | ErrorFound = NotAnAssignmentOp; |
| 5415 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5416 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5417 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5418 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5419 | return true; |
| 5420 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5421 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5422 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5426 | unsigned NoteId) { |
| 5427 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5428 | SourceLocation ErrorLoc, NoteLoc; |
| 5429 | SourceRange ErrorRange, NoteRange; |
| 5430 | // Allowed constructs are: |
| 5431 | // x++; |
| 5432 | // x--; |
| 5433 | // ++x; |
| 5434 | // --x; |
| 5435 | // x binop= expr; |
| 5436 | // x = x binop expr; |
| 5437 | // x = expr binop x; |
| 5438 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5439 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5440 | if (AtomicBody->getType()->isScalarType() || |
| 5441 | AtomicBody->isInstantiationDependent()) { |
| 5442 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5443 | AtomicBody->IgnoreParenImpCasts())) { |
| 5444 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5445 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5446 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5447 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5448 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5449 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5450 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5451 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5452 | AtomicBody->IgnoreParenImpCasts())) { |
| 5453 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5454 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5455 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5456 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 5457 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5458 | // Check for Unary Operation |
| 5459 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5460 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5461 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5462 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5463 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5464 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5465 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5466 | } else { |
| 5467 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5468 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5469 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5470 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5471 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5472 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5473 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5474 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5475 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5476 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5477 | } |
| 5478 | } else { |
| 5479 | ErrorFound = NotAScalarType; |
| 5480 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5481 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5482 | } |
| 5483 | } else { |
| 5484 | ErrorFound = NotAnExpression; |
| 5485 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5486 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5487 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5488 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5489 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5490 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5491 | return true; |
| 5492 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5493 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5494 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5495 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5496 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5497 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5498 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5499 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5500 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5501 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5502 | auto Update = |
| 5503 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5504 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5505 | if (Update.isInvalid()) |
| 5506 | return true; |
| 5507 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5508 | Sema::AA_Casting); |
| 5509 | if (Update.isInvalid()) |
| 5510 | return true; |
| 5511 | UpdateExpr = Update.get(); |
| 5512 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5513 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5514 | } |
| 5515 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5516 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5517 | Stmt *AStmt, |
| 5518 | SourceLocation StartLoc, |
| 5519 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5520 | if (!AStmt) |
| 5521 | return StmtError(); |
| 5522 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5523 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5524 | // 1.2.2 OpenMP Language Terminology |
| 5525 | // Structured block - An executable statement with a single entry at the |
| 5526 | // top and a single exit at the bottom. |
| 5527 | // The point of exit cannot be a branch out of the structured block. |
| 5528 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5529 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5530 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5531 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5532 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5533 | C->getClauseKind() == OMPC_update || |
| 5534 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5535 | if (AtomicKind != OMPC_unknown) { |
| 5536 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5537 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5538 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5539 | << getOpenMPClauseName(AtomicKind); |
| 5540 | } else { |
| 5541 | AtomicKind = C->getClauseKind(); |
| 5542 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5543 | } |
| 5544 | } |
| 5545 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5546 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5547 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5548 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5549 | Body = EWC->getSubExpr(); |
| 5550 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5551 | Expr *X = nullptr; |
| 5552 | Expr *V = nullptr; |
| 5553 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5554 | Expr *UE = nullptr; |
| 5555 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5556 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5557 | // OpenMP [2.12.6, atomic Construct] |
| 5558 | // In the next expressions: |
| 5559 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5560 | // * During the execution of an atomic region, multiple syntactic |
| 5561 | // occurrences of x must designate the same storage location. |
| 5562 | // * Neither of v and expr (as applicable) may access the storage location |
| 5563 | // designated by x. |
| 5564 | // * Neither of x and expr (as applicable) may access the storage location |
| 5565 | // designated by v. |
| 5566 | // * expr is an expression with scalar type. |
| 5567 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5568 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5569 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5570 | // (expr). This requirement is satisfied if the operators in expr have |
| 5571 | // precedence greater than binop, or by using parentheses around expr or |
| 5572 | // subexpressions of expr. |
| 5573 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5574 | // binop x. This requirement is satisfied if the operators in expr have |
| 5575 | // precedence equal to or greater than binop, or by using parentheses around |
| 5576 | // expr or subexpressions of expr. |
| 5577 | // * For forms that allow multiple occurrences of x, the number of times |
| 5578 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5579 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5580 | enum { |
| 5581 | NotAnExpression, |
| 5582 | NotAnAssignmentOp, |
| 5583 | NotAScalarType, |
| 5584 | NotAnLValue, |
| 5585 | NoError |
| 5586 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5587 | SourceLocation ErrorLoc, NoteLoc; |
| 5588 | SourceRange ErrorRange, NoteRange; |
| 5589 | // If clause is read: |
| 5590 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5591 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5592 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5593 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5594 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5595 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5596 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5597 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5598 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5599 | if (!X->isLValue() || !V->isLValue()) { |
| 5600 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5601 | ErrorFound = NotAnLValue; |
| 5602 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5603 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5604 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5605 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5606 | } |
| 5607 | } else if (!X->isInstantiationDependent() || |
| 5608 | !V->isInstantiationDependent()) { |
| 5609 | auto NotScalarExpr = |
| 5610 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5611 | ? V |
| 5612 | : X; |
| 5613 | ErrorFound = NotAScalarType; |
| 5614 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5615 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5616 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5617 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5618 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5619 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5620 | ErrorFound = NotAnAssignmentOp; |
| 5621 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5622 | ErrorRange = AtomicBody->getSourceRange(); |
| 5623 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5624 | : AtomicBody->getExprLoc(); |
| 5625 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5626 | : AtomicBody->getSourceRange(); |
| 5627 | } |
| 5628 | } else { |
| 5629 | ErrorFound = NotAnExpression; |
| 5630 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5631 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5632 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5633 | if (ErrorFound != NoError) { |
| 5634 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5635 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5636 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5637 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5638 | return StmtError(); |
| 5639 | } else if (CurContext->isDependentContext()) |
| 5640 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5641 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5642 | enum { |
| 5643 | NotAnExpression, |
| 5644 | NotAnAssignmentOp, |
| 5645 | NotAScalarType, |
| 5646 | NotAnLValue, |
| 5647 | NoError |
| 5648 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5649 | SourceLocation ErrorLoc, NoteLoc; |
| 5650 | SourceRange ErrorRange, NoteRange; |
| 5651 | // If clause is write: |
| 5652 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5653 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5654 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5655 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5656 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5657 | X = AtomicBinOp->getLHS(); |
| 5658 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5659 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5660 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5661 | if (!X->isLValue()) { |
| 5662 | ErrorFound = NotAnLValue; |
| 5663 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5664 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5665 | NoteLoc = X->getExprLoc(); |
| 5666 | NoteRange = X->getSourceRange(); |
| 5667 | } |
| 5668 | } else if (!X->isInstantiationDependent() || |
| 5669 | !E->isInstantiationDependent()) { |
| 5670 | auto NotScalarExpr = |
| 5671 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5672 | ? E |
| 5673 | : X; |
| 5674 | ErrorFound = NotAScalarType; |
| 5675 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5676 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5677 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5678 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5679 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5680 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5681 | ErrorFound = NotAnAssignmentOp; |
| 5682 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5683 | ErrorRange = AtomicBody->getSourceRange(); |
| 5684 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5685 | : AtomicBody->getExprLoc(); |
| 5686 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5687 | : AtomicBody->getSourceRange(); |
| 5688 | } |
| 5689 | } else { |
| 5690 | ErrorFound = NotAnExpression; |
| 5691 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5692 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5693 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5694 | if (ErrorFound != NoError) { |
| 5695 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5696 | << ErrorRange; |
| 5697 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5698 | << NoteRange; |
| 5699 | return StmtError(); |
| 5700 | } else if (CurContext->isDependentContext()) |
| 5701 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5702 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5703 | // If clause is update: |
| 5704 | // x++; |
| 5705 | // x--; |
| 5706 | // ++x; |
| 5707 | // --x; |
| 5708 | // x binop= expr; |
| 5709 | // x = x binop expr; |
| 5710 | // x = expr binop x; |
| 5711 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5712 | if (Checker.checkStatement( |
| 5713 | Body, (AtomicKind == OMPC_update) |
| 5714 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5715 | : diag::err_omp_atomic_not_expression_statement, |
| 5716 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5717 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5718 | if (!CurContext->isDependentContext()) { |
| 5719 | E = Checker.getExpr(); |
| 5720 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5721 | UE = Checker.getUpdateExpr(); |
| 5722 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5723 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5724 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5725 | enum { |
| 5726 | NotAnAssignmentOp, |
| 5727 | NotACompoundStatement, |
| 5728 | NotTwoSubstatements, |
| 5729 | NotASpecificExpression, |
| 5730 | NoError |
| 5731 | } ErrorFound = NoError; |
| 5732 | SourceLocation ErrorLoc, NoteLoc; |
| 5733 | SourceRange ErrorRange, NoteRange; |
| 5734 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5735 | // If clause is a capture: |
| 5736 | // v = x++; |
| 5737 | // v = x--; |
| 5738 | // v = ++x; |
| 5739 | // v = --x; |
| 5740 | // v = x binop= expr; |
| 5741 | // v = x = x binop expr; |
| 5742 | // v = x = expr binop x; |
| 5743 | auto *AtomicBinOp = |
| 5744 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5745 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5746 | V = AtomicBinOp->getLHS(); |
| 5747 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5748 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5749 | if (Checker.checkStatement( |
| 5750 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5751 | diag::note_omp_atomic_update)) |
| 5752 | return StmtError(); |
| 5753 | E = Checker.getExpr(); |
| 5754 | X = Checker.getX(); |
| 5755 | UE = Checker.getUpdateExpr(); |
| 5756 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5757 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5758 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5759 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5760 | ErrorRange = AtomicBody->getSourceRange(); |
| 5761 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5762 | : AtomicBody->getExprLoc(); |
| 5763 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5764 | : AtomicBody->getSourceRange(); |
| 5765 | ErrorFound = NotAnAssignmentOp; |
| 5766 | } |
| 5767 | if (ErrorFound != NoError) { |
| 5768 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5769 | << ErrorRange; |
| 5770 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5771 | return StmtError(); |
| 5772 | } else if (CurContext->isDependentContext()) { |
| 5773 | UE = V = E = X = nullptr; |
| 5774 | } |
| 5775 | } else { |
| 5776 | // If clause is a capture: |
| 5777 | // { v = x; x = expr; } |
| 5778 | // { v = x; x++; } |
| 5779 | // { v = x; x--; } |
| 5780 | // { v = x; ++x; } |
| 5781 | // { v = x; --x; } |
| 5782 | // { v = x; x binop= expr; } |
| 5783 | // { v = x; x = x binop expr; } |
| 5784 | // { v = x; x = expr binop x; } |
| 5785 | // { x++; v = x; } |
| 5786 | // { x--; v = x; } |
| 5787 | // { ++x; v = x; } |
| 5788 | // { --x; v = x; } |
| 5789 | // { x binop= expr; v = x; } |
| 5790 | // { x = x binop expr; v = x; } |
| 5791 | // { x = expr binop x; v = x; } |
| 5792 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5793 | // Check that this is { expr1; expr2; } |
| 5794 | if (CS->size() == 2) { |
| 5795 | auto *First = CS->body_front(); |
| 5796 | auto *Second = CS->body_back(); |
| 5797 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5798 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5799 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5800 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5801 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5802 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5803 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5804 | BinaryOperator *BinOp = nullptr; |
| 5805 | if (IsUpdateExprFound) { |
| 5806 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5807 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5808 | } |
| 5809 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5810 | // { v = x; x++; } |
| 5811 | // { v = x; x--; } |
| 5812 | // { v = x; ++x; } |
| 5813 | // { v = x; --x; } |
| 5814 | // { v = x; x binop= expr; } |
| 5815 | // { v = x; x = x binop expr; } |
| 5816 | // { v = x; x = expr binop x; } |
| 5817 | // Check that the first expression has form v = x. |
| 5818 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5819 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5820 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5821 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5822 | IsUpdateExprFound = XId == PossibleXId; |
| 5823 | if (IsUpdateExprFound) { |
| 5824 | V = BinOp->getLHS(); |
| 5825 | X = Checker.getX(); |
| 5826 | E = Checker.getExpr(); |
| 5827 | UE = Checker.getUpdateExpr(); |
| 5828 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5829 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5830 | } |
| 5831 | } |
| 5832 | if (!IsUpdateExprFound) { |
| 5833 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5834 | BinOp = nullptr; |
| 5835 | if (IsUpdateExprFound) { |
| 5836 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5837 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5838 | } |
| 5839 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5840 | // { x++; v = x; } |
| 5841 | // { x--; v = x; } |
| 5842 | // { ++x; v = x; } |
| 5843 | // { --x; v = x; } |
| 5844 | // { x binop= expr; v = x; } |
| 5845 | // { x = x binop expr; v = x; } |
| 5846 | // { x = expr binop x; v = x; } |
| 5847 | // Check that the second expression has form v = x. |
| 5848 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5849 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5850 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5851 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5852 | IsUpdateExprFound = XId == PossibleXId; |
| 5853 | if (IsUpdateExprFound) { |
| 5854 | V = BinOp->getLHS(); |
| 5855 | X = Checker.getX(); |
| 5856 | E = Checker.getExpr(); |
| 5857 | UE = Checker.getUpdateExpr(); |
| 5858 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5859 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5860 | } |
| 5861 | } |
| 5862 | } |
| 5863 | if (!IsUpdateExprFound) { |
| 5864 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5865 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5866 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5867 | if (!FirstExpr || !SecondExpr || |
| 5868 | !(FirstExpr->isInstantiationDependent() || |
| 5869 | SecondExpr->isInstantiationDependent())) { |
| 5870 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5871 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5872 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5873 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5874 | : First->getLocStart(); |
| 5875 | NoteRange = ErrorRange = FirstBinOp |
| 5876 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5877 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5878 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5879 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5880 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5881 | ErrorFound = NotAnAssignmentOp; |
| 5882 | NoteLoc = ErrorLoc = SecondBinOp |
| 5883 | ? SecondBinOp->getOperatorLoc() |
| 5884 | : Second->getLocStart(); |
| 5885 | NoteRange = ErrorRange = |
| 5886 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5887 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5888 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5889 | auto *PossibleXRHSInFirst = |
| 5890 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5891 | auto *PossibleXLHSInSecond = |
| 5892 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5893 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5894 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5895 | /*Canonical=*/true); |
| 5896 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5897 | /*Canonical=*/true); |
| 5898 | IsUpdateExprFound = X1Id == X2Id; |
| 5899 | if (IsUpdateExprFound) { |
| 5900 | V = FirstBinOp->getLHS(); |
| 5901 | X = SecondBinOp->getLHS(); |
| 5902 | E = SecondBinOp->getRHS(); |
| 5903 | UE = nullptr; |
| 5904 | IsXLHSInRHSPart = false; |
| 5905 | IsPostfixUpdate = true; |
| 5906 | } else { |
| 5907 | ErrorFound = NotASpecificExpression; |
| 5908 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5909 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5910 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5911 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5912 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5913 | } |
| 5914 | } |
| 5915 | } |
| 5916 | } |
| 5917 | } else { |
| 5918 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5919 | NoteRange = ErrorRange = |
| 5920 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5921 | ErrorFound = NotTwoSubstatements; |
| 5922 | } |
| 5923 | } else { |
| 5924 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5925 | NoteRange = ErrorRange = |
| 5926 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5927 | ErrorFound = NotACompoundStatement; |
| 5928 | } |
| 5929 | if (ErrorFound != NoError) { |
| 5930 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5931 | << ErrorRange; |
| 5932 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5933 | return StmtError(); |
| 5934 | } else if (CurContext->isDependentContext()) { |
| 5935 | UE = V = E = X = nullptr; |
| 5936 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5937 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5938 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5939 | |
| 5940 | getCurFunction()->setHasBranchProtectedScope(); |
| 5941 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5942 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5943 | X, V, E, UE, IsXLHSInRHSPart, |
| 5944 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5945 | } |
| 5946 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5947 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5948 | Stmt *AStmt, |
| 5949 | SourceLocation StartLoc, |
| 5950 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5951 | if (!AStmt) |
| 5952 | return StmtError(); |
| 5953 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5954 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5955 | // 1.2.2 OpenMP Language Terminology |
| 5956 | // Structured block - An executable statement with a single entry at the |
| 5957 | // top and a single exit at the bottom. |
| 5958 | // The point of exit cannot be a branch out of the structured block. |
| 5959 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5960 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5961 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5962 | // OpenMP [2.16, Nesting of Regions] |
| 5963 | // If specified, a teams construct must be contained within a target |
| 5964 | // construct. That target construct must contain no statements or directives |
| 5965 | // outside of the teams construct. |
| 5966 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5967 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5968 | bool OMPTeamsFound = true; |
| 5969 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5970 | auto I = CS->body_begin(); |
| 5971 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5972 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5973 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5974 | OMPTeamsFound = false; |
| 5975 | break; |
| 5976 | } |
| 5977 | ++I; |
| 5978 | } |
| 5979 | assert(I != CS->body_end() && "Not found statement"); |
| 5980 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 5981 | } else { |
| 5982 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 5983 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5984 | } |
| 5985 | if (!OMPTeamsFound) { |
| 5986 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5987 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5988 | diag::note_omp_nested_teams_construct_here); |
| 5989 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5990 | << isa<OMPExecutableDirective>(S); |
| 5991 | return StmtError(); |
| 5992 | } |
| 5993 | } |
| 5994 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5995 | getCurFunction()->setHasBranchProtectedScope(); |
| 5996 | |
| 5997 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5998 | } |
| 5999 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6000 | StmtResult |
| 6001 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6002 | Stmt *AStmt, SourceLocation StartLoc, |
| 6003 | SourceLocation EndLoc) { |
| 6004 | if (!AStmt) |
| 6005 | return StmtError(); |
| 6006 | |
| 6007 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6008 | // 1.2.2 OpenMP Language Terminology |
| 6009 | // Structured block - An executable statement with a single entry at the |
| 6010 | // top and a single exit at the bottom. |
| 6011 | // The point of exit cannot be a branch out of the structured block. |
| 6012 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6013 | CS->getCapturedDecl()->setNothrow(); |
| 6014 | |
| 6015 | getCurFunction()->setHasBranchProtectedScope(); |
| 6016 | |
| 6017 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6018 | AStmt); |
| 6019 | } |
| 6020 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6021 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6022 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6023 | SourceLocation EndLoc, |
| 6024 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6025 | if (!AStmt) |
| 6026 | return StmtError(); |
| 6027 | |
| 6028 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6029 | // 1.2.2 OpenMP Language Terminology |
| 6030 | // Structured block - An executable statement with a single entry at the |
| 6031 | // top and a single exit at the bottom. |
| 6032 | // The point of exit cannot be a branch out of the structured block. |
| 6033 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6034 | CS->getCapturedDecl()->setNothrow(); |
| 6035 | |
| 6036 | OMPLoopDirective::HelperExprs B; |
| 6037 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6038 | // define the nested loops number. |
| 6039 | unsigned NestedLoopCount = |
| 6040 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6041 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6042 | VarsWithImplicitDSA, B); |
| 6043 | if (NestedLoopCount == 0) |
| 6044 | return StmtError(); |
| 6045 | |
| 6046 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6047 | "omp target parallel for loop exprs were not built"); |
| 6048 | |
| 6049 | if (!CurContext->isDependentContext()) { |
| 6050 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6051 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6052 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6053 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6054 | B.NumIterations, *this, CurScope, |
| 6055 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6056 | return StmtError(); |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | getCurFunction()->setHasBranchProtectedScope(); |
| 6061 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6062 | NestedLoopCount, Clauses, AStmt, |
| 6063 | B, DSAStack->isCancelRegion()); |
| 6064 | } |
| 6065 | |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6066 | /// Check for existence of a map clause in the list of clauses. |
| 6067 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, |
| 6068 | const OpenMPClauseKind K) { |
| 6069 | return llvm::any_of( |
| 6070 | Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; }); |
| 6071 | } |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6072 | |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6073 | template <typename... Params> |
| 6074 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, const OpenMPClauseKind K, |
| 6075 | const Params... ClauseTypes) { |
| 6076 | return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...); |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6079 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6080 | Stmt *AStmt, |
| 6081 | SourceLocation StartLoc, |
| 6082 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6083 | if (!AStmt) |
| 6084 | return StmtError(); |
| 6085 | |
| 6086 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6087 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6088 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6089 | // At least one map clause must appear on the directive. |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6090 | if (!hasClauses(Clauses, OMPC_map, OMPC_use_device_ptr)) { |
| 6091 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6092 | << "'map' or 'use_device_ptr'" |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6093 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6094 | return StmtError(); |
| 6095 | } |
| 6096 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6097 | getCurFunction()->setHasBranchProtectedScope(); |
| 6098 | |
| 6099 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6100 | AStmt); |
| 6101 | } |
| 6102 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6103 | StmtResult |
| 6104 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6105 | SourceLocation StartLoc, |
| 6106 | SourceLocation EndLoc) { |
| 6107 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6108 | // At least one map clause must appear on the directive. |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6109 | if (!hasClauses(Clauses, OMPC_map)) { |
| 6110 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6111 | << "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data); |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6112 | return StmtError(); |
| 6113 | } |
| 6114 | |
| 6115 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6116 | Clauses); |
| 6117 | } |
| 6118 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6119 | StmtResult |
| 6120 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6121 | SourceLocation StartLoc, |
| 6122 | SourceLocation EndLoc) { |
| 6123 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6124 | // At least one map clause must appear on the directive. |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6125 | if (!hasClauses(Clauses, OMPC_map)) { |
| 6126 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 6127 | << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data); |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6128 | return StmtError(); |
| 6129 | } |
| 6130 | |
| 6131 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6132 | } |
| 6133 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6134 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 6135 | SourceLocation StartLoc, |
| 6136 | SourceLocation EndLoc) { |
Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 6137 | if (!hasClauses(Clauses, OMPC_to, OMPC_from)) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6138 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 6139 | return StmtError(); |
| 6140 | } |
| 6141 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6142 | } |
| 6143 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6144 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6145 | Stmt *AStmt, SourceLocation StartLoc, |
| 6146 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6147 | if (!AStmt) |
| 6148 | return StmtError(); |
| 6149 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6150 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6151 | // 1.2.2 OpenMP Language Terminology |
| 6152 | // Structured block - An executable statement with a single entry at the |
| 6153 | // top and a single exit at the bottom. |
| 6154 | // The point of exit cannot be a branch out of the structured block. |
| 6155 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6156 | CS->getCapturedDecl()->setNothrow(); |
| 6157 | |
| 6158 | getCurFunction()->setHasBranchProtectedScope(); |
| 6159 | |
| 6160 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6161 | } |
| 6162 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6163 | StmtResult |
| 6164 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6165 | SourceLocation EndLoc, |
| 6166 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6167 | if (DSAStack->isParentNowaitRegion()) { |
| 6168 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6169 | return StmtError(); |
| 6170 | } |
| 6171 | if (DSAStack->isParentOrderedRegion()) { |
| 6172 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6173 | return StmtError(); |
| 6174 | } |
| 6175 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6176 | CancelRegion); |
| 6177 | } |
| 6178 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6179 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6180 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6181 | SourceLocation EndLoc, |
| 6182 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6183 | if (DSAStack->isParentNowaitRegion()) { |
| 6184 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6185 | return StmtError(); |
| 6186 | } |
| 6187 | if (DSAStack->isParentOrderedRegion()) { |
| 6188 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6189 | return StmtError(); |
| 6190 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6191 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6192 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6193 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6196 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6197 | ArrayRef<OMPClause *> Clauses) { |
| 6198 | OMPClause *PrevClause = nullptr; |
| 6199 | bool ErrorFound = false; |
| 6200 | for (auto *C : Clauses) { |
| 6201 | if (C->getClauseKind() == OMPC_grainsize || |
| 6202 | C->getClauseKind() == OMPC_num_tasks) { |
| 6203 | if (!PrevClause) |
| 6204 | PrevClause = C; |
| 6205 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6206 | S.Diag(C->getLocStart(), |
| 6207 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6208 | << getOpenMPClauseName(C->getClauseKind()) |
| 6209 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6210 | S.Diag(PrevClause->getLocStart(), |
| 6211 | diag::note_omp_previous_grainsize_num_tasks) |
| 6212 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6213 | ErrorFound = true; |
| 6214 | } |
| 6215 | } |
| 6216 | } |
| 6217 | return ErrorFound; |
| 6218 | } |
| 6219 | |
Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 6220 | static bool checkReductionClauseWithNogroup(Sema &S, |
| 6221 | ArrayRef<OMPClause *> Clauses) { |
| 6222 | OMPClause *ReductionClause = nullptr; |
| 6223 | OMPClause *NogroupClause = nullptr; |
| 6224 | for (auto *C : Clauses) { |
| 6225 | if (C->getClauseKind() == OMPC_reduction) { |
| 6226 | ReductionClause = C; |
| 6227 | if (NogroupClause) |
| 6228 | break; |
| 6229 | continue; |
| 6230 | } |
| 6231 | if (C->getClauseKind() == OMPC_nogroup) { |
| 6232 | NogroupClause = C; |
| 6233 | if (ReductionClause) |
| 6234 | break; |
| 6235 | continue; |
| 6236 | } |
| 6237 | } |
| 6238 | if (ReductionClause && NogroupClause) { |
| 6239 | S.Diag(ReductionClause->getLocStart(), diag::err_omp_reduction_with_nogroup) |
| 6240 | << SourceRange(NogroupClause->getLocStart(), |
| 6241 | NogroupClause->getLocEnd()); |
| 6242 | return true; |
| 6243 | } |
| 6244 | return false; |
| 6245 | } |
| 6246 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6247 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6248 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6249 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6250 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6251 | if (!AStmt) |
| 6252 | return StmtError(); |
| 6253 | |
| 6254 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6255 | OMPLoopDirective::HelperExprs B; |
| 6256 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6257 | // define the nested loops number. |
| 6258 | unsigned NestedLoopCount = |
| 6259 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6260 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6261 | VarsWithImplicitDSA, B); |
| 6262 | if (NestedLoopCount == 0) |
| 6263 | return StmtError(); |
| 6264 | |
| 6265 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6266 | "omp for loop exprs were not built"); |
| 6267 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6268 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6269 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6270 | // not appear on the same taskloop directive. |
| 6271 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6272 | return StmtError(); |
Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 6273 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6274 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 6275 | // clause must not be specified. |
| 6276 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 6277 | return StmtError(); |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6278 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6279 | getCurFunction()->setHasBranchProtectedScope(); |
| 6280 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6281 | NestedLoopCount, Clauses, AStmt, B); |
| 6282 | } |
| 6283 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6284 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6285 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6286 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6287 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6288 | if (!AStmt) |
| 6289 | return StmtError(); |
| 6290 | |
| 6291 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6292 | OMPLoopDirective::HelperExprs B; |
| 6293 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6294 | // define the nested loops number. |
| 6295 | unsigned NestedLoopCount = |
| 6296 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6297 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6298 | VarsWithImplicitDSA, B); |
| 6299 | if (NestedLoopCount == 0) |
| 6300 | return StmtError(); |
| 6301 | |
| 6302 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6303 | "omp for loop exprs were not built"); |
| 6304 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6305 | if (!CurContext->isDependentContext()) { |
| 6306 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6307 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6308 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6309 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6310 | B.NumIterations, *this, CurScope, |
| 6311 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6312 | return StmtError(); |
| 6313 | } |
| 6314 | } |
| 6315 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6316 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6317 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6318 | // not appear on the same taskloop directive. |
| 6319 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6320 | return StmtError(); |
Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 6321 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6322 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 6323 | // clause must not be specified. |
| 6324 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 6325 | return StmtError(); |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6326 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6327 | getCurFunction()->setHasBranchProtectedScope(); |
| 6328 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6329 | NestedLoopCount, Clauses, AStmt, B); |
| 6330 | } |
| 6331 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6332 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6333 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6334 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6335 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6336 | if (!AStmt) |
| 6337 | return StmtError(); |
| 6338 | |
| 6339 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6340 | OMPLoopDirective::HelperExprs B; |
| 6341 | // In presence of clause 'collapse' with number of loops, it will |
| 6342 | // define the nested loops number. |
| 6343 | unsigned NestedLoopCount = |
| 6344 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6345 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6346 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6347 | if (NestedLoopCount == 0) |
| 6348 | return StmtError(); |
| 6349 | |
| 6350 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6351 | "omp for loop exprs were not built"); |
| 6352 | |
| 6353 | getCurFunction()->setHasBranchProtectedScope(); |
| 6354 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6355 | NestedLoopCount, Clauses, AStmt, B); |
| 6356 | } |
| 6357 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 6358 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 6359 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6360 | SourceLocation EndLoc, |
| 6361 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6362 | if (!AStmt) |
| 6363 | return StmtError(); |
| 6364 | |
| 6365 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6366 | // 1.2.2 OpenMP Language Terminology |
| 6367 | // Structured block - An executable statement with a single entry at the |
| 6368 | // top and a single exit at the bottom. |
| 6369 | // The point of exit cannot be a branch out of the structured block. |
| 6370 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6371 | CS->getCapturedDecl()->setNothrow(); |
| 6372 | |
| 6373 | OMPLoopDirective::HelperExprs B; |
| 6374 | // In presence of clause 'collapse' with number of loops, it will |
| 6375 | // define the nested loops number. |
| 6376 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6377 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6378 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6379 | VarsWithImplicitDSA, B); |
| 6380 | if (NestedLoopCount == 0) |
| 6381 | return StmtError(); |
| 6382 | |
| 6383 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6384 | "omp for loop exprs were not built"); |
| 6385 | |
| 6386 | getCurFunction()->setHasBranchProtectedScope(); |
| 6387 | return OMPDistributeParallelForDirective::Create( |
| 6388 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6389 | } |
| 6390 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6391 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 6392 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6393 | SourceLocation EndLoc, |
| 6394 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6395 | if (!AStmt) |
| 6396 | return StmtError(); |
| 6397 | |
| 6398 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6399 | // 1.2.2 OpenMP Language Terminology |
| 6400 | // Structured block - An executable statement with a single entry at the |
| 6401 | // top and a single exit at the bottom. |
| 6402 | // The point of exit cannot be a branch out of the structured block. |
| 6403 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6404 | CS->getCapturedDecl()->setNothrow(); |
| 6405 | |
| 6406 | OMPLoopDirective::HelperExprs B; |
| 6407 | // In presence of clause 'collapse' with number of loops, it will |
| 6408 | // define the nested loops number. |
| 6409 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6410 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6411 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6412 | VarsWithImplicitDSA, B); |
| 6413 | if (NestedLoopCount == 0) |
| 6414 | return StmtError(); |
| 6415 | |
| 6416 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6417 | "omp for loop exprs were not built"); |
| 6418 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6419 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6420 | return StmtError(); |
| 6421 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6422 | getCurFunction()->setHasBranchProtectedScope(); |
| 6423 | return OMPDistributeParallelForSimdDirective::Create( |
| 6424 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6425 | } |
| 6426 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6427 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 6428 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6429 | SourceLocation EndLoc, |
| 6430 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6431 | if (!AStmt) |
| 6432 | return StmtError(); |
| 6433 | |
| 6434 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6435 | // 1.2.2 OpenMP Language Terminology |
| 6436 | // Structured block - An executable statement with a single entry at the |
| 6437 | // top and a single exit at the bottom. |
| 6438 | // The point of exit cannot be a branch out of the structured block. |
| 6439 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6440 | CS->getCapturedDecl()->setNothrow(); |
| 6441 | |
| 6442 | OMPLoopDirective::HelperExprs B; |
| 6443 | // In presence of clause 'collapse' with number of loops, it will |
| 6444 | // define the nested loops number. |
| 6445 | unsigned NestedLoopCount = |
| 6446 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6447 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6448 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6449 | if (NestedLoopCount == 0) |
| 6450 | return StmtError(); |
| 6451 | |
| 6452 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6453 | "omp for loop exprs were not built"); |
| 6454 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6455 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6456 | return StmtError(); |
| 6457 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6458 | getCurFunction()->setHasBranchProtectedScope(); |
| 6459 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6460 | NestedLoopCount, Clauses, AStmt, B); |
| 6461 | } |
| 6462 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6463 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 6464 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6465 | SourceLocation EndLoc, |
| 6466 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6467 | if (!AStmt) |
| 6468 | return StmtError(); |
| 6469 | |
| 6470 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6471 | // 1.2.2 OpenMP Language Terminology |
| 6472 | // Structured block - An executable statement with a single entry at the |
| 6473 | // top and a single exit at the bottom. |
| 6474 | // The point of exit cannot be a branch out of the structured block. |
| 6475 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6476 | CS->getCapturedDecl()->setNothrow(); |
| 6477 | |
| 6478 | OMPLoopDirective::HelperExprs B; |
| 6479 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6480 | // define the nested loops number. |
| 6481 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6482 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6483 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6484 | VarsWithImplicitDSA, B); |
| 6485 | if (NestedLoopCount == 0) |
| 6486 | return StmtError(); |
| 6487 | |
| 6488 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6489 | "omp target parallel for simd loop exprs were not built"); |
| 6490 | |
| 6491 | if (!CurContext->isDependentContext()) { |
| 6492 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6493 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6494 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6495 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6496 | B.NumIterations, *this, CurScope, |
| 6497 | DSAStack)) |
| 6498 | return StmtError(); |
| 6499 | } |
| 6500 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6501 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6502 | return StmtError(); |
| 6503 | |
| 6504 | getCurFunction()->setHasBranchProtectedScope(); |
| 6505 | return OMPTargetParallelForSimdDirective::Create( |
| 6506 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6507 | } |
| 6508 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6509 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 6510 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6511 | SourceLocation EndLoc, |
| 6512 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6513 | if (!AStmt) |
| 6514 | return StmtError(); |
| 6515 | |
| 6516 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6517 | // 1.2.2 OpenMP Language Terminology |
| 6518 | // Structured block - An executable statement with a single entry at the |
| 6519 | // top and a single exit at the bottom. |
| 6520 | // The point of exit cannot be a branch out of the structured block. |
| 6521 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6522 | CS->getCapturedDecl()->setNothrow(); |
| 6523 | |
| 6524 | OMPLoopDirective::HelperExprs B; |
| 6525 | // In presence of clause 'collapse' with number of loops, it will define the |
| 6526 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6527 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6528 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 6529 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6530 | VarsWithImplicitDSA, B); |
| 6531 | if (NestedLoopCount == 0) |
| 6532 | return StmtError(); |
| 6533 | |
| 6534 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6535 | "omp target simd loop exprs were not built"); |
| 6536 | |
| 6537 | if (!CurContext->isDependentContext()) { |
| 6538 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6539 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6540 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6541 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6542 | B.NumIterations, *this, CurScope, |
| 6543 | DSAStack)) |
| 6544 | return StmtError(); |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6549 | return StmtError(); |
| 6550 | |
| 6551 | getCurFunction()->setHasBranchProtectedScope(); |
| 6552 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6553 | NestedLoopCount, Clauses, AStmt, B); |
| 6554 | } |
| 6555 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6556 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 6557 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6558 | SourceLocation EndLoc, |
| 6559 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6560 | if (!AStmt) |
| 6561 | return StmtError(); |
| 6562 | |
| 6563 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6564 | // 1.2.2 OpenMP Language Terminology |
| 6565 | // Structured block - An executable statement with a single entry at the |
| 6566 | // top and a single exit at the bottom. |
| 6567 | // The point of exit cannot be a branch out of the structured block. |
| 6568 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6569 | CS->getCapturedDecl()->setNothrow(); |
| 6570 | |
| 6571 | OMPLoopDirective::HelperExprs B; |
| 6572 | // In presence of clause 'collapse' with number of loops, it will |
| 6573 | // define the nested loops number. |
| 6574 | unsigned NestedLoopCount = |
| 6575 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 6576 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6577 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6578 | if (NestedLoopCount == 0) |
| 6579 | return StmtError(); |
| 6580 | |
| 6581 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6582 | "omp teams distribute loop exprs were not built"); |
| 6583 | |
| 6584 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6585 | return OMPTeamsDistributeDirective::Create( |
| 6586 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6587 | } |
| 6588 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6589 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 6590 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6591 | SourceLocation EndLoc, |
| 6592 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6593 | if (!AStmt) |
| 6594 | return StmtError(); |
| 6595 | |
| 6596 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6597 | // 1.2.2 OpenMP Language Terminology |
| 6598 | // Structured block - An executable statement with a single entry at the |
| 6599 | // top and a single exit at the bottom. |
| 6600 | // The point of exit cannot be a branch out of the structured block. |
| 6601 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6602 | CS->getCapturedDecl()->setNothrow(); |
| 6603 | |
| 6604 | OMPLoopDirective::HelperExprs B; |
| 6605 | // In presence of clause 'collapse' with number of loops, it will |
| 6606 | // define the nested loops number. |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 6607 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6608 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6609 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6610 | VarsWithImplicitDSA, B); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6611 | |
| 6612 | if (NestedLoopCount == 0) |
| 6613 | return StmtError(); |
| 6614 | |
| 6615 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6616 | "omp teams distribute simd loop exprs were not built"); |
| 6617 | |
| 6618 | if (!CurContext->isDependentContext()) { |
| 6619 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6620 | for (auto C : Clauses) { |
| 6621 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6622 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6623 | B.NumIterations, *this, CurScope, |
| 6624 | DSAStack)) |
| 6625 | return StmtError(); |
| 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6630 | return StmtError(); |
| 6631 | |
| 6632 | getCurFunction()->setHasBranchProtectedScope(); |
| 6633 | return OMPTeamsDistributeSimdDirective::Create( |
| 6634 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6635 | } |
| 6636 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 6637 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 6638 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6639 | SourceLocation EndLoc, |
| 6640 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6641 | if (!AStmt) |
| 6642 | return StmtError(); |
| 6643 | |
| 6644 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6645 | // 1.2.2 OpenMP Language Terminology |
| 6646 | // Structured block - An executable statement with a single entry at the |
| 6647 | // top and a single exit at the bottom. |
| 6648 | // The point of exit cannot be a branch out of the structured block. |
| 6649 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6650 | CS->getCapturedDecl()->setNothrow(); |
| 6651 | |
| 6652 | OMPLoopDirective::HelperExprs B; |
| 6653 | // In presence of clause 'collapse' with number of loops, it will |
| 6654 | // define the nested loops number. |
| 6655 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6656 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6657 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6658 | VarsWithImplicitDSA, B); |
| 6659 | |
| 6660 | if (NestedLoopCount == 0) |
| 6661 | return StmtError(); |
| 6662 | |
| 6663 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6664 | "omp for loop exprs were not built"); |
| 6665 | |
| 6666 | if (!CurContext->isDependentContext()) { |
| 6667 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6668 | for (auto C : Clauses) { |
| 6669 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6670 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6671 | B.NumIterations, *this, CurScope, |
| 6672 | DSAStack)) |
| 6673 | return StmtError(); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6678 | return StmtError(); |
| 6679 | |
| 6680 | getCurFunction()->setHasBranchProtectedScope(); |
| 6681 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 6682 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6683 | } |
| 6684 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 6685 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 6686 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6687 | SourceLocation EndLoc, |
| 6688 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6689 | if (!AStmt) |
| 6690 | return StmtError(); |
| 6691 | |
| 6692 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6693 | // 1.2.2 OpenMP Language Terminology |
| 6694 | // Structured block - An executable statement with a single entry at the |
| 6695 | // top and a single exit at the bottom. |
| 6696 | // The point of exit cannot be a branch out of the structured block. |
| 6697 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6698 | CS->getCapturedDecl()->setNothrow(); |
| 6699 | |
| 6700 | OMPLoopDirective::HelperExprs B; |
| 6701 | // In presence of clause 'collapse' with number of loops, it will |
| 6702 | // define the nested loops number. |
| 6703 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6704 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6705 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6706 | VarsWithImplicitDSA, B); |
| 6707 | |
| 6708 | if (NestedLoopCount == 0) |
| 6709 | return StmtError(); |
| 6710 | |
| 6711 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6712 | "omp for loop exprs were not built"); |
| 6713 | |
| 6714 | if (!CurContext->isDependentContext()) { |
| 6715 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6716 | for (auto C : Clauses) { |
| 6717 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6718 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6719 | B.NumIterations, *this, CurScope, |
| 6720 | DSAStack)) |
| 6721 | return StmtError(); |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | getCurFunction()->setHasBranchProtectedScope(); |
| 6726 | return OMPTeamsDistributeParallelForDirective::Create( |
| 6727 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6728 | } |
| 6729 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 6730 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6731 | Stmt *AStmt, |
| 6732 | SourceLocation StartLoc, |
| 6733 | SourceLocation EndLoc) { |
| 6734 | if (!AStmt) |
| 6735 | return StmtError(); |
| 6736 | |
| 6737 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6738 | // 1.2.2 OpenMP Language Terminology |
| 6739 | // Structured block - An executable statement with a single entry at the |
| 6740 | // top and a single exit at the bottom. |
| 6741 | // The point of exit cannot be a branch out of the structured block. |
| 6742 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6743 | CS->getCapturedDecl()->setNothrow(); |
| 6744 | |
| 6745 | getCurFunction()->setHasBranchProtectedScope(); |
| 6746 | |
| 6747 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6748 | AStmt); |
| 6749 | } |
| 6750 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 6751 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 6752 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6753 | SourceLocation EndLoc, |
| 6754 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6755 | if (!AStmt) |
| 6756 | return StmtError(); |
| 6757 | |
| 6758 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6759 | // 1.2.2 OpenMP Language Terminology |
| 6760 | // Structured block - An executable statement with a single entry at the |
| 6761 | // top and a single exit at the bottom. |
| 6762 | // The point of exit cannot be a branch out of the structured block. |
| 6763 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6764 | CS->getCapturedDecl()->setNothrow(); |
| 6765 | |
| 6766 | OMPLoopDirective::HelperExprs B; |
| 6767 | // In presence of clause 'collapse' with number of loops, it will |
| 6768 | // define the nested loops number. |
| 6769 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6770 | OMPD_target_teams_distribute, |
| 6771 | getCollapseNumberExpr(Clauses), |
| 6772 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6773 | VarsWithImplicitDSA, B); |
| 6774 | if (NestedLoopCount == 0) |
| 6775 | return StmtError(); |
| 6776 | |
| 6777 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6778 | "omp target teams distribute loop exprs were not built"); |
| 6779 | |
| 6780 | getCurFunction()->setHasBranchProtectedScope(); |
| 6781 | return OMPTargetTeamsDistributeDirective::Create( |
| 6782 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6783 | } |
| 6784 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 6785 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 6786 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6787 | SourceLocation EndLoc, |
| 6788 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6789 | if (!AStmt) |
| 6790 | return StmtError(); |
| 6791 | |
| 6792 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6793 | // 1.2.2 OpenMP Language Terminology |
| 6794 | // Structured block - An executable statement with a single entry at the |
| 6795 | // top and a single exit at the bottom. |
| 6796 | // The point of exit cannot be a branch out of the structured block. |
| 6797 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6798 | CS->getCapturedDecl()->setNothrow(); |
| 6799 | |
| 6800 | OMPLoopDirective::HelperExprs B; |
| 6801 | // In presence of clause 'collapse' with number of loops, it will |
| 6802 | // define the nested loops number. |
| 6803 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6804 | OMPD_target_teams_distribute_parallel_for, |
| 6805 | getCollapseNumberExpr(Clauses), |
| 6806 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6807 | VarsWithImplicitDSA, B); |
| 6808 | if (NestedLoopCount == 0) |
| 6809 | return StmtError(); |
| 6810 | |
| 6811 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6812 | "omp target teams distribute parallel for loop exprs were not built"); |
| 6813 | |
| 6814 | if (!CurContext->isDependentContext()) { |
| 6815 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6816 | for (auto C : Clauses) { |
| 6817 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6818 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6819 | B.NumIterations, *this, CurScope, |
| 6820 | DSAStack)) |
| 6821 | return StmtError(); |
| 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | getCurFunction()->setHasBranchProtectedScope(); |
| 6826 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| 6827 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6828 | } |
| 6829 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 6830 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 6831 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6832 | SourceLocation EndLoc, |
| 6833 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6834 | if (!AStmt) |
| 6835 | return StmtError(); |
| 6836 | |
| 6837 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 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 | OMPLoopDirective::HelperExprs B; |
| 6846 | // In presence of clause 'collapse' with number of loops, it will |
| 6847 | // define the nested loops number. |
| 6848 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6849 | OMPD_target_teams_distribute_parallel_for_simd, |
| 6850 | getCollapseNumberExpr(Clauses), |
| 6851 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6852 | VarsWithImplicitDSA, B); |
| 6853 | if (NestedLoopCount == 0) |
| 6854 | return StmtError(); |
| 6855 | |
| 6856 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6857 | "omp target teams distribute parallel for simd loop exprs were not " |
| 6858 | "built"); |
| 6859 | |
| 6860 | if (!CurContext->isDependentContext()) { |
| 6861 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6862 | for (auto C : Clauses) { |
| 6863 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6864 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6865 | B.NumIterations, *this, CurScope, |
| 6866 | DSAStack)) |
| 6867 | return StmtError(); |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | getCurFunction()->setHasBranchProtectedScope(); |
| 6872 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 6873 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6874 | } |
| 6875 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 6876 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 6877 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6878 | SourceLocation EndLoc, |
| 6879 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6880 | if (!AStmt) |
| 6881 | return StmtError(); |
| 6882 | |
| 6883 | auto *CS = cast<CapturedStmt>(AStmt); |
| 6884 | // 1.2.2 OpenMP Language Terminology |
| 6885 | // Structured block - An executable statement with a single entry at the |
| 6886 | // top and a single exit at the bottom. |
| 6887 | // The point of exit cannot be a branch out of the structured block. |
| 6888 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6889 | CS->getCapturedDecl()->setNothrow(); |
| 6890 | |
| 6891 | OMPLoopDirective::HelperExprs B; |
| 6892 | // In presence of clause 'collapse' with number of loops, it will |
| 6893 | // define the nested loops number. |
| 6894 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6895 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6896 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6897 | VarsWithImplicitDSA, B); |
| 6898 | if (NestedLoopCount == 0) |
| 6899 | return StmtError(); |
| 6900 | |
| 6901 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6902 | "omp target teams distribute simd loop exprs were not built"); |
| 6903 | |
| 6904 | getCurFunction()->setHasBranchProtectedScope(); |
| 6905 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 6906 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6907 | } |
| 6908 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6909 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6910 | SourceLocation StartLoc, |
| 6911 | SourceLocation LParenLoc, |
| 6912 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6913 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6914 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6915 | case OMPC_final: |
| 6916 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6917 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6918 | case OMPC_num_threads: |
| 6919 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6920 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6921 | case OMPC_safelen: |
| 6922 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6923 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6924 | case OMPC_simdlen: |
| 6925 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6926 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6927 | case OMPC_collapse: |
| 6928 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6929 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6930 | case OMPC_ordered: |
| 6931 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6932 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6933 | case OMPC_device: |
| 6934 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6935 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6936 | case OMPC_num_teams: |
| 6937 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6938 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6939 | case OMPC_thread_limit: |
| 6940 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6941 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6942 | case OMPC_priority: |
| 6943 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6944 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6945 | case OMPC_grainsize: |
| 6946 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6947 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6948 | case OMPC_num_tasks: |
| 6949 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6950 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6951 | case OMPC_hint: |
| 6952 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6953 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6954 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6955 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6956 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6957 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6958 | case OMPC_private: |
| 6959 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6960 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6961 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6962 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 6963 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 6964 | case OMPC_in_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6965 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6966 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6967 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6968 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6969 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6970 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6971 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6972 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6973 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6974 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6975 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6976 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6977 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6978 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6979 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6980 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6981 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6982 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6983 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6984 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6985 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6986 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6987 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6988 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6989 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6990 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6991 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6992 | llvm_unreachable("Clause is not allowed."); |
| 6993 | } |
| 6994 | return Res; |
| 6995 | } |
| 6996 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 6997 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 6998 | // for the 'target' and 'parallel' respectively. This function returns |
| 6999 | // the region in which to capture expressions associated with a clause. |
| 7000 | // A return value of OMPD_unknown signifies that the expression should not |
| 7001 | // be captured. |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7002 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| 7003 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 7004 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7005 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| 7006 | |
| 7007 | switch (CKind) { |
| 7008 | case OMPC_if: |
| 7009 | switch (DKind) { |
| 7010 | case OMPD_target_parallel: |
| 7011 | // If this clause applies to the nested 'parallel' region, capture within |
| 7012 | // the 'target' region, otherwise do not capture. |
| 7013 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 7014 | CaptureRegion = OMPD_target; |
| 7015 | break; |
| 7016 | case OMPD_cancel: |
| 7017 | case OMPD_parallel: |
| 7018 | case OMPD_parallel_sections: |
| 7019 | case OMPD_parallel_for: |
| 7020 | case OMPD_parallel_for_simd: |
| 7021 | case OMPD_target: |
| 7022 | case OMPD_target_simd: |
| 7023 | case OMPD_target_parallel_for: |
| 7024 | case OMPD_target_parallel_for_simd: |
| 7025 | case OMPD_target_teams: |
| 7026 | case OMPD_target_teams_distribute: |
| 7027 | case OMPD_target_teams_distribute_simd: |
| 7028 | case OMPD_target_teams_distribute_parallel_for: |
| 7029 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 7030 | case OMPD_teams_distribute_parallel_for: |
| 7031 | case OMPD_teams_distribute_parallel_for_simd: |
| 7032 | case OMPD_distribute_parallel_for: |
| 7033 | case OMPD_distribute_parallel_for_simd: |
| 7034 | case OMPD_task: |
| 7035 | case OMPD_taskloop: |
| 7036 | case OMPD_taskloop_simd: |
| 7037 | case OMPD_target_data: |
| 7038 | case OMPD_target_enter_data: |
| 7039 | case OMPD_target_exit_data: |
| 7040 | case OMPD_target_update: |
| 7041 | // Do not capture if-clause expressions. |
| 7042 | break; |
| 7043 | case OMPD_threadprivate: |
| 7044 | case OMPD_taskyield: |
| 7045 | case OMPD_barrier: |
| 7046 | case OMPD_taskwait: |
| 7047 | case OMPD_cancellation_point: |
| 7048 | case OMPD_flush: |
| 7049 | case OMPD_declare_reduction: |
| 7050 | case OMPD_declare_simd: |
| 7051 | case OMPD_declare_target: |
| 7052 | case OMPD_end_declare_target: |
| 7053 | case OMPD_teams: |
| 7054 | case OMPD_simd: |
| 7055 | case OMPD_for: |
| 7056 | case OMPD_for_simd: |
| 7057 | case OMPD_sections: |
| 7058 | case OMPD_section: |
| 7059 | case OMPD_single: |
| 7060 | case OMPD_master: |
| 7061 | case OMPD_critical: |
| 7062 | case OMPD_taskgroup: |
| 7063 | case OMPD_distribute: |
| 7064 | case OMPD_ordered: |
| 7065 | case OMPD_atomic: |
| 7066 | case OMPD_distribute_simd: |
| 7067 | case OMPD_teams_distribute: |
| 7068 | case OMPD_teams_distribute_simd: |
| 7069 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 7070 | case OMPD_unknown: |
| 7071 | llvm_unreachable("Unknown OpenMP directive"); |
| 7072 | } |
| 7073 | break; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7074 | case OMPC_num_threads: |
| 7075 | switch (DKind) { |
| 7076 | case OMPD_target_parallel: |
| 7077 | CaptureRegion = OMPD_target; |
| 7078 | break; |
| 7079 | case OMPD_cancel: |
| 7080 | case OMPD_parallel: |
| 7081 | case OMPD_parallel_sections: |
| 7082 | case OMPD_parallel_for: |
| 7083 | case OMPD_parallel_for_simd: |
| 7084 | case OMPD_target: |
| 7085 | case OMPD_target_simd: |
| 7086 | case OMPD_target_parallel_for: |
| 7087 | case OMPD_target_parallel_for_simd: |
| 7088 | case OMPD_target_teams: |
| 7089 | case OMPD_target_teams_distribute: |
| 7090 | case OMPD_target_teams_distribute_simd: |
| 7091 | case OMPD_target_teams_distribute_parallel_for: |
| 7092 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 7093 | case OMPD_teams_distribute_parallel_for: |
| 7094 | case OMPD_teams_distribute_parallel_for_simd: |
| 7095 | case OMPD_distribute_parallel_for: |
| 7096 | case OMPD_distribute_parallel_for_simd: |
| 7097 | case OMPD_task: |
| 7098 | case OMPD_taskloop: |
| 7099 | case OMPD_taskloop_simd: |
| 7100 | case OMPD_target_data: |
| 7101 | case OMPD_target_enter_data: |
| 7102 | case OMPD_target_exit_data: |
| 7103 | case OMPD_target_update: |
| 7104 | // Do not capture num_threads-clause expressions. |
| 7105 | break; |
| 7106 | case OMPD_threadprivate: |
| 7107 | case OMPD_taskyield: |
| 7108 | case OMPD_barrier: |
| 7109 | case OMPD_taskwait: |
| 7110 | case OMPD_cancellation_point: |
| 7111 | case OMPD_flush: |
| 7112 | case OMPD_declare_reduction: |
| 7113 | case OMPD_declare_simd: |
| 7114 | case OMPD_declare_target: |
| 7115 | case OMPD_end_declare_target: |
| 7116 | case OMPD_teams: |
| 7117 | case OMPD_simd: |
| 7118 | case OMPD_for: |
| 7119 | case OMPD_for_simd: |
| 7120 | case OMPD_sections: |
| 7121 | case OMPD_section: |
| 7122 | case OMPD_single: |
| 7123 | case OMPD_master: |
| 7124 | case OMPD_critical: |
| 7125 | case OMPD_taskgroup: |
| 7126 | case OMPD_distribute: |
| 7127 | case OMPD_ordered: |
| 7128 | case OMPD_atomic: |
| 7129 | case OMPD_distribute_simd: |
| 7130 | case OMPD_teams_distribute: |
| 7131 | case OMPD_teams_distribute_simd: |
| 7132 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 7133 | case OMPD_unknown: |
| 7134 | llvm_unreachable("Unknown OpenMP directive"); |
| 7135 | } |
| 7136 | break; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 7137 | case OMPC_num_teams: |
| 7138 | switch (DKind) { |
| 7139 | case OMPD_target_teams: |
| 7140 | CaptureRegion = OMPD_target; |
| 7141 | break; |
| 7142 | case OMPD_cancel: |
| 7143 | case OMPD_parallel: |
| 7144 | case OMPD_parallel_sections: |
| 7145 | case OMPD_parallel_for: |
| 7146 | case OMPD_parallel_for_simd: |
| 7147 | case OMPD_target: |
| 7148 | case OMPD_target_simd: |
| 7149 | case OMPD_target_parallel: |
| 7150 | case OMPD_target_parallel_for: |
| 7151 | case OMPD_target_parallel_for_simd: |
| 7152 | case OMPD_target_teams_distribute: |
| 7153 | case OMPD_target_teams_distribute_simd: |
| 7154 | case OMPD_target_teams_distribute_parallel_for: |
| 7155 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 7156 | case OMPD_teams_distribute_parallel_for: |
| 7157 | case OMPD_teams_distribute_parallel_for_simd: |
| 7158 | case OMPD_distribute_parallel_for: |
| 7159 | case OMPD_distribute_parallel_for_simd: |
| 7160 | case OMPD_task: |
| 7161 | case OMPD_taskloop: |
| 7162 | case OMPD_taskloop_simd: |
| 7163 | case OMPD_target_data: |
| 7164 | case OMPD_target_enter_data: |
| 7165 | case OMPD_target_exit_data: |
| 7166 | case OMPD_target_update: |
| 7167 | case OMPD_teams: |
| 7168 | case OMPD_teams_distribute: |
| 7169 | case OMPD_teams_distribute_simd: |
| 7170 | // Do not capture num_teams-clause expressions. |
| 7171 | break; |
| 7172 | case OMPD_threadprivate: |
| 7173 | case OMPD_taskyield: |
| 7174 | case OMPD_barrier: |
| 7175 | case OMPD_taskwait: |
| 7176 | case OMPD_cancellation_point: |
| 7177 | case OMPD_flush: |
| 7178 | case OMPD_declare_reduction: |
| 7179 | case OMPD_declare_simd: |
| 7180 | case OMPD_declare_target: |
| 7181 | case OMPD_end_declare_target: |
| 7182 | case OMPD_simd: |
| 7183 | case OMPD_for: |
| 7184 | case OMPD_for_simd: |
| 7185 | case OMPD_sections: |
| 7186 | case OMPD_section: |
| 7187 | case OMPD_single: |
| 7188 | case OMPD_master: |
| 7189 | case OMPD_critical: |
| 7190 | case OMPD_taskgroup: |
| 7191 | case OMPD_distribute: |
| 7192 | case OMPD_ordered: |
| 7193 | case OMPD_atomic: |
| 7194 | case OMPD_distribute_simd: |
| 7195 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 7196 | case OMPD_unknown: |
| 7197 | llvm_unreachable("Unknown OpenMP directive"); |
| 7198 | } |
| 7199 | break; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 7200 | case OMPC_thread_limit: |
| 7201 | switch (DKind) { |
| 7202 | case OMPD_target_teams: |
| 7203 | CaptureRegion = OMPD_target; |
| 7204 | break; |
| 7205 | case OMPD_cancel: |
| 7206 | case OMPD_parallel: |
| 7207 | case OMPD_parallel_sections: |
| 7208 | case OMPD_parallel_for: |
| 7209 | case OMPD_parallel_for_simd: |
| 7210 | case OMPD_target: |
| 7211 | case OMPD_target_simd: |
| 7212 | case OMPD_target_parallel: |
| 7213 | case OMPD_target_parallel_for: |
| 7214 | case OMPD_target_parallel_for_simd: |
| 7215 | case OMPD_target_teams_distribute: |
| 7216 | case OMPD_target_teams_distribute_simd: |
| 7217 | case OMPD_target_teams_distribute_parallel_for: |
| 7218 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 7219 | case OMPD_teams_distribute_parallel_for: |
| 7220 | case OMPD_teams_distribute_parallel_for_simd: |
| 7221 | case OMPD_distribute_parallel_for: |
| 7222 | case OMPD_distribute_parallel_for_simd: |
| 7223 | case OMPD_task: |
| 7224 | case OMPD_taskloop: |
| 7225 | case OMPD_taskloop_simd: |
| 7226 | case OMPD_target_data: |
| 7227 | case OMPD_target_enter_data: |
| 7228 | case OMPD_target_exit_data: |
| 7229 | case OMPD_target_update: |
| 7230 | case OMPD_teams: |
| 7231 | case OMPD_teams_distribute: |
| 7232 | case OMPD_teams_distribute_simd: |
| 7233 | // Do not capture thread_limit-clause expressions. |
| 7234 | break; |
| 7235 | case OMPD_threadprivate: |
| 7236 | case OMPD_taskyield: |
| 7237 | case OMPD_barrier: |
| 7238 | case OMPD_taskwait: |
| 7239 | case OMPD_cancellation_point: |
| 7240 | case OMPD_flush: |
| 7241 | case OMPD_declare_reduction: |
| 7242 | case OMPD_declare_simd: |
| 7243 | case OMPD_declare_target: |
| 7244 | case OMPD_end_declare_target: |
| 7245 | case OMPD_simd: |
| 7246 | case OMPD_for: |
| 7247 | case OMPD_for_simd: |
| 7248 | case OMPD_sections: |
| 7249 | case OMPD_section: |
| 7250 | case OMPD_single: |
| 7251 | case OMPD_master: |
| 7252 | case OMPD_critical: |
| 7253 | case OMPD_taskgroup: |
| 7254 | case OMPD_distribute: |
| 7255 | case OMPD_ordered: |
| 7256 | case OMPD_atomic: |
| 7257 | case OMPD_distribute_simd: |
| 7258 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 7259 | case OMPD_unknown: |
| 7260 | llvm_unreachable("Unknown OpenMP directive"); |
| 7261 | } |
| 7262 | break; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7263 | case OMPC_schedule: |
| 7264 | case OMPC_dist_schedule: |
| 7265 | case OMPC_firstprivate: |
| 7266 | case OMPC_lastprivate: |
| 7267 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 7268 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 7269 | case OMPC_in_reduction: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7270 | case OMPC_linear: |
| 7271 | case OMPC_default: |
| 7272 | case OMPC_proc_bind: |
| 7273 | case OMPC_final: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7274 | case OMPC_safelen: |
| 7275 | case OMPC_simdlen: |
| 7276 | case OMPC_collapse: |
| 7277 | case OMPC_private: |
| 7278 | case OMPC_shared: |
| 7279 | case OMPC_aligned: |
| 7280 | case OMPC_copyin: |
| 7281 | case OMPC_copyprivate: |
| 7282 | case OMPC_ordered: |
| 7283 | case OMPC_nowait: |
| 7284 | case OMPC_untied: |
| 7285 | case OMPC_mergeable: |
| 7286 | case OMPC_threadprivate: |
| 7287 | case OMPC_flush: |
| 7288 | case OMPC_read: |
| 7289 | case OMPC_write: |
| 7290 | case OMPC_update: |
| 7291 | case OMPC_capture: |
| 7292 | case OMPC_seq_cst: |
| 7293 | case OMPC_depend: |
| 7294 | case OMPC_device: |
| 7295 | case OMPC_threads: |
| 7296 | case OMPC_simd: |
| 7297 | case OMPC_map: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7298 | case OMPC_priority: |
| 7299 | case OMPC_grainsize: |
| 7300 | case OMPC_nogroup: |
| 7301 | case OMPC_num_tasks: |
| 7302 | case OMPC_hint: |
| 7303 | case OMPC_defaultmap: |
| 7304 | case OMPC_unknown: |
| 7305 | case OMPC_uniform: |
| 7306 | case OMPC_to: |
| 7307 | case OMPC_from: |
| 7308 | case OMPC_use_device_ptr: |
| 7309 | case OMPC_is_device_ptr: |
| 7310 | llvm_unreachable("Unexpected OpenMP clause."); |
| 7311 | } |
| 7312 | return CaptureRegion; |
| 7313 | } |
| 7314 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7315 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7316 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7317 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7318 | SourceLocation NameModifierLoc, |
| 7319 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7320 | SourceLocation EndLoc) { |
| 7321 | Expr *ValExpr = Condition; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7322 | Stmt *HelperValStmt = nullptr; |
| 7323 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7324 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7325 | !Condition->isInstantiationDependent() && |
| 7326 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7327 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7328 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7329 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7330 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7331 | ValExpr = MakeFullExpr(Val.get()).get(); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7332 | |
| 7333 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7334 | CaptureRegion = |
| 7335 | getOpenMPCaptureRegionForClause(DKind, OMPC_if, NameModifier); |
| 7336 | if (CaptureRegion != OMPD_unknown) { |
| 7337 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7338 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7339 | HelperValStmt = buildPreInits(Context, Captures); |
| 7340 | } |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7343 | return new (Context) |
| 7344 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 7345 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7348 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7349 | SourceLocation StartLoc, |
| 7350 | SourceLocation LParenLoc, |
| 7351 | SourceLocation EndLoc) { |
| 7352 | Expr *ValExpr = Condition; |
| 7353 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7354 | !Condition->isInstantiationDependent() && |
| 7355 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7356 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7357 | if (Val.isInvalid()) |
| 7358 | return nullptr; |
| 7359 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7360 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
| 7363 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7364 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7365 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7366 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7367 | if (!Op) |
| 7368 | return ExprError(); |
| 7369 | |
| 7370 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7371 | public: |
| 7372 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7373 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7374 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7375 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7376 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7377 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7378 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7379 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7380 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7381 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7382 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7383 | QualType T, |
| 7384 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7385 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7386 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7387 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7388 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7389 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7390 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7391 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7392 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7393 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7394 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7395 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7396 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7397 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7398 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7399 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7400 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7401 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7402 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7403 | llvm_unreachable("conversion functions are permitted"); |
| 7404 | } |
| 7405 | } ConvertDiagnoser; |
| 7406 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7407 | } |
| 7408 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7409 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7410 | OpenMPClauseKind CKind, |
| 7411 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7412 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7413 | !ValExpr->isInstantiationDependent()) { |
| 7414 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7415 | ExprResult Value = |
| 7416 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7417 | if (Value.isInvalid()) |
| 7418 | return false; |
| 7419 | |
| 7420 | ValExpr = Value.get(); |
| 7421 | // The expression must evaluate to a non-negative integer value. |
| 7422 | llvm::APSInt Result; |
| 7423 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7424 | Result.isSigned() && |
| 7425 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7426 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7427 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7428 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7429 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7430 | return false; |
| 7431 | } |
| 7432 | } |
| 7433 | return true; |
| 7434 | } |
| 7435 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7436 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7437 | SourceLocation StartLoc, |
| 7438 | SourceLocation LParenLoc, |
| 7439 | SourceLocation EndLoc) { |
| 7440 | Expr *ValExpr = NumThreads; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7441 | Stmt *HelperValStmt = nullptr; |
| 7442 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7443 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7444 | // OpenMP [2.5, Restrictions] |
| 7445 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7446 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7447 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7448 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7449 | |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7450 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7451 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads); |
| 7452 | if (CaptureRegion != OMPD_unknown) { |
| 7453 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7454 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7455 | HelperValStmt = buildPreInits(Context, Captures); |
| 7456 | } |
| 7457 | |
| 7458 | return new (Context) OMPNumThreadsClause( |
| 7459 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7460 | } |
| 7461 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7462 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7463 | OpenMPClauseKind CKind, |
| 7464 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7465 | if (!E) |
| 7466 | return ExprError(); |
| 7467 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7468 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7469 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7470 | llvm::APSInt Result; |
| 7471 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7472 | if (ICE.isInvalid()) |
| 7473 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7474 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7475 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7476 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7477 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7478 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7479 | return ExprError(); |
| 7480 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7481 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7482 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7483 | << E->getSourceRange(); |
| 7484 | return ExprError(); |
| 7485 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7486 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7487 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7488 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7489 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7490 | return ICE; |
| 7491 | } |
| 7492 | |
| 7493 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7494 | SourceLocation LParenLoc, |
| 7495 | SourceLocation EndLoc) { |
| 7496 | // OpenMP [2.8.1, simd construct, Description] |
| 7497 | // The parameter of the safelen clause must be a constant |
| 7498 | // positive integer expression. |
| 7499 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7500 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7501 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7502 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7503 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7504 | } |
| 7505 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7506 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7507 | SourceLocation LParenLoc, |
| 7508 | SourceLocation EndLoc) { |
| 7509 | // OpenMP [2.8.1, simd construct, Description] |
| 7510 | // The parameter of the simdlen clause must be a constant |
| 7511 | // positive integer expression. |
| 7512 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7513 | if (Simdlen.isInvalid()) |
| 7514 | return nullptr; |
| 7515 | return new (Context) |
| 7516 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7517 | } |
| 7518 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7519 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7520 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7521 | SourceLocation LParenLoc, |
| 7522 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7523 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7524 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7525 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7526 | // The parameter of the collapse clause must be a constant |
| 7527 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7528 | ExprResult NumForLoopsResult = |
| 7529 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7530 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7531 | return nullptr; |
| 7532 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7533 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7534 | } |
| 7535 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7536 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7537 | SourceLocation EndLoc, |
| 7538 | SourceLocation LParenLoc, |
| 7539 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7540 | // OpenMP [2.7.1, loop construct, Description] |
| 7541 | // OpenMP [2.8.1, simd construct, Description] |
| 7542 | // OpenMP [2.9.6, distribute construct, Description] |
| 7543 | // The parameter of the ordered clause must be a constant |
| 7544 | // positive integer expression if any. |
| 7545 | if (NumForLoops && LParenLoc.isValid()) { |
| 7546 | ExprResult NumForLoopsResult = |
| 7547 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7548 | if (NumForLoopsResult.isInvalid()) |
| 7549 | return nullptr; |
| 7550 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7551 | } else |
| 7552 | NumForLoops = nullptr; |
| 7553 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7554 | return new (Context) |
| 7555 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7556 | } |
| 7557 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7558 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7559 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7560 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7561 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7562 | switch (Kind) { |
| 7563 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7564 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7565 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7566 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7567 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7568 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7569 | Res = ActOnOpenMPProcBindClause( |
| 7570 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7571 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7572 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7573 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7574 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7575 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7576 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7577 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7578 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7579 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7580 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7581 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7582 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7583 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7584 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 7585 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 7586 | case OMPC_in_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7587 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7588 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7589 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7590 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7591 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7592 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7593 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7594 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7595 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7596 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7597 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7598 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7599 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7600 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7601 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7602 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7603 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7604 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7605 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7606 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7607 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7608 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7609 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7610 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7611 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7612 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7613 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7614 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7615 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7616 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7617 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7618 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7619 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7620 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7621 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7622 | llvm_unreachable("Clause is not allowed."); |
| 7623 | } |
| 7624 | return Res; |
| 7625 | } |
| 7626 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7627 | static std::string |
| 7628 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7629 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7630 | std::string Values; |
| 7631 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7632 | unsigned Skipped = Exclude.size(); |
| 7633 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7634 | for (unsigned i = First; i < Last; ++i) { |
| 7635 | if (std::find(S, E, i) != E) { |
| 7636 | --Skipped; |
| 7637 | continue; |
| 7638 | } |
| 7639 | Values += "'"; |
| 7640 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7641 | Values += "'"; |
| 7642 | if (i == Bound - Skipped) |
| 7643 | Values += " or "; |
| 7644 | else if (i != Bound + 1 - Skipped) |
| 7645 | Values += ", "; |
| 7646 | } |
| 7647 | return Values; |
| 7648 | } |
| 7649 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7650 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7651 | SourceLocation KindKwLoc, |
| 7652 | SourceLocation StartLoc, |
| 7653 | SourceLocation LParenLoc, |
| 7654 | SourceLocation EndLoc) { |
| 7655 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7656 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7657 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7658 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7659 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7660 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7661 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7662 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7663 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7664 | switch (Kind) { |
| 7665 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7666 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7667 | break; |
| 7668 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7669 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7670 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7671 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7672 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7673 | break; |
| 7674 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7675 | return new (Context) |
| 7676 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7677 | } |
| 7678 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7679 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7680 | SourceLocation KindKwLoc, |
| 7681 | SourceLocation StartLoc, |
| 7682 | SourceLocation LParenLoc, |
| 7683 | SourceLocation EndLoc) { |
| 7684 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7685 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7686 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7687 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7688 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7689 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7690 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7691 | return new (Context) |
| 7692 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7693 | } |
| 7694 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7695 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7696 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7697 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7698 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7699 | SourceLocation EndLoc) { |
| 7700 | OMPClause *Res = nullptr; |
| 7701 | switch (Kind) { |
| 7702 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7703 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7704 | assert(Argument.size() == NumberOfElements && |
| 7705 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7706 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7707 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7708 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7709 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7710 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7711 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7712 | break; |
| 7713 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7714 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7715 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7716 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7717 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7718 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7719 | case OMPC_dist_schedule: |
| 7720 | Res = ActOnOpenMPDistScheduleClause( |
| 7721 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7722 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7723 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7724 | case OMPC_defaultmap: |
| 7725 | enum { Modifier, DefaultmapKind }; |
| 7726 | Res = ActOnOpenMPDefaultmapClause( |
| 7727 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7728 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7729 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7730 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7731 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7732 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7733 | case OMPC_num_threads: |
| 7734 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7735 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7736 | case OMPC_collapse: |
| 7737 | case OMPC_default: |
| 7738 | case OMPC_proc_bind: |
| 7739 | case OMPC_private: |
| 7740 | case OMPC_firstprivate: |
| 7741 | case OMPC_lastprivate: |
| 7742 | case OMPC_shared: |
| 7743 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 7744 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 7745 | case OMPC_in_reduction: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7746 | case OMPC_linear: |
| 7747 | case OMPC_aligned: |
| 7748 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7749 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7750 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7751 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7752 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7753 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7754 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7755 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7756 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7757 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7758 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7759 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7760 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7761 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7762 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7763 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7764 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7765 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7766 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7767 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7768 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7769 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7770 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7771 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7772 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7773 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7774 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7775 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7776 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7777 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7778 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7779 | llvm_unreachable("Clause is not allowed."); |
| 7780 | } |
| 7781 | return Res; |
| 7782 | } |
| 7783 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7784 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7785 | OpenMPScheduleClauseModifier M2, |
| 7786 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7787 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7788 | SmallVector<unsigned, 2> Excluded; |
| 7789 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7790 | Excluded.push_back(M2); |
| 7791 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7792 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7793 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7794 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7795 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7796 | << getListOfPossibleValues(OMPC_schedule, |
| 7797 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7798 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7799 | Excluded) |
| 7800 | << getOpenMPClauseName(OMPC_schedule); |
| 7801 | return true; |
| 7802 | } |
| 7803 | return false; |
| 7804 | } |
| 7805 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7806 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7807 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7808 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7809 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7810 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7811 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7812 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7813 | return nullptr; |
| 7814 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7815 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7816 | // but not both. |
| 7817 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7818 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7819 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7820 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7821 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7822 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7823 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7824 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7825 | return nullptr; |
| 7826 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7827 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7828 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7829 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7830 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7831 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7832 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7833 | Exclude); |
| 7834 | } else { |
| 7835 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7836 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7837 | } |
| 7838 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7839 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7840 | return nullptr; |
| 7841 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7842 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7843 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7844 | // schedule(guided). |
| 7845 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7846 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7847 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7848 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7849 | diag::err_omp_schedule_nonmonotonic_static); |
| 7850 | return nullptr; |
| 7851 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7852 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7853 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7854 | if (ChunkSize) { |
| 7855 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7856 | !ChunkSize->isInstantiationDependent() && |
| 7857 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7858 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7859 | ExprResult Val = |
| 7860 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7861 | if (Val.isInvalid()) |
| 7862 | return nullptr; |
| 7863 | |
| 7864 | ValExpr = Val.get(); |
| 7865 | |
| 7866 | // OpenMP [2.7.1, Restrictions] |
| 7867 | // chunk_size must be a loop invariant integer expression with a positive |
| 7868 | // value. |
| 7869 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7870 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7871 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7872 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7873 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7874 | return nullptr; |
| 7875 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7876 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7877 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7878 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7879 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7880 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7881 | } |
| 7882 | } |
| 7883 | } |
| 7884 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7885 | return new (Context) |
| 7886 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7887 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7888 | } |
| 7889 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7890 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7891 | SourceLocation StartLoc, |
| 7892 | SourceLocation EndLoc) { |
| 7893 | OMPClause *Res = nullptr; |
| 7894 | switch (Kind) { |
| 7895 | case OMPC_ordered: |
| 7896 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7897 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7898 | case OMPC_nowait: |
| 7899 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7900 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7901 | case OMPC_untied: |
| 7902 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7903 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7904 | case OMPC_mergeable: |
| 7905 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7906 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7907 | case OMPC_read: |
| 7908 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7909 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7910 | case OMPC_write: |
| 7911 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7912 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7913 | case OMPC_update: |
| 7914 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7915 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7916 | case OMPC_capture: |
| 7917 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7918 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7919 | case OMPC_seq_cst: |
| 7920 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7921 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7922 | case OMPC_threads: |
| 7923 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7924 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7925 | case OMPC_simd: |
| 7926 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7927 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7928 | case OMPC_nogroup: |
| 7929 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7930 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7931 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7932 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7933 | case OMPC_num_threads: |
| 7934 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7935 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7936 | case OMPC_collapse: |
| 7937 | case OMPC_schedule: |
| 7938 | case OMPC_private: |
| 7939 | case OMPC_firstprivate: |
| 7940 | case OMPC_lastprivate: |
| 7941 | case OMPC_shared: |
| 7942 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 7943 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 7944 | case OMPC_in_reduction: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7945 | case OMPC_linear: |
| 7946 | case OMPC_aligned: |
| 7947 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7948 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7949 | case OMPC_default: |
| 7950 | case OMPC_proc_bind: |
| 7951 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7952 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7953 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7954 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7955 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7956 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7957 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7958 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7959 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7960 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7961 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7962 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7963 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7964 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7965 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7966 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7967 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7968 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7969 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7970 | llvm_unreachable("Clause is not allowed."); |
| 7971 | } |
| 7972 | return Res; |
| 7973 | } |
| 7974 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7975 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7976 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7977 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7978 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7979 | } |
| 7980 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7981 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7982 | SourceLocation EndLoc) { |
| 7983 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7984 | } |
| 7985 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7986 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7987 | SourceLocation EndLoc) { |
| 7988 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7989 | } |
| 7990 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7991 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7992 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7993 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7994 | } |
| 7995 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7996 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7997 | SourceLocation EndLoc) { |
| 7998 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7999 | } |
| 8000 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8001 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 8002 | SourceLocation EndLoc) { |
| 8003 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 8004 | } |
| 8005 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8006 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 8007 | SourceLocation EndLoc) { |
| 8008 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 8009 | } |
| 8010 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8011 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 8012 | SourceLocation EndLoc) { |
| 8013 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 8014 | } |
| 8015 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8016 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 8017 | SourceLocation EndLoc) { |
| 8018 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 8019 | } |
| 8020 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8021 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 8022 | SourceLocation EndLoc) { |
| 8023 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 8024 | } |
| 8025 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8026 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 8027 | SourceLocation EndLoc) { |
| 8028 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 8029 | } |
| 8030 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8031 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 8032 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 8033 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 8034 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8035 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8036 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 8037 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8038 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8039 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8040 | switch (Kind) { |
| 8041 | case OMPC_private: |
| 8042 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8043 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8044 | case OMPC_firstprivate: |
| 8045 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8046 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8047 | case OMPC_lastprivate: |
| 8048 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8049 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8050 | case OMPC_shared: |
| 8051 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8052 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8053 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8054 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 8055 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8056 | break; |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8057 | case OMPC_task_reduction: |
| 8058 | Res = ActOnOpenMPTaskReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 8059 | EndLoc, ReductionIdScopeSpec, |
| 8060 | ReductionId); |
| 8061 | break; |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 8062 | case OMPC_in_reduction: |
| 8063 | Res = |
| 8064 | ActOnOpenMPInReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 8065 | EndLoc, ReductionIdScopeSpec, ReductionId); |
| 8066 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8067 | case OMPC_linear: |
| 8068 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8069 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8070 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8071 | case OMPC_aligned: |
| 8072 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 8073 | ColonLoc, EndLoc); |
| 8074 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8075 | case OMPC_copyin: |
| 8076 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8077 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8078 | case OMPC_copyprivate: |
| 8079 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8080 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8081 | case OMPC_flush: |
| 8082 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8083 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8084 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8085 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8086 | StartLoc, LParenLoc, EndLoc); |
| 8087 | break; |
| 8088 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8089 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8090 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 8091 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8092 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8093 | case OMPC_to: |
| 8094 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8095 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8096 | case OMPC_from: |
| 8097 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8098 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8099 | case OMPC_use_device_ptr: |
| 8100 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8101 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8102 | case OMPC_is_device_ptr: |
| 8103 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8104 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8105 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8106 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8107 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8108 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8109 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8110 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8111 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8112 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8113 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8114 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8115 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8116 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8117 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8118 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8119 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8120 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8121 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8122 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8123 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8124 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8125 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8126 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8127 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8128 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8129 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8130 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8131 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8132 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8133 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8134 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8135 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8136 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8137 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8138 | llvm_unreachable("Clause is not allowed."); |
| 8139 | } |
| 8140 | return Res; |
| 8141 | } |
| 8142 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8143 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8144 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8145 | ExprResult Res = BuildDeclRefExpr( |
| 8146 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 8147 | if (!Res.isUsable()) |
| 8148 | return ExprError(); |
| 8149 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 8150 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 8151 | if (!Res.isUsable()) |
| 8152 | return ExprError(); |
| 8153 | } |
| 8154 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 8155 | Res = DefaultLvalueConversion(Res.get()); |
| 8156 | if (!Res.isUsable()) |
| 8157 | return ExprError(); |
| 8158 | } |
| 8159 | return Res; |
| 8160 | } |
| 8161 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8162 | static std::pair<ValueDecl *, bool> |
| 8163 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 8164 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8165 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 8166 | RefExpr->containsUnexpandedParameterPack()) |
| 8167 | return std::make_pair(nullptr, true); |
| 8168 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8169 | // OpenMP [3.1, C/C++] |
| 8170 | // A list item is a variable name. |
| 8171 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 8172 | // A variable that is part of another variable (as an array or |
| 8173 | // structure element) cannot appear in a private clause. |
| 8174 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8175 | enum { |
| 8176 | NoArrayExpr = -1, |
| 8177 | ArraySubscript = 0, |
| 8178 | OMPArraySection = 1 |
| 8179 | } IsArrayExpr = NoArrayExpr; |
| 8180 | if (AllowArraySection) { |
| 8181 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 8182 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 8183 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8184 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8185 | RefExpr = Base; |
| 8186 | IsArrayExpr = ArraySubscript; |
| 8187 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 8188 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 8189 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 8190 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 8191 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8192 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8193 | RefExpr = Base; |
| 8194 | IsArrayExpr = OMPArraySection; |
| 8195 | } |
| 8196 | } |
| 8197 | ELoc = RefExpr->getExprLoc(); |
| 8198 | ERange = RefExpr->getSourceRange(); |
| 8199 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8200 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 8201 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 8202 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 8203 | (S.getCurrentThisType().isNull() || !ME || |
| 8204 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 8205 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8206 | if (IsArrayExpr != NoArrayExpr) |
| 8207 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 8208 | << ERange; |
| 8209 | else { |
| 8210 | S.Diag(ELoc, |
| 8211 | AllowArraySection |
| 8212 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 8213 | : diag::err_omp_expected_var_name_member_expr) |
| 8214 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 8215 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8216 | return std::make_pair(nullptr, false); |
| 8217 | } |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 8218 | return std::make_pair( |
| 8219 | getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8220 | } |
| 8221 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8222 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 8223 | SourceLocation StartLoc, |
| 8224 | SourceLocation LParenLoc, |
| 8225 | SourceLocation EndLoc) { |
| 8226 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8227 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8228 | for (auto &RefExpr : VarList) { |
| 8229 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8230 | SourceLocation ELoc; |
| 8231 | SourceRange ERange; |
| 8232 | Expr *SimpleRefExpr = RefExpr; |
| 8233 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8234 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8235 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8236 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8237 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8238 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8239 | ValueDecl *D = Res.first; |
| 8240 | if (!D) |
| 8241 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8242 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8243 | QualType Type = D->getType(); |
| 8244 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8245 | |
| 8246 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8247 | // A variable that appears in a private clause must not have an incomplete |
| 8248 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8249 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8250 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8251 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8252 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8253 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8254 | // in a Construct] |
| 8255 | // Variables with the predetermined data-sharing attributes may not be |
| 8256 | // listed in data-sharing attributes clauses, except for the cases |
| 8257 | // listed below. For these exceptions only, listing a predetermined |
| 8258 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8259 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8260 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8261 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8262 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8263 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8264 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8265 | continue; |
| 8266 | } |
| 8267 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8268 | auto CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8269 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8270 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8271 | isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8272 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8273 | << getOpenMPClauseName(OMPC_private) << Type |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8274 | << getOpenMPDirectiveName(CurrDir); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8275 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8276 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8277 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8278 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8279 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8280 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8281 | continue; |
| 8282 | } |
| 8283 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8284 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8285 | // A list item cannot appear in both a map clause and a data-sharing |
| 8286 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8287 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8288 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8289 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8290 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8291 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8292 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8293 | CurrDir == OMPD_target_parallel_for_simd || |
| 8294 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8295 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8296 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8297 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8298 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8299 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8300 | ConflictKind = WhereFoundClauseKind; |
| 8301 | return true; |
| 8302 | })) { |
| 8303 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8304 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8305 | << getOpenMPClauseName(ConflictKind) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8306 | << getOpenMPDirectiveName(CurrDir); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8307 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8308 | continue; |
| 8309 | } |
| 8310 | } |
| 8311 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8312 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8313 | // A variable of class type (or array thereof) that appears in a private |
| 8314 | // clause requires an accessible, unambiguous default constructor for the |
| 8315 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8316 | // Generate helper private variable and initialize it with the default |
| 8317 | // value. The address of the original variable is replaced by the address of |
| 8318 | // the new private variable in CodeGen. This new variable is not added to |
| 8319 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8320 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8321 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8322 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8323 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8324 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8325 | if (VDPrivate->isInvalidDecl()) |
| 8326 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8327 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8328 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8329 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8330 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8331 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8332 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8333 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8334 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8335 | ? RefExpr->IgnoreParens() |
| 8336 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8337 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8338 | } |
| 8339 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8340 | if (Vars.empty()) |
| 8341 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8342 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8343 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8344 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8345 | } |
| 8346 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8347 | namespace { |
| 8348 | class DiagsUninitializedSeveretyRAII { |
| 8349 | private: |
| 8350 | DiagnosticsEngine &Diags; |
| 8351 | SourceLocation SavedLoc; |
| 8352 | bool IsIgnored; |
| 8353 | |
| 8354 | public: |
| 8355 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8356 | bool IsIgnored) |
| 8357 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8358 | if (!IsIgnored) { |
| 8359 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8360 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8361 | } |
| 8362 | } |
| 8363 | ~DiagsUninitializedSeveretyRAII() { |
| 8364 | if (!IsIgnored) |
| 8365 | Diags.popMappings(SavedLoc); |
| 8366 | } |
| 8367 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8368 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8369 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8370 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8371 | SourceLocation StartLoc, |
| 8372 | SourceLocation LParenLoc, |
| 8373 | SourceLocation EndLoc) { |
| 8374 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8375 | SmallVector<Expr *, 8> PrivateCopies; |
| 8376 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8377 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8378 | bool IsImplicitClause = |
| 8379 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8380 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8381 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8382 | for (auto &RefExpr : VarList) { |
| 8383 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8384 | SourceLocation ELoc; |
| 8385 | SourceRange ERange; |
| 8386 | Expr *SimpleRefExpr = RefExpr; |
| 8387 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8388 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8389 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8390 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8391 | PrivateCopies.push_back(nullptr); |
| 8392 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8393 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8394 | ValueDecl *D = Res.first; |
| 8395 | if (!D) |
| 8396 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8397 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8398 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8399 | QualType Type = D->getType(); |
| 8400 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8401 | |
| 8402 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8403 | // A variable that appears in a private clause must not have an incomplete |
| 8404 | // type or a reference type. |
| 8405 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8406 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8407 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8408 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8409 | |
| 8410 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8411 | // 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] | 8412 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8413 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8414 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8415 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8416 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8417 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8418 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8419 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8420 | TopDVar = DVar; |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8421 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8422 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8423 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8424 | // A list item that specifies a given variable may not appear in more |
| 8425 | // than one clause on the same directive, except that a variable may be |
| 8426 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8427 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8428 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8429 | // both. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8430 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8431 | (CurrDir == OMPD_distribute || DVar.CKind != OMPC_lastprivate) && |
| 8432 | DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8433 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8434 | << getOpenMPClauseName(DVar.CKind) |
| 8435 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8436 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8437 | continue; |
| 8438 | } |
| 8439 | |
| 8440 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8441 | // in a Construct] |
| 8442 | // Variables with the predetermined data-sharing attributes may not be |
| 8443 | // listed in data-sharing attributes clauses, except for the cases |
| 8444 | // listed below. For these exceptions only, listing a predetermined |
| 8445 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8446 | // the variable's predetermined data-sharing attributes. |
| 8447 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8448 | // in a Construct, C/C++, p.2] |
| 8449 | // Variables with const-qualified type having no mutable member may be |
| 8450 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8451 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8452 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8453 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8454 | << getOpenMPClauseName(DVar.CKind) |
| 8455 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8456 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8457 | continue; |
| 8458 | } |
| 8459 | |
| 8460 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8461 | // A list item that is private within a parallel region must not appear |
| 8462 | // in a firstprivate clause on a worksharing construct if any of the |
| 8463 | // worksharing regions arising from the worksharing construct ever bind |
| 8464 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8465 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8466 | // A list item that is private within a teams region must not appear in a |
| 8467 | // firstprivate clause on a distribute construct if any of the distribute |
| 8468 | // regions arising from the distribute construct ever bind to any of the |
| 8469 | // teams regions arising from the teams construct. |
| 8470 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8471 | // A list item that appears in a reduction clause of a teams construct |
| 8472 | // must not appear in a firstprivate clause on a distribute construct if |
| 8473 | // any of the distribute regions arising from the distribute construct |
| 8474 | // ever bind to any of the teams regions arising from the teams construct. |
| 8475 | if ((isOpenMPWorksharingDirective(CurrDir) || |
| 8476 | isOpenMPDistributeDirective(CurrDir)) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8477 | !isOpenMPParallelDirective(CurrDir) && |
| 8478 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8479 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8480 | if (DVar.CKind != OMPC_shared && |
| 8481 | (isOpenMPParallelDirective(DVar.DKind) || |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8482 | isOpenMPTeamsDirective(DVar.DKind) || |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8483 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8484 | Diag(ELoc, diag::err_omp_required_access) |
| 8485 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8486 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8487 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8488 | continue; |
| 8489 | } |
| 8490 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8491 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8492 | // A list item that appears in a reduction clause of a parallel construct |
| 8493 | // must not appear in a firstprivate clause on a worksharing or task |
| 8494 | // construct if any of the worksharing or task regions arising from the |
| 8495 | // worksharing or task construct ever bind to any of the parallel regions |
| 8496 | // arising from the parallel construct. |
| 8497 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8498 | // A list item that appears in a reduction clause in worksharing |
| 8499 | // construct must not appear in a firstprivate clause in a task construct |
| 8500 | // encountered during execution of any of the worksharing regions arising |
| 8501 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8502 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8503 | DVar = DSAStack->hasInnermostDSA( |
| 8504 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8505 | [](OpenMPDirectiveKind K) -> bool { |
| 8506 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8507 | isOpenMPWorksharingDirective(K) || |
| 8508 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8509 | }, |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8510 | /*FromParent=*/true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8511 | if (DVar.CKind == OMPC_reduction && |
| 8512 | (isOpenMPParallelDirective(DVar.DKind) || |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8513 | isOpenMPWorksharingDirective(DVar.DKind) || |
| 8514 | isOpenMPTeamsDirective(DVar.DKind))) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8515 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8516 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8517 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8518 | continue; |
| 8519 | } |
| 8520 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8521 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8522 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8523 | // A list item cannot appear in both a map clause and a data-sharing |
| 8524 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8525 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8526 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8527 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8528 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8529 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8530 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8531 | CurrDir == OMPD_target_parallel_for_simd || |
| 8532 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8533 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8534 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8535 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8536 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8537 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8538 | ConflictKind = WhereFoundClauseKind; |
| 8539 | return true; |
| 8540 | })) { |
| 8541 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8542 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8543 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8544 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8545 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8546 | continue; |
| 8547 | } |
| 8548 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8549 | } |
| 8550 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8551 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8552 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8553 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8554 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8555 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8556 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8557 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8558 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8559 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8560 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8561 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8562 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8563 | continue; |
| 8564 | } |
| 8565 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8566 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8567 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8568 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8569 | // Generate helper private variable and initialize it with the value of the |
| 8570 | // original variable. The address of the original variable is replaced by |
| 8571 | // the address of the new private variable in the CodeGen. This new variable |
| 8572 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8573 | // original variable for proper diagnostics and variable capturing. |
| 8574 | Expr *VDInitRefExpr = nullptr; |
| 8575 | // For arrays generate initializer for single element and replace it by the |
| 8576 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8577 | if (Type->isArrayType()) { |
| 8578 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8579 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8580 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8581 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8582 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8583 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8584 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8585 | InitializedEntity Entity = |
| 8586 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8587 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8588 | |
| 8589 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8590 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8591 | if (Result.isInvalid()) |
| 8592 | VDPrivate->setInvalidDecl(); |
| 8593 | else |
| 8594 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8595 | // Remove temp variable declaration. |
| 8596 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8597 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8598 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8599 | ".firstprivate.temp"); |
| 8600 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8601 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8602 | AddInitializerToDecl(VDPrivate, |
| 8603 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8604 | /*DirectInit=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8605 | } |
| 8606 | if (VDPrivate->isInvalidDecl()) { |
| 8607 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8608 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8609 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8610 | } |
| 8611 | continue; |
| 8612 | } |
| 8613 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8614 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8615 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8616 | RefExpr->getExprLoc()); |
| 8617 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8618 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8619 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8620 | Ref = TopDVar.PrivateCopy; |
| 8621 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8622 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8623 | if (!IsOpenMPCapturedDecl(D)) |
| 8624 | ExprCaptures.push_back(Ref->getDecl()); |
| 8625 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8626 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8627 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8628 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8629 | ? RefExpr->IgnoreParens() |
| 8630 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8631 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8632 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8633 | } |
| 8634 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8635 | if (Vars.empty()) |
| 8636 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8637 | |
| 8638 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8639 | Vars, PrivateCopies, Inits, |
| 8640 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8641 | } |
| 8642 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8643 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8644 | SourceLocation StartLoc, |
| 8645 | SourceLocation LParenLoc, |
| 8646 | SourceLocation EndLoc) { |
| 8647 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8648 | SmallVector<Expr *, 8> SrcExprs; |
| 8649 | SmallVector<Expr *, 8> DstExprs; |
| 8650 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8651 | SmallVector<Decl *, 4> ExprCaptures; |
| 8652 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8653 | for (auto &RefExpr : VarList) { |
| 8654 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8655 | SourceLocation ELoc; |
| 8656 | SourceRange ERange; |
| 8657 | Expr *SimpleRefExpr = RefExpr; |
| 8658 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8659 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8660 | // It will be analyzed later. |
| 8661 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8662 | SrcExprs.push_back(nullptr); |
| 8663 | DstExprs.push_back(nullptr); |
| 8664 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8665 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8666 | ValueDecl *D = Res.first; |
| 8667 | if (!D) |
| 8668 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8669 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8670 | QualType Type = D->getType(); |
| 8671 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8672 | |
| 8673 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8674 | // A variable that appears in a lastprivate clause must not have an |
| 8675 | // incomplete type or a reference type. |
| 8676 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8677 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8678 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8679 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8680 | |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8681 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8682 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8683 | // in a Construct] |
| 8684 | // Variables with the predetermined data-sharing attributes may not be |
| 8685 | // listed in data-sharing attributes clauses, except for the cases |
| 8686 | // listed below. |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8687 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8688 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8689 | // both. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8690 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8691 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8692 | (CurrDir == OMPD_distribute || DVar.CKind != OMPC_firstprivate) && |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8693 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8694 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8695 | << getOpenMPClauseName(DVar.CKind) |
| 8696 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8697 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8698 | continue; |
| 8699 | } |
| 8700 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8701 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8702 | // A list item that is private within a parallel region, or that appears in |
| 8703 | // the reduction clause of a parallel construct, must not appear in a |
| 8704 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8705 | // worksharing regions ever binds to any of the corresponding parallel |
| 8706 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8707 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8708 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8709 | !isOpenMPParallelDirective(CurrDir) && |
| 8710 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8711 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8712 | if (DVar.CKind != OMPC_shared) { |
| 8713 | Diag(ELoc, diag::err_omp_required_access) |
| 8714 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8715 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8716 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8717 | continue; |
| 8718 | } |
| 8719 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8720 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8721 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8722 | // A variable of class type (or array thereof) that appears in a |
| 8723 | // lastprivate clause requires an accessible, unambiguous default |
| 8724 | // constructor for the class type, unless the list item is also specified |
| 8725 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8726 | // A variable of class type (or array thereof) that appears in a |
| 8727 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8728 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8729 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8730 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8731 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8732 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8733 | auto *PseudoSrcExpr = |
| 8734 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8735 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8736 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8737 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8738 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8739 | // For arrays generate assignment operation for single element and replace |
| 8740 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8741 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8742 | PseudoDstExpr, PseudoSrcExpr); |
| 8743 | if (AssignmentOp.isInvalid()) |
| 8744 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8745 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8746 | /*DiscardedValue=*/true); |
| 8747 | if (AssignmentOp.isInvalid()) |
| 8748 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8749 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8750 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8751 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8752 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8753 | Ref = TopDVar.PrivateCopy; |
| 8754 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8755 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8756 | if (!IsOpenMPCapturedDecl(D)) |
| 8757 | ExprCaptures.push_back(Ref->getDecl()); |
| 8758 | } |
| 8759 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8760 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8761 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8762 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8763 | if (!RefRes.isUsable()) |
| 8764 | continue; |
| 8765 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8766 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8767 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8768 | if (!PostUpdateRes.isUsable()) |
| 8769 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8770 | ExprPostUpdates.push_back( |
| 8771 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8772 | } |
| 8773 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8774 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8775 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8776 | ? RefExpr->IgnoreParens() |
| 8777 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8778 | SrcExprs.push_back(PseudoSrcExpr); |
| 8779 | DstExprs.push_back(PseudoDstExpr); |
| 8780 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8781 | } |
| 8782 | |
| 8783 | if (Vars.empty()) |
| 8784 | return nullptr; |
| 8785 | |
| 8786 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8787 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8788 | buildPreInits(Context, ExprCaptures), |
| 8789 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8792 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8793 | SourceLocation StartLoc, |
| 8794 | SourceLocation LParenLoc, |
| 8795 | SourceLocation EndLoc) { |
| 8796 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8797 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8798 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8799 | SourceLocation ELoc; |
| 8800 | SourceRange ERange; |
| 8801 | Expr *SimpleRefExpr = RefExpr; |
| 8802 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8803 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8804 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8805 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8806 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8807 | ValueDecl *D = Res.first; |
| 8808 | if (!D) |
| 8809 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8810 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8811 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8812 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8813 | // in a Construct] |
| 8814 | // Variables with the predetermined data-sharing attributes may not be |
| 8815 | // listed in data-sharing attributes clauses, except for the cases |
| 8816 | // listed below. For these exceptions only, listing a predetermined |
| 8817 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8818 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8819 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8820 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8821 | DVar.RefExpr) { |
| 8822 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8823 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8824 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8825 | continue; |
| 8826 | } |
| 8827 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8828 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8829 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8830 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8831 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8832 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8833 | ? RefExpr->IgnoreParens() |
| 8834 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8835 | } |
| 8836 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8837 | if (Vars.empty()) |
| 8838 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8839 | |
| 8840 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8841 | } |
| 8842 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8843 | namespace { |
| 8844 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8845 | DSAStackTy *Stack; |
| 8846 | |
| 8847 | public: |
| 8848 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8849 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8850 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8851 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8852 | return false; |
| 8853 | if (DVar.CKind != OMPC_unknown) |
| 8854 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8855 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8856 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 8857 | /*FromParent=*/true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8858 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8859 | return true; |
| 8860 | return false; |
| 8861 | } |
| 8862 | return false; |
| 8863 | } |
| 8864 | bool VisitStmt(Stmt *S) { |
| 8865 | for (auto Child : S->children()) { |
| 8866 | if (Child && Visit(Child)) |
| 8867 | return true; |
| 8868 | } |
| 8869 | return false; |
| 8870 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8871 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8872 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8873 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8874 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8875 | namespace { |
| 8876 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8877 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8878 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8879 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8880 | ValueDecl *Field; |
| 8881 | DeclRefExpr *CapturedExpr; |
| 8882 | |
| 8883 | public: |
| 8884 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8885 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8886 | |
| 8887 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8888 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8889 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8890 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8891 | return CapturedExpr; |
| 8892 | } |
| 8893 | return BaseTransform::TransformMemberExpr(E); |
| 8894 | } |
| 8895 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8896 | }; |
| 8897 | } // namespace |
| 8898 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8899 | template <typename T> |
| 8900 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8901 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8902 | for (auto &Set : Lookups) { |
| 8903 | for (auto *D : Set) { |
| 8904 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8905 | return Res; |
| 8906 | } |
| 8907 | } |
| 8908 | return T(); |
| 8909 | } |
| 8910 | |
| 8911 | static ExprResult |
| 8912 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8913 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8914 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8915 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8916 | if (ReductionIdScopeSpec.isInvalid()) |
| 8917 | return ExprError(); |
| 8918 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8919 | if (S) { |
| 8920 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8921 | Lookup.suppressDiagnostics(); |
| 8922 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8923 | auto *D = Lookup.getRepresentativeDecl(); |
| 8924 | do { |
| 8925 | S = S->getParent(); |
| 8926 | } while (S && !S->isDeclScope(D)); |
| 8927 | if (S) |
| 8928 | S = S->getParent(); |
| 8929 | Lookups.push_back(UnresolvedSet<8>()); |
| 8930 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8931 | Lookup.clear(); |
| 8932 | } |
| 8933 | } else if (auto *ULE = |
| 8934 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8935 | Lookups.push_back(UnresolvedSet<8>()); |
| 8936 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8937 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8938 | if (D == PrevD) |
| 8939 | Lookups.push_back(UnresolvedSet<8>()); |
| 8940 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8941 | Lookups.back().addDecl(DRD); |
| 8942 | PrevD = D; |
| 8943 | } |
| 8944 | } |
| 8945 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8946 | Ty->containsUnexpandedParameterPack() || |
| 8947 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8948 | return !D->isInvalidDecl() && |
| 8949 | (D->getType()->isDependentType() || |
| 8950 | D->getType()->isInstantiationDependentType() || |
| 8951 | D->getType()->containsUnexpandedParameterPack()); |
| 8952 | })) { |
| 8953 | UnresolvedSet<8> ResSet; |
| 8954 | for (auto &Set : Lookups) { |
| 8955 | ResSet.append(Set.begin(), Set.end()); |
| 8956 | // The last item marks the end of all declarations at the specified scope. |
| 8957 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8958 | } |
| 8959 | return UnresolvedLookupExpr::Create( |
| 8960 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8961 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8962 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8963 | } |
| 8964 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8965 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8966 | if (!D->isInvalidDecl() && |
| 8967 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8968 | return D; |
| 8969 | return nullptr; |
| 8970 | })) |
| 8971 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8972 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8973 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8974 | if (!D->isInvalidDecl() && |
| 8975 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8976 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8977 | return D; |
| 8978 | return nullptr; |
| 8979 | })) { |
| 8980 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8981 | /*DetectVirtual=*/false); |
| 8982 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8983 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8984 | VD->getType().getUnqualifiedType()))) { |
| 8985 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8986 | /*DiagID=*/0) != |
| 8987 | Sema::AR_inaccessible) { |
| 8988 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8989 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8990 | } |
| 8991 | } |
| 8992 | } |
| 8993 | } |
| 8994 | if (ReductionIdScopeSpec.isSet()) { |
| 8995 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8996 | return ExprError(); |
| 8997 | } |
| 8998 | return ExprEmpty(); |
| 8999 | } |
| 9000 | |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9001 | namespace { |
| 9002 | /// Data for the reduction-based clauses. |
| 9003 | struct ReductionData { |
| 9004 | /// List of original reduction items. |
| 9005 | SmallVector<Expr *, 8> Vars; |
| 9006 | /// List of private copies of the reduction items. |
| 9007 | SmallVector<Expr *, 8> Privates; |
| 9008 | /// LHS expressions for the reduction_op expressions. |
| 9009 | SmallVector<Expr *, 8> LHSs; |
| 9010 | /// RHS expressions for the reduction_op expressions. |
| 9011 | SmallVector<Expr *, 8> RHSs; |
| 9012 | /// Reduction operation expression. |
| 9013 | SmallVector<Expr *, 8> ReductionOps; |
| 9014 | /// List of captures for clause. |
| 9015 | SmallVector<Decl *, 4> ExprCaptures; |
| 9016 | /// List of postupdate expressions. |
| 9017 | SmallVector<Expr *, 4> ExprPostUpdates; |
| 9018 | ReductionData() = delete; |
| 9019 | /// Reserves required memory for the reduction data. |
| 9020 | ReductionData(unsigned Size) { |
| 9021 | Vars.reserve(Size); |
| 9022 | Privates.reserve(Size); |
| 9023 | LHSs.reserve(Size); |
| 9024 | RHSs.reserve(Size); |
| 9025 | ReductionOps.reserve(Size); |
| 9026 | ExprCaptures.reserve(Size); |
| 9027 | ExprPostUpdates.reserve(Size); |
| 9028 | } |
| 9029 | /// Stores reduction item and reduction operation only (required for dependent |
| 9030 | /// reduction item). |
| 9031 | void push(Expr *Item, Expr *ReductionOp) { |
| 9032 | Vars.emplace_back(Item); |
| 9033 | Privates.emplace_back(nullptr); |
| 9034 | LHSs.emplace_back(nullptr); |
| 9035 | RHSs.emplace_back(nullptr); |
| 9036 | ReductionOps.emplace_back(ReductionOp); |
| 9037 | } |
| 9038 | /// Stores reduction data. |
| 9039 | void push(Expr *Item, Expr *Private, Expr *LHS, Expr *RHS, |
| 9040 | Expr *ReductionOp) { |
| 9041 | Vars.emplace_back(Item); |
| 9042 | Privates.emplace_back(Private); |
| 9043 | LHSs.emplace_back(LHS); |
| 9044 | RHSs.emplace_back(RHS); |
| 9045 | ReductionOps.emplace_back(ReductionOp); |
| 9046 | } |
| 9047 | }; |
| 9048 | } // namespace |
| 9049 | |
| 9050 | static bool ActOnOMPReductionKindClause( |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9051 | Sema &S, DSAStackTy *Stack, OpenMPClauseKind ClauseKind, |
| 9052 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9053 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 9054 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9055 | ArrayRef<Expr *> UnresolvedReductions, ReductionData &RD) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9056 | auto DN = ReductionId.getName(); |
| 9057 | auto OOK = DN.getCXXOverloadedOperator(); |
| 9058 | BinaryOperatorKind BOK = BO_Comma; |
| 9059 | |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9060 | ASTContext &Context = S.Context; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9061 | // OpenMP [2.14.3.6, reduction clause] |
| 9062 | // C |
| 9063 | // reduction-identifier is either an identifier or one of the following |
| 9064 | // operators: +, -, *, &, |, ^, && and || |
| 9065 | // C++ |
| 9066 | // reduction-identifier is either an id-expression or one of the following |
| 9067 | // operators: +, -, *, &, |, ^, && and || |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9068 | switch (OOK) { |
| 9069 | case OO_Plus: |
| 9070 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9071 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9072 | break; |
| 9073 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9074 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9075 | break; |
| 9076 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9077 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9078 | break; |
| 9079 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9080 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9081 | break; |
| 9082 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9083 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9084 | break; |
| 9085 | case OO_AmpAmp: |
| 9086 | BOK = BO_LAnd; |
| 9087 | break; |
| 9088 | case OO_PipePipe: |
| 9089 | BOK = BO_LOr; |
| 9090 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9091 | case OO_New: |
| 9092 | case OO_Delete: |
| 9093 | case OO_Array_New: |
| 9094 | case OO_Array_Delete: |
| 9095 | case OO_Slash: |
| 9096 | case OO_Percent: |
| 9097 | case OO_Tilde: |
| 9098 | case OO_Exclaim: |
| 9099 | case OO_Equal: |
| 9100 | case OO_Less: |
| 9101 | case OO_Greater: |
| 9102 | case OO_LessEqual: |
| 9103 | case OO_GreaterEqual: |
| 9104 | case OO_PlusEqual: |
| 9105 | case OO_MinusEqual: |
| 9106 | case OO_StarEqual: |
| 9107 | case OO_SlashEqual: |
| 9108 | case OO_PercentEqual: |
| 9109 | case OO_CaretEqual: |
| 9110 | case OO_AmpEqual: |
| 9111 | case OO_PipeEqual: |
| 9112 | case OO_LessLess: |
| 9113 | case OO_GreaterGreater: |
| 9114 | case OO_LessLessEqual: |
| 9115 | case OO_GreaterGreaterEqual: |
| 9116 | case OO_EqualEqual: |
| 9117 | case OO_ExclaimEqual: |
| 9118 | case OO_PlusPlus: |
| 9119 | case OO_MinusMinus: |
| 9120 | case OO_Comma: |
| 9121 | case OO_ArrowStar: |
| 9122 | case OO_Arrow: |
| 9123 | case OO_Call: |
| 9124 | case OO_Subscript: |
| 9125 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 9126 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9127 | case NUM_OVERLOADED_OPERATORS: |
| 9128 | llvm_unreachable("Unexpected reduction identifier"); |
| 9129 | case OO_None: |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9130 | if (auto *II = DN.getAsIdentifierInfo()) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9131 | if (II->isStr("max")) |
| 9132 | BOK = BO_GT; |
| 9133 | else if (II->isStr("min")) |
| 9134 | BOK = BO_LT; |
| 9135 | } |
| 9136 | break; |
| 9137 | } |
| 9138 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9139 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9140 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9141 | else |
| 9142 | ReductionIdRange.setBegin(ReductionId.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9143 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9144 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9145 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 9146 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9147 | for (auto RefExpr : VarList) { |
| 9148 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9149 | // OpenMP [2.1, C/C++] |
| 9150 | // A list item is a variable or array section, subject to the restrictions |
| 9151 | // specified in Section 2.4 on page 42 and in each of the sections |
| 9152 | // describing clauses and directives for which a list appears. |
| 9153 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 9154 | // A variable that is part of another variable (as an array or |
| 9155 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9156 | if (!FirstIter && IR != ER) |
| 9157 | ++IR; |
| 9158 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9159 | SourceLocation ELoc; |
| 9160 | SourceRange ERange; |
| 9161 | Expr *SimpleRefExpr = RefExpr; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9162 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9163 | /*AllowArraySection=*/true); |
| 9164 | if (Res.second) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9165 | // Try to find 'declare reduction' corresponding construct before using |
| 9166 | // builtin/overloaded operators. |
| 9167 | QualType Type = Context.DependentTy; |
| 9168 | CXXCastPath BasePath; |
| 9169 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9170 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9171 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9172 | Expr *ReductionOp = nullptr; |
| 9173 | if (S.CurContext->isDependentContext() && |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9174 | (DeclareReductionRef.isUnset() || |
| 9175 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9176 | ReductionOp = DeclareReductionRef.get(); |
| 9177 | // It will be analyzed later. |
| 9178 | RD.push(RefExpr, ReductionOp); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9179 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9180 | ValueDecl *D = Res.first; |
| 9181 | if (!D) |
| 9182 | continue; |
| 9183 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9184 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9185 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 9186 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 9187 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9188 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9189 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9190 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 9191 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 9192 | Type = ATy->getElementType(); |
| 9193 | else |
| 9194 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9195 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9196 | } else |
| 9197 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 9198 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9199 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9200 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9201 | // A variable that appears in a private clause must not have an incomplete |
| 9202 | // type or a reference type. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9203 | if (S.RequireCompleteType(ELoc, Type, |
| 9204 | diag::err_omp_reduction_incomplete_type)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9205 | continue; |
| 9206 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9207 | // A list item that appears in a reduction clause must not be |
| 9208 | // const-qualified. |
| 9209 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9210 | S.Diag(ELoc, diag::err_omp_const_reduction_list_item) << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9211 | if (!ASE && !OASE) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9212 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 9213 | VarDecl::DeclarationOnly; |
| 9214 | S.Diag(D->getLocation(), |
| 9215 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9216 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9217 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9218 | continue; |
| 9219 | } |
| 9220 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 9221 | // If a list-item is a reference type then it must bind to the same object |
| 9222 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9223 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9224 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 9225 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9226 | DSARefChecker Check(Stack); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9227 | if (Check.Visit(VDDef->getInit())) { |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9228 | S.Diag(ELoc, diag::err_omp_reduction_ref_type_arg) |
| 9229 | << getOpenMPClauseName(ClauseKind) << ERange; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9230 | S.Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9231 | continue; |
| 9232 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9233 | } |
| 9234 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9235 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9236 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9237 | // in a Construct] |
| 9238 | // Variables with the predetermined data-sharing attributes may not be |
| 9239 | // listed in data-sharing attributes clauses, except for the cases |
| 9240 | // listed below. For these exceptions only, listing a predetermined |
| 9241 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9242 | // the variable's predetermined data-sharing attributes. |
| 9243 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 9244 | // Any number of reduction clauses can be specified on the directive, |
| 9245 | // but a list item can appear only once in the reduction clauses for that |
| 9246 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9247 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9248 | DVar = Stack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9249 | if (DVar.CKind == OMPC_reduction) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9250 | S.Diag(ELoc, diag::err_omp_once_referenced) |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9251 | << getOpenMPClauseName(ClauseKind); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9252 | if (DVar.RefExpr) |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9253 | S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9254 | continue; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9255 | } else if (DVar.CKind != OMPC_unknown) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9256 | S.Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9257 | << getOpenMPClauseName(DVar.CKind) |
| 9258 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9259 | ReportOriginalDSA(S, Stack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9260 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9261 | } |
| 9262 | |
| 9263 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 9264 | // A list item that appears in a reduction clause of a worksharing |
| 9265 | // construct must be shared in the parallel regions to which any of the |
| 9266 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9267 | OpenMPDirectiveKind CurrDir = Stack->getCurrentDirective(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9268 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 9269 | !isOpenMPParallelDirective(CurrDir) && |
| 9270 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9271 | DVar = Stack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9272 | if (DVar.CKind != OMPC_shared) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9273 | S.Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9274 | << getOpenMPClauseName(OMPC_reduction) |
| 9275 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9276 | ReportOriginalDSA(S, Stack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9277 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9278 | } |
| 9279 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9280 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9281 | // Try to find 'declare reduction' corresponding construct before using |
| 9282 | // builtin/overloaded operators. |
| 9283 | CXXCastPath BasePath; |
| 9284 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9285 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9286 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9287 | if (DeclareReductionRef.isInvalid()) |
| 9288 | continue; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9289 | if (S.CurContext->isDependentContext() && |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9290 | (DeclareReductionRef.isUnset() || |
| 9291 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9292 | RD.push(RefExpr, DeclareReductionRef.get()); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9293 | continue; |
| 9294 | } |
| 9295 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9296 | // Not allowed reduction identifier is found. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9297 | S.Diag(ReductionId.getLocStart(), |
| 9298 | diag::err_omp_unknown_reduction_identifier) |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9299 | << Type << ReductionIdRange; |
| 9300 | continue; |
| 9301 | } |
| 9302 | |
| 9303 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9304 | // The type of a list item that appears in a reduction clause must be valid |
| 9305 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9306 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9307 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9308 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9309 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9310 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9311 | if (DeclareReductionRef.isUnset()) { |
| 9312 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9313 | !(Type->isScalarType() || |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9314 | (S.getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9315 | S.Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9316 | << getOpenMPClauseName(ClauseKind) << S.getLangOpts().CPlusPlus; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9317 | if (!ASE && !OASE) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9318 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 9319 | VarDecl::DeclarationOnly; |
| 9320 | S.Diag(D->getLocation(), |
| 9321 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9322 | << D; |
| 9323 | } |
| 9324 | continue; |
| 9325 | } |
| 9326 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9327 | !S.getLangOpts().CPlusPlus && Type->isFloatingType()) { |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9328 | S.Diag(ELoc, diag::err_omp_clause_floating_type_arg) |
| 9329 | << getOpenMPClauseName(ClauseKind); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9330 | if (!ASE && !OASE) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9331 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 9332 | VarDecl::DeclarationOnly; |
| 9333 | S.Diag(D->getLocation(), |
| 9334 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9335 | << D; |
| 9336 | } |
| 9337 | continue; |
| 9338 | } |
| 9339 | } |
| 9340 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9341 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9342 | auto *LHSVD = buildVarDecl(S, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9343 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9344 | auto *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(), |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9345 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9346 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9347 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9348 | (!ASE && |
| 9349 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9350 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9351 | // Create pseudo array type for private copy. The size for this array will |
| 9352 | // be generated during codegen. |
| 9353 | // For array subscripts or single variables Private Ty is the same as Type |
| 9354 | // (type of the variable or single array element). |
| 9355 | PrivateTy = Context.getVariableArrayType( |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9356 | Type, |
| 9357 | new (Context) OpaqueValueExpr(SourceLocation(), Context.getSizeType(), |
| 9358 | VK_RValue), |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9359 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9360 | } else if (!ASE && !OASE && |
| 9361 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9362 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9363 | // Private copy. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9364 | auto *PrivateVD = buildVarDecl(S, ELoc, PrivateTy, D->getName(), |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9365 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9366 | // Add initializer for private variable. |
| 9367 | Expr *Init = nullptr; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9368 | auto *LHSDRE = buildDeclRefExpr(S, LHSVD, Type, ELoc); |
| 9369 | auto *RHSDRE = buildDeclRefExpr(S, RHSVD, Type, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9370 | if (DeclareReductionRef.isUsable()) { |
| 9371 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9372 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9373 | if (DRD->getInitializer()) { |
| 9374 | Init = DRDRef; |
| 9375 | RHSVD->setInit(DRDRef); |
| 9376 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9377 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9378 | } else { |
| 9379 | switch (BOK) { |
| 9380 | case BO_Add: |
| 9381 | case BO_Xor: |
| 9382 | case BO_Or: |
| 9383 | case BO_LOr: |
| 9384 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9385 | if (Type->isScalarType() || Type->isAnyComplexType()) |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9386 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9387 | break; |
| 9388 | case BO_Mul: |
| 9389 | case BO_LAnd: |
| 9390 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9391 | // '*' and '&&' reduction ops - initializer is '1'. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9392 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9393 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9394 | break; |
| 9395 | case BO_And: { |
| 9396 | // '&' reduction op - initializer is '~0'. |
| 9397 | QualType OrigType = Type; |
| 9398 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9399 | Type = ComplexTy->getElementType(); |
| 9400 | if (Type->isRealFloatingType()) { |
| 9401 | llvm::APFloat InitValue = |
| 9402 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9403 | /*isIEEE=*/true); |
| 9404 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9405 | Type, ELoc); |
| 9406 | } else if (Type->isScalarType()) { |
| 9407 | auto Size = Context.getTypeSize(Type); |
| 9408 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9409 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9410 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9411 | } |
| 9412 | if (Init && OrigType->isAnyComplexType()) { |
| 9413 | // Init = 0xFFFF + 0xFFFFi; |
| 9414 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9415 | Init = S.CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9416 | } |
| 9417 | Type = OrigType; |
| 9418 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9419 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9420 | case BO_LT: |
| 9421 | case BO_GT: { |
| 9422 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9423 | // the reduction list item type'. |
| 9424 | // 'max' reduction op - initializer is 'Least representable number in |
| 9425 | // the reduction list item type'. |
| 9426 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9427 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9428 | auto Size = Context.getTypeSize(Type); |
| 9429 | QualType IntTy = |
| 9430 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9431 | llvm::APInt InitValue = |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9432 | (BOK != BO_LT) ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9433 | : llvm::APInt::getMinValue(Size) |
| 9434 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9435 | : llvm::APInt::getMaxValue(Size); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9436 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9437 | if (Type->isPointerType()) { |
| 9438 | // Cast to pointer type. |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9439 | auto CastExpr = S.BuildCStyleCastExpr( |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9440 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9441 | SourceLocation(), Init); |
| 9442 | if (CastExpr.isInvalid()) |
| 9443 | continue; |
| 9444 | Init = CastExpr.get(); |
| 9445 | } |
| 9446 | } else if (Type->isRealFloatingType()) { |
| 9447 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9448 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9449 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9450 | Type, ELoc); |
| 9451 | } |
| 9452 | break; |
| 9453 | } |
| 9454 | case BO_PtrMemD: |
| 9455 | case BO_PtrMemI: |
| 9456 | case BO_MulAssign: |
| 9457 | case BO_Div: |
| 9458 | case BO_Rem: |
| 9459 | case BO_Sub: |
| 9460 | case BO_Shl: |
| 9461 | case BO_Shr: |
| 9462 | case BO_LE: |
| 9463 | case BO_GE: |
| 9464 | case BO_EQ: |
| 9465 | case BO_NE: |
| 9466 | case BO_AndAssign: |
| 9467 | case BO_XorAssign: |
| 9468 | case BO_OrAssign: |
| 9469 | case BO_Assign: |
| 9470 | case BO_AddAssign: |
| 9471 | case BO_SubAssign: |
| 9472 | case BO_DivAssign: |
| 9473 | case BO_RemAssign: |
| 9474 | case BO_ShlAssign: |
| 9475 | case BO_ShrAssign: |
| 9476 | case BO_Comma: |
| 9477 | llvm_unreachable("Unexpected reduction operation"); |
| 9478 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9479 | } |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9480 | if (Init && DeclareReductionRef.isUnset()) |
| 9481 | S.AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
| 9482 | else if (!Init) |
| 9483 | S.ActOnUninitializedDecl(RHSVD); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9484 | if (RHSVD->isInvalidDecl()) |
| 9485 | continue; |
| 9486 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9487 | S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible) |
| 9488 | << Type << ReductionIdRange; |
| 9489 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 9490 | VarDecl::DeclarationOnly; |
| 9491 | S.Diag(D->getLocation(), |
| 9492 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9493 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9494 | continue; |
| 9495 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9496 | // Store initializer for single element in private copy. Will be used during |
| 9497 | // codegen. |
| 9498 | PrivateVD->setInit(RHSVD->getInit()); |
| 9499 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9500 | auto *PrivateDRE = buildDeclRefExpr(S, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9501 | ExprResult ReductionOp; |
| 9502 | if (DeclareReductionRef.isUsable()) { |
| 9503 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9504 | QualType PtrRedTy = Context.getPointerType(RedTy); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9505 | ExprResult LHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9506 | ExprResult RHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9507 | if (!BasePath.empty()) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9508 | LHS = S.DefaultLvalueConversion(LHS.get()); |
| 9509 | RHS = S.DefaultLvalueConversion(RHS.get()); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9510 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9511 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9512 | &BasePath, LHS.get()->getValueKind()); |
| 9513 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9514 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9515 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9516 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9517 | FunctionProtoType::ExtProtoInfo EPI; |
| 9518 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9519 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9520 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9521 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9522 | S.DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9523 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9524 | ReductionOp = new (Context) |
| 9525 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9526 | } else { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9527 | ReductionOp = S.BuildBinOp( |
| 9528 | Stack->getCurScope(), ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9529 | if (ReductionOp.isUsable()) { |
| 9530 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9531 | ReductionOp = |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9532 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(), |
| 9533 | BO_Assign, LHSDRE, ReductionOp.get()); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9534 | } else { |
| 9535 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9536 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9537 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9538 | ReductionOp = |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9539 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(), |
| 9540 | BO_Assign, LHSDRE, ConditionalOp); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9541 | } |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9542 | if (ReductionOp.isUsable()) |
| 9543 | ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9544 | } |
Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9545 | if (!ReductionOp.isUsable()) |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9546 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9547 | } |
| 9548 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 9549 | // OpenMP [2.15.4.6, Restrictions, p.2] |
| 9550 | // A list item that appears in an in_reduction clause of a task construct |
| 9551 | // must appear in a task_reduction clause of a construct associated with a |
| 9552 | // taskgroup region that includes the participating task in its taskgroup |
| 9553 | // set. The construct associated with the innermost region that meets this |
| 9554 | // condition must specify the same reduction-identifier as the in_reduction |
| 9555 | // clause. |
| 9556 | if (ClauseKind == OMPC_in_reduction) { |
| 9557 | DVar = Stack->hasDSA( |
| 9558 | D, [](OpenMPClauseKind K) { return K != OMPC_unknown; }, |
| 9559 | [](OpenMPDirectiveKind K) { return K == OMPD_taskgroup; }, |
| 9560 | /*FromParent=*/true); |
| 9561 | if (DVar.CKind != OMPC_reduction || DVar.DKind != OMPD_taskgroup) { |
| 9562 | S.Diag(ELoc, diag::err_omp_in_reduction_not_task_reduction); |
| 9563 | continue; |
| 9564 | } |
| 9565 | SourceRange ParentSR; |
| 9566 | BinaryOperatorKind ParentBOK; |
| 9567 | const Expr *ParentReductionOp; |
| 9568 | bool IsParentBOK = Stack->getTopMostReductionData(D, ParentSR, ParentBOK); |
| 9569 | bool IsParentReductionOp = |
| 9570 | Stack->getTopMostReductionData(D, ParentSR, ParentReductionOp); |
| 9571 | if ((DeclareReductionRef.isUnset() && IsParentReductionOp) || |
| 9572 | (DeclareReductionRef.isUsable() && IsParentBOK) || BOK != ParentBOK || |
| 9573 | IsParentReductionOp) { |
| 9574 | bool EmitError = true; |
| 9575 | if (IsParentReductionOp && DeclareReductionRef.isUsable()) { |
| 9576 | llvm::FoldingSetNodeID RedId, ParentRedId; |
| 9577 | ParentReductionOp->Profile(ParentRedId, Context, /*Canonical=*/true); |
| 9578 | DeclareReductionRef.get()->Profile(RedId, Context, |
| 9579 | /*Canonical=*/true); |
| 9580 | EmitError = RedId != ParentRedId; |
| 9581 | } |
| 9582 | if (EmitError) { |
| 9583 | S.Diag(ReductionId.getLocStart(), |
| 9584 | diag::err_omp_reduction_identifier_mismatch) |
| 9585 | << ReductionIdRange << RefExpr->getSourceRange(); |
| 9586 | S.Diag(ParentSR.getBegin(), |
| 9587 | diag::note_omp_previous_reduction_identifier) |
| 9588 | << ParentSR << DVar.RefExpr->getSourceRange(); |
| 9589 | continue; |
| 9590 | } |
| 9591 | } |
| 9592 | } |
| 9593 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9594 | DeclRefExpr *Ref = nullptr; |
| 9595 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9596 | if (!VD && !S.CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9597 | if (ASE || OASE) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9598 | TransformExprToCaptures RebuildToCapture(S, D); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9599 | VarsExpr = |
| 9600 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9601 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9602 | } else { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9603 | VarsExpr = Ref = buildCapture(S, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9604 | } |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9605 | if (!S.IsOpenMPCapturedDecl(D)) { |
| 9606 | RD.ExprCaptures.emplace_back(Ref->getDecl()); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9607 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9608 | ExprResult RefRes = S.DefaultLvalueConversion(Ref); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9609 | if (!RefRes.isUsable()) |
| 9610 | continue; |
| 9611 | ExprResult PostUpdateRes = |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9612 | S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 9613 | RefRes.get()); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9614 | if (!PostUpdateRes.isUsable()) |
| 9615 | continue; |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9616 | if (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
| 9617 | Stack->getCurrentDirective() == OMPD_taskgroup) { |
| 9618 | S.Diag(RefExpr->getExprLoc(), |
| 9619 | diag::err_omp_reduction_non_addressable_expression) |
Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 9620 | << RefExpr->getSourceRange(); |
| 9621 | continue; |
| 9622 | } |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9623 | RD.ExprPostUpdates.emplace_back( |
| 9624 | S.IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9625 | } |
| 9626 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9627 | } |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9628 | // All reduction items are still marked as reduction (to do not increase |
| 9629 | // code base size). |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9630 | Stack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 9631 | if (DeclareReductionRef.isUsable()) |
| 9632 | Stack->addReductionData(D, ReductionIdRange, DeclareReductionRef.get()); |
| 9633 | else |
| 9634 | Stack->addReductionData(D, ReductionIdRange, BOK); |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9635 | RD.push(VarsExpr, PrivateDRE, LHSDRE, RHSDRE, ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9636 | } |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9637 | return RD.Vars.empty(); |
| 9638 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9639 | |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9640 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 9641 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9642 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 9643 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 9644 | ArrayRef<Expr *> UnresolvedReductions) { |
| 9645 | ReductionData RD(VarList.size()); |
| 9646 | |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9647 | if (ActOnOMPReductionKindClause(*this, DSAStack, OMPC_reduction, VarList, |
| 9648 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 9649 | ReductionIdScopeSpec, ReductionId, |
| 9650 | UnresolvedReductions, RD)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9651 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9652 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9653 | return OMPReductionClause::Create( |
Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 9654 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 9655 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 9656 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 9657 | buildPreInits(Context, RD.ExprCaptures), |
| 9658 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9659 | } |
| 9660 | |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9661 | OMPClause *Sema::ActOnOpenMPTaskReductionClause( |
| 9662 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9663 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 9664 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 9665 | ArrayRef<Expr *> UnresolvedReductions) { |
| 9666 | ReductionData RD(VarList.size()); |
| 9667 | |
| 9668 | if (ActOnOMPReductionKindClause(*this, DSAStack, OMPC_task_reduction, |
| 9669 | VarList, StartLoc, LParenLoc, ColonLoc, |
| 9670 | EndLoc, ReductionIdScopeSpec, ReductionId, |
| 9671 | UnresolvedReductions, RD)) |
| 9672 | return nullptr; |
| 9673 | |
| 9674 | return OMPTaskReductionClause::Create( |
| 9675 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 9676 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 9677 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 9678 | buildPreInits(Context, RD.ExprCaptures), |
| 9679 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 9680 | } |
| 9681 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame^] | 9682 | OMPClause *Sema::ActOnOpenMPInReductionClause( |
| 9683 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9684 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 9685 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 9686 | ArrayRef<Expr *> UnresolvedReductions) { |
| 9687 | ReductionData RD(VarList.size()); |
| 9688 | |
| 9689 | if (ActOnOMPReductionKindClause(*this, DSAStack, OMPC_in_reduction, VarList, |
| 9690 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 9691 | ReductionIdScopeSpec, ReductionId, |
| 9692 | UnresolvedReductions, RD)) |
| 9693 | return nullptr; |
| 9694 | |
| 9695 | return OMPInReductionClause::Create( |
| 9696 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 9697 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 9698 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 9699 | buildPreInits(Context, RD.ExprCaptures), |
| 9700 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 9701 | } |
| 9702 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9703 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9704 | SourceLocation LinLoc) { |
| 9705 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9706 | LinKind == OMPC_LINEAR_unknown) { |
| 9707 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9708 | return true; |
| 9709 | } |
| 9710 | return false; |
| 9711 | } |
| 9712 | |
| 9713 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9714 | OpenMPLinearClauseKind LinKind, |
| 9715 | QualType Type) { |
| 9716 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9717 | // A variable must not have an incomplete type or a reference type. |
| 9718 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9719 | return true; |
| 9720 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9721 | !Type->isReferenceType()) { |
| 9722 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9723 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9724 | return true; |
| 9725 | } |
| 9726 | Type = Type.getNonReferenceType(); |
| 9727 | |
| 9728 | // A list item must not be const-qualified. |
| 9729 | if (Type.isConstant(Context)) { |
| 9730 | Diag(ELoc, diag::err_omp_const_variable) |
| 9731 | << getOpenMPClauseName(OMPC_linear); |
| 9732 | if (D) { |
| 9733 | bool IsDecl = |
| 9734 | !VD || |
| 9735 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9736 | Diag(D->getLocation(), |
| 9737 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9738 | << D; |
| 9739 | } |
| 9740 | return true; |
| 9741 | } |
| 9742 | |
| 9743 | // A list item must be of integral or pointer type. |
| 9744 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9745 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9746 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9747 | !Ty->isPointerType())) { |
| 9748 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9749 | if (D) { |
| 9750 | bool IsDecl = |
| 9751 | !VD || |
| 9752 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9753 | Diag(D->getLocation(), |
| 9754 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9755 | << D; |
| 9756 | } |
| 9757 | return true; |
| 9758 | } |
| 9759 | return false; |
| 9760 | } |
| 9761 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9762 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9763 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9764 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9765 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9766 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9767 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9768 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9769 | SmallVector<Decl *, 4> ExprCaptures; |
| 9770 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9771 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9772 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9773 | for (auto &RefExpr : VarList) { |
| 9774 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9775 | SourceLocation ELoc; |
| 9776 | SourceRange ERange; |
| 9777 | Expr *SimpleRefExpr = RefExpr; |
| 9778 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9779 | /*AllowArraySection=*/false); |
| 9780 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9781 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9782 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9783 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9784 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9785 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9786 | ValueDecl *D = Res.first; |
| 9787 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9788 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9789 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9790 | QualType Type = D->getType(); |
| 9791 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9792 | |
| 9793 | // OpenMP [2.14.3.7, linear clause] |
| 9794 | // A list-item cannot appear in more than one linear clause. |
| 9795 | // A list-item that appears in a linear clause cannot appear in any |
| 9796 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9797 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9798 | if (DVar.RefExpr) { |
| 9799 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9800 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9801 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9802 | continue; |
| 9803 | } |
| 9804 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9805 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9806 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9807 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9808 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9809 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9810 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9811 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9812 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9813 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9814 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9815 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9816 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9817 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9818 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9819 | if (!IsOpenMPCapturedDecl(D)) { |
| 9820 | ExprCaptures.push_back(Ref->getDecl()); |
| 9821 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9822 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9823 | if (!RefRes.isUsable()) |
| 9824 | continue; |
| 9825 | ExprResult PostUpdateRes = |
| 9826 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9827 | SimpleRefExpr, RefRes.get()); |
| 9828 | if (!PostUpdateRes.isUsable()) |
| 9829 | continue; |
| 9830 | ExprPostUpdates.push_back( |
| 9831 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9832 | } |
| 9833 | } |
| 9834 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9835 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9836 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9837 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9838 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9839 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9840 | /*DirectInit=*/false); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9841 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9842 | |
| 9843 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9844 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9845 | ? RefExpr->IgnoreParens() |
| 9846 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9847 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9848 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9849 | } |
| 9850 | |
| 9851 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9852 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9853 | |
| 9854 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9855 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9856 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9857 | !Step->isInstantiationDependent() && |
| 9858 | !Step->containsUnexpandedParameterPack()) { |
| 9859 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9860 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9861 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9862 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9863 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9864 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9865 | // Build var to save the step value. |
| 9866 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9867 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9868 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9869 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9870 | ExprResult CalcStep = |
| 9871 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9872 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9873 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9874 | // Warn about zero linear step (it would be probably better specified as |
| 9875 | // making corresponding variables 'const'). |
| 9876 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9877 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9878 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9879 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9880 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9881 | if (!IsConstant && CalcStep.isUsable()) { |
| 9882 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9883 | // (This is not used if the number of iterations may be kfold-ed). |
| 9884 | CalcStepExpr = CalcStep.get(); |
| 9885 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9886 | } |
| 9887 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9888 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9889 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9890 | StepExpr, CalcStepExpr, |
| 9891 | buildPreInits(Context, ExprCaptures), |
| 9892 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9893 | } |
| 9894 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9895 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9896 | Expr *NumIterations, Sema &SemaRef, |
| 9897 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9898 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9899 | SmallVector<Expr *, 8> Updates; |
| 9900 | SmallVector<Expr *, 8> Finals; |
| 9901 | Expr *Step = Clause.getStep(); |
| 9902 | Expr *CalcStep = Clause.getCalcStep(); |
| 9903 | // OpenMP [2.14.3.7, linear clause] |
| 9904 | // If linear-step is not specified it is assumed to be 1. |
| 9905 | if (Step == nullptr) |
| 9906 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9907 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9908 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9909 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9910 | bool HasErrors = false; |
| 9911 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9912 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9913 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9914 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9915 | SourceLocation ELoc; |
| 9916 | SourceRange ERange; |
| 9917 | Expr *SimpleRefExpr = RefExpr; |
| 9918 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9919 | /*AllowArraySection=*/false); |
| 9920 | ValueDecl *D = Res.first; |
| 9921 | if (Res.second || !D) { |
| 9922 | Updates.push_back(nullptr); |
| 9923 | Finals.push_back(nullptr); |
| 9924 | HasErrors = true; |
| 9925 | continue; |
| 9926 | } |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9927 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9928 | Expr *InitExpr = *CurInit; |
| 9929 | |
| 9930 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9931 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9932 | Expr *CapturedRef; |
| 9933 | if (LinKind == OMPC_LINEAR_uval) |
| 9934 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9935 | else |
| 9936 | CapturedRef = |
| 9937 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9938 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9939 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9940 | |
| 9941 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9942 | ExprResult Update; |
| 9943 | if (!Info.first) { |
| 9944 | Update = |
| 9945 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9946 | InitExpr, IV, Step, /* Subtract */ false); |
| 9947 | } else |
| 9948 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9949 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9950 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9951 | |
| 9952 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9953 | ExprResult Final; |
| 9954 | if (!Info.first) { |
| 9955 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9956 | InitExpr, NumIterations, Step, |
| 9957 | /* Subtract */ false); |
| 9958 | } else |
| 9959 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9960 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9961 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9962 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9963 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9964 | Updates.push_back(nullptr); |
| 9965 | Finals.push_back(nullptr); |
| 9966 | HasErrors = true; |
| 9967 | } else { |
| 9968 | Updates.push_back(Update.get()); |
| 9969 | Finals.push_back(Final.get()); |
| 9970 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9971 | ++CurInit; |
| 9972 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9973 | } |
| 9974 | Clause.setUpdates(Updates); |
| 9975 | Clause.setFinals(Finals); |
| 9976 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9977 | } |
| 9978 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9979 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9980 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9981 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9982 | |
| 9983 | SmallVector<Expr *, 8> Vars; |
| 9984 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9985 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9986 | SourceLocation ELoc; |
| 9987 | SourceRange ERange; |
| 9988 | Expr *SimpleRefExpr = RefExpr; |
| 9989 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9990 | /*AllowArraySection=*/false); |
| 9991 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9992 | // It will be analyzed later. |
| 9993 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9994 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9995 | ValueDecl *D = Res.first; |
| 9996 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9997 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9998 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9999 | QualType QType = D->getType(); |
| 10000 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10001 | |
| 10002 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 10003 | // The type of list items appearing in the aligned clause must be |
| 10004 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10005 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10006 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10007 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10008 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10009 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10010 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10011 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10012 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10013 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10014 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10015 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10016 | continue; |
| 10017 | } |
| 10018 | |
| 10019 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 10020 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10021 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 10022 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10023 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 10024 | << getOpenMPClauseName(OMPC_aligned); |
| 10025 | continue; |
| 10026 | } |
| 10027 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10028 | DeclRefExpr *Ref = nullptr; |
| 10029 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 10030 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 10031 | Vars.push_back(DefaultFunctionArrayConversion( |
| 10032 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 10033 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10034 | } |
| 10035 | |
| 10036 | // OpenMP [2.8.1, simd construct, Description] |
| 10037 | // The parameter of the aligned clause, alignment, must be a constant |
| 10038 | // positive integer expression. |
| 10039 | // If no optional parameter is specified, implementation-defined default |
| 10040 | // alignments for SIMD instructions on the target platforms are assumed. |
| 10041 | if (Alignment != nullptr) { |
| 10042 | ExprResult AlignResult = |
| 10043 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 10044 | if (AlignResult.isInvalid()) |
| 10045 | return nullptr; |
| 10046 | Alignment = AlignResult.get(); |
| 10047 | } |
| 10048 | if (Vars.empty()) |
| 10049 | return nullptr; |
| 10050 | |
| 10051 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 10052 | EndLoc, Vars, Alignment); |
| 10053 | } |
| 10054 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10055 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 10056 | SourceLocation StartLoc, |
| 10057 | SourceLocation LParenLoc, |
| 10058 | SourceLocation EndLoc) { |
| 10059 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10060 | SmallVector<Expr *, 8> SrcExprs; |
| 10061 | SmallVector<Expr *, 8> DstExprs; |
| 10062 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10063 | for (auto &RefExpr : VarList) { |
| 10064 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 10065 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10066 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10067 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10068 | SrcExprs.push_back(nullptr); |
| 10069 | DstExprs.push_back(nullptr); |
| 10070 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10071 | continue; |
| 10072 | } |
| 10073 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10074 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10075 | // OpenMP [2.1, C/C++] |
| 10076 | // A list item is a variable name. |
| 10077 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 10078 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10079 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10080 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10081 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 10082 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10083 | continue; |
| 10084 | } |
| 10085 | |
| 10086 | Decl *D = DE->getDecl(); |
| 10087 | VarDecl *VD = cast<VarDecl>(D); |
| 10088 | |
| 10089 | QualType Type = VD->getType(); |
| 10090 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 10091 | // It will be analyzed later. |
| 10092 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10093 | SrcExprs.push_back(nullptr); |
| 10094 | DstExprs.push_back(nullptr); |
| 10095 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10096 | continue; |
| 10097 | } |
| 10098 | |
| 10099 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 10100 | // A list item that appears in a copyin clause must be threadprivate. |
| 10101 | if (!DSAStack->isThreadPrivate(VD)) { |
| 10102 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10103 | << getOpenMPClauseName(OMPC_copyin) |
| 10104 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10105 | continue; |
| 10106 | } |
| 10107 | |
| 10108 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10109 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10110 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10111 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10112 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10113 | auto *SrcVD = |
| 10114 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 10115 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 10116 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10117 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 10118 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10119 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 10120 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10121 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10122 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10123 | // For arrays generate assignment operation for single element and replace |
| 10124 | // it by the original array element in CodeGen. |
| 10125 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 10126 | PseudoDstExpr, PseudoSrcExpr); |
| 10127 | if (AssignmentOp.isInvalid()) |
| 10128 | continue; |
| 10129 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 10130 | /*DiscardedValue=*/true); |
| 10131 | if (AssignmentOp.isInvalid()) |
| 10132 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10133 | |
| 10134 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 10135 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10136 | SrcExprs.push_back(PseudoSrcExpr); |
| 10137 | DstExprs.push_back(PseudoDstExpr); |
| 10138 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10139 | } |
| 10140 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10141 | if (Vars.empty()) |
| 10142 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10143 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10144 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 10145 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10146 | } |
| 10147 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10148 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 10149 | SourceLocation StartLoc, |
| 10150 | SourceLocation LParenLoc, |
| 10151 | SourceLocation EndLoc) { |
| 10152 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10153 | SmallVector<Expr *, 8> SrcExprs; |
| 10154 | SmallVector<Expr *, 8> DstExprs; |
| 10155 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10156 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10157 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 10158 | SourceLocation ELoc; |
| 10159 | SourceRange ERange; |
| 10160 | Expr *SimpleRefExpr = RefExpr; |
| 10161 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 10162 | /*AllowArraySection=*/false); |
| 10163 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10164 | // It will be analyzed later. |
| 10165 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10166 | SrcExprs.push_back(nullptr); |
| 10167 | DstExprs.push_back(nullptr); |
| 10168 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10169 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10170 | ValueDecl *D = Res.first; |
| 10171 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10172 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10173 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10174 | QualType Type = D->getType(); |
| 10175 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10176 | |
| 10177 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 10178 | // A list item that appears in a copyprivate clause may not appear in a |
| 10179 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10180 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 10181 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10182 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 10183 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10184 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 10185 | << getOpenMPClauseName(DVar.CKind) |
| 10186 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10187 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10188 | continue; |
| 10189 | } |
| 10190 | |
| 10191 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 10192 | // All list items that appear in a copyprivate clause must be either |
| 10193 | // threadprivate or private in the enclosing context. |
| 10194 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10195 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10196 | if (DVar.CKind == OMPC_shared) { |
| 10197 | Diag(ELoc, diag::err_omp_required_access) |
| 10198 | << getOpenMPClauseName(OMPC_copyprivate) |
| 10199 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10200 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10201 | continue; |
| 10202 | } |
| 10203 | } |
| 10204 | } |
| 10205 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10206 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 10207 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10208 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10209 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 10210 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10211 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10212 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10213 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10214 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10215 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10216 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10217 | continue; |
| 10218 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10219 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10220 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10221 | // A variable of class type (or array thereof) that appears in a |
| 10222 | // copyin clause requires an accessible, unambiguous copy assignment |
| 10223 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 10224 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 10225 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10226 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10227 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 10228 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10229 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10230 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10231 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 10232 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10233 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10234 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10235 | PseudoDstExpr, PseudoSrcExpr); |
| 10236 | if (AssignmentOp.isInvalid()) |
| 10237 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10238 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10239 | /*DiscardedValue=*/true); |
| 10240 | if (AssignmentOp.isInvalid()) |
| 10241 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10242 | |
| 10243 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 10244 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10245 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 10246 | Vars.push_back( |
| 10247 | VD ? RefExpr->IgnoreParens() |
| 10248 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10249 | SrcExprs.push_back(PseudoSrcExpr); |
| 10250 | DstExprs.push_back(PseudoDstExpr); |
| 10251 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10252 | } |
| 10253 | |
| 10254 | if (Vars.empty()) |
| 10255 | return nullptr; |
| 10256 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10257 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10258 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10259 | } |
| 10260 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 10261 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 10262 | SourceLocation StartLoc, |
| 10263 | SourceLocation LParenLoc, |
| 10264 | SourceLocation EndLoc) { |
| 10265 | if (VarList.empty()) |
| 10266 | return nullptr; |
| 10267 | |
| 10268 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 10269 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 10270 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10271 | OMPClause * |
| 10272 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 10273 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 10274 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10275 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10276 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10277 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10278 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10279 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10280 | return nullptr; |
| 10281 | } |
| 10282 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10283 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 10284 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10285 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10286 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10287 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 10288 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 10289 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10290 | return nullptr; |
| 10291 | } |
| 10292 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10293 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10294 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 10295 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 10296 | if (DepKind == OMPC_DEPEND_sink) { |
| 10297 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 10298 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 10299 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10300 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10301 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10302 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 10303 | DSAStack->getParentOrderedRegionParam()) { |
| 10304 | for (auto &RefExpr : VarList) { |
| 10305 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10306 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10307 | // It will be analyzed later. |
| 10308 | Vars.push_back(RefExpr); |
| 10309 | continue; |
| 10310 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10311 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10312 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 10313 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 10314 | if (DepKind == OMPC_DEPEND_sink) { |
| 10315 | if (DepCounter >= TotalDepCount) { |
| 10316 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 10317 | continue; |
| 10318 | } |
| 10319 | ++DepCounter; |
| 10320 | // OpenMP [2.13.9, Summary] |
| 10321 | // depend(dependence-type : vec), where dependence-type is: |
| 10322 | // 'sink' and where vec is the iteration vector, which has the form: |
| 10323 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 10324 | // where n is the value specified by the ordered clause in the loop |
| 10325 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 10326 | // loop associated with the loop directive, and di is a constant |
| 10327 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10328 | if (CurContext->isDependentContext()) { |
| 10329 | // It will be analyzed later. |
| 10330 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10331 | continue; |
| 10332 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10333 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 10334 | OverloadedOperatorKind OOK = OO_None; |
| 10335 | SourceLocation OOLoc; |
| 10336 | Expr *LHS = SimpleExpr; |
| 10337 | Expr *RHS = nullptr; |
| 10338 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 10339 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 10340 | OOLoc = BO->getOperatorLoc(); |
| 10341 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 10342 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 10343 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 10344 | OOK = OCE->getOperator(); |
| 10345 | OOLoc = OCE->getOperatorLoc(); |
| 10346 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10347 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 10348 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 10349 | OOK = MCE->getMethodDecl() |
| 10350 | ->getNameInfo() |
| 10351 | .getName() |
| 10352 | .getCXXOverloadedOperator(); |
| 10353 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 10354 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 10355 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10356 | } |
| 10357 | SourceLocation ELoc; |
| 10358 | SourceRange ERange; |
| 10359 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 10360 | /*AllowArraySection=*/false); |
| 10361 | if (Res.second) { |
| 10362 | // It will be analyzed later. |
| 10363 | Vars.push_back(RefExpr); |
| 10364 | } |
| 10365 | ValueDecl *D = Res.first; |
| 10366 | if (!D) |
| 10367 | continue; |
| 10368 | |
| 10369 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 10370 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 10371 | continue; |
| 10372 | } |
| 10373 | if (RHS) { |
| 10374 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 10375 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10376 | if (RHSRes.isInvalid()) |
| 10377 | continue; |
| 10378 | } |
| 10379 | if (!CurContext->isDependentContext() && |
| 10380 | DSAStack->getParentOrderedRegionParam() && |
| 10381 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10382 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10383 | << DSAStack->getParentLoopControlVariable( |
| 10384 | DepCounter.getZExtValue()); |
| 10385 | continue; |
| 10386 | } |
| 10387 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10388 | } else { |
| 10389 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10390 | // A variable that is part of another variable (such as a field of a |
| 10391 | // structure) but is not an array element or an array section cannot |
| 10392 | // appear in a depend clause. |
| 10393 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10394 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10395 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10396 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10397 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10398 | (ASE && |
| 10399 | !ASE->getBase() |
| 10400 | ->getType() |
| 10401 | .getNonReferenceType() |
| 10402 | ->isPointerType() && |
| 10403 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10404 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10405 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10406 | continue; |
| 10407 | } |
| 10408 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10409 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10410 | } |
| 10411 | |
| 10412 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10413 | TotalDepCount > VarList.size() && |
| 10414 | DSAStack->getParentOrderedRegionParam()) { |
| 10415 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10416 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10417 | } |
| 10418 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10419 | Vars.empty()) |
| 10420 | return nullptr; |
| 10421 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10422 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10423 | DepKind, DepLoc, ColonLoc, Vars); |
| 10424 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10425 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10426 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10427 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10428 | |
| 10429 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10430 | SourceLocation LParenLoc, |
| 10431 | SourceLocation EndLoc) { |
| 10432 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10433 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10434 | // OpenMP [2.9.1, Restrictions] |
| 10435 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10436 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10437 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10438 | return nullptr; |
| 10439 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10440 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10441 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10442 | |
| 10443 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10444 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10445 | if (!RD || RD->isInvalidDecl()) |
| 10446 | return true; |
| 10447 | |
| 10448 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10449 | if (RD->isDynamicClass()) { |
| 10450 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10451 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10452 | return false; |
| 10453 | } |
| 10454 | auto *DC = RD; |
| 10455 | bool IsCorrect = true; |
| 10456 | for (auto *I : DC->decls()) { |
| 10457 | if (I) { |
| 10458 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10459 | if (MD->isStatic()) { |
| 10460 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10461 | SemaRef.Diag(MD->getLocation(), |
| 10462 | diag::note_omp_static_member_in_target); |
| 10463 | IsCorrect = false; |
| 10464 | } |
| 10465 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10466 | if (VD->isStaticDataMember()) { |
| 10467 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10468 | SemaRef.Diag(VD->getLocation(), |
| 10469 | diag::note_omp_static_member_in_target); |
| 10470 | IsCorrect = false; |
| 10471 | } |
| 10472 | } |
| 10473 | } |
| 10474 | } |
| 10475 | |
| 10476 | for (auto &I : RD->bases()) { |
| 10477 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10478 | I.getType()->getAsCXXRecordDecl())) |
| 10479 | IsCorrect = false; |
| 10480 | } |
| 10481 | return IsCorrect; |
| 10482 | } |
| 10483 | |
| 10484 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10485 | DSAStackTy *Stack, QualType QTy) { |
| 10486 | NamedDecl *ND; |
| 10487 | if (QTy->isIncompleteType(&ND)) { |
| 10488 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10489 | return false; |
| 10490 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10491 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10492 | return false; |
| 10493 | } |
| 10494 | return true; |
| 10495 | } |
| 10496 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10497 | /// \brief Return true if it can be proven that the provided array expression |
| 10498 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10499 | /// array whose base type is \a BaseQTy. |
| 10500 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10501 | const Expr *E, |
| 10502 | QualType BaseQTy) { |
| 10503 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10504 | |
| 10505 | // If this is an array subscript, it refers to the whole size if the size of |
| 10506 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10507 | // format of an array subscript if no colon is used. |
| 10508 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10509 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10510 | return ATy->getSize().getSExtValue() != 1; |
| 10511 | // Size can't be evaluated statically. |
| 10512 | return false; |
| 10513 | } |
| 10514 | |
| 10515 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10516 | auto *LowerBound = OASE->getLowerBound(); |
| 10517 | auto *Length = OASE->getLength(); |
| 10518 | |
| 10519 | // 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] | 10520 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10521 | if (LowerBound) { |
| 10522 | llvm::APSInt ConstLowerBound; |
| 10523 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10524 | return false; // Can't get the integer value as a constant. |
| 10525 | if (ConstLowerBound.getSExtValue()) |
| 10526 | return true; |
| 10527 | } |
| 10528 | |
| 10529 | // If we don't have a length we covering the whole dimension. |
| 10530 | if (!Length) |
| 10531 | return false; |
| 10532 | |
| 10533 | // If the base is a pointer, we don't have a way to get the size of the |
| 10534 | // pointee. |
| 10535 | if (BaseQTy->isPointerType()) |
| 10536 | return false; |
| 10537 | |
| 10538 | // We can only check if the length is the same as the size of the dimension |
| 10539 | // if we have a constant array. |
| 10540 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10541 | if (!CATy) |
| 10542 | return false; |
| 10543 | |
| 10544 | llvm::APSInt ConstLength; |
| 10545 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10546 | return false; // Can't get the integer value as a constant. |
| 10547 | |
| 10548 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10549 | } |
| 10550 | |
| 10551 | // Return true if it can be proven that the provided array expression (array |
| 10552 | // section or array subscript) does NOT specify a single element of the array |
| 10553 | // whose base type is \a BaseQTy. |
| 10554 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10555 | const Expr *E, |
| 10556 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10557 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10558 | |
| 10559 | // An array subscript always refer to a single element. Also, an array section |
| 10560 | // assumes the format of an array subscript if no colon is used. |
| 10561 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10562 | return false; |
| 10563 | |
| 10564 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10565 | auto *Length = OASE->getLength(); |
| 10566 | |
| 10567 | // If we don't have a length we have to check if the array has unitary size |
| 10568 | // for this dimension. Also, we should always expect a length if the base type |
| 10569 | // is pointer. |
| 10570 | if (!Length) { |
| 10571 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10572 | return ATy->getSize().getSExtValue() != 1; |
| 10573 | // We cannot assume anything. |
| 10574 | return false; |
| 10575 | } |
| 10576 | |
| 10577 | // Check if the length evaluates to 1. |
| 10578 | llvm::APSInt ConstLength; |
| 10579 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10580 | return false; // Can't get the integer value as a constant. |
| 10581 | |
| 10582 | return ConstLength.getSExtValue() != 1; |
| 10583 | } |
| 10584 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10585 | // Return the expression of the base of the mappable expression or null if it |
| 10586 | // cannot be determined and do all the necessary checks to see if the expression |
| 10587 | // 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] | 10588 | // components of the expression. |
| 10589 | static Expr *CheckMapClauseExpressionBase( |
| 10590 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10591 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10592 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10593 | SourceLocation ELoc = E->getExprLoc(); |
| 10594 | SourceRange ERange = E->getSourceRange(); |
| 10595 | |
| 10596 | // The base of elements of list in a map clause have to be either: |
| 10597 | // - a reference to variable or field. |
| 10598 | // - a member expression. |
| 10599 | // - an array expression. |
| 10600 | // |
| 10601 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10602 | // reference to 'r'. |
| 10603 | // |
| 10604 | // If we have: |
| 10605 | // |
| 10606 | // struct SS { |
| 10607 | // Bla S; |
| 10608 | // foo() { |
| 10609 | // #pragma omp target map (S.Arr[:12]); |
| 10610 | // } |
| 10611 | // } |
| 10612 | // |
| 10613 | // We want to retrieve the member expression 'this->S'; |
| 10614 | |
| 10615 | Expr *RelevantExpr = nullptr; |
| 10616 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10617 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10618 | // If a list item is an array section, it must specify contiguous storage. |
| 10619 | // |
| 10620 | // For this restriction it is sufficient that we make sure only references |
| 10621 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10622 | // exist except in the rightmost expression (unless they cover the whole |
| 10623 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10624 | // |
| 10625 | // r.ArrS[3:5].Arr[6:7] |
| 10626 | // |
| 10627 | // r.ArrS[3:5].x |
| 10628 | // |
| 10629 | // but these would be valid: |
| 10630 | // r.ArrS[3].Arr[6:7] |
| 10631 | // |
| 10632 | // r.ArrS[3].x |
| 10633 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10634 | bool AllowUnitySizeArraySection = true; |
| 10635 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10636 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10637 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10638 | E = E->IgnoreParenImpCasts(); |
| 10639 | |
| 10640 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10641 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10642 | break; |
| 10643 | |
| 10644 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10645 | |
| 10646 | // If we got a reference to a declaration, we should not expect any array |
| 10647 | // section before that. |
| 10648 | AllowUnitySizeArraySection = false; |
| 10649 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10650 | |
| 10651 | // Record the component. |
| 10652 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10653 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10654 | continue; |
| 10655 | } |
| 10656 | |
| 10657 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10658 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10659 | |
| 10660 | if (isa<CXXThisExpr>(BaseE)) |
| 10661 | // We found a base expression: this->Val. |
| 10662 | RelevantExpr = CurE; |
| 10663 | else |
| 10664 | E = BaseE; |
| 10665 | |
| 10666 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10667 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10668 | << CurE->getSourceRange(); |
| 10669 | break; |
| 10670 | } |
| 10671 | |
| 10672 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10673 | |
| 10674 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10675 | // A bit-field cannot appear in a map clause. |
| 10676 | // |
| 10677 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10678 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10679 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10680 | break; |
| 10681 | } |
| 10682 | |
| 10683 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10684 | // If the type of a list item is a reference to a type T then the type |
| 10685 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10686 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10687 | |
| 10688 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10689 | // A list item cannot be a variable that is a member of a structure with |
| 10690 | // a union type. |
| 10691 | // |
| 10692 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10693 | if (RT->isUnionType()) { |
| 10694 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10695 | << CurE->getSourceRange(); |
| 10696 | break; |
| 10697 | } |
| 10698 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10699 | // If we got a member expression, we should not expect any array section |
| 10700 | // before that: |
| 10701 | // |
| 10702 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10703 | // If a list item is an element of a structure, only the rightmost symbol |
| 10704 | // of the variable reference can be an array section. |
| 10705 | // |
| 10706 | AllowUnitySizeArraySection = false; |
| 10707 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10708 | |
| 10709 | // Record the component. |
| 10710 | CurComponents.push_back( |
| 10711 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10712 | continue; |
| 10713 | } |
| 10714 | |
| 10715 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10716 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10717 | |
| 10718 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10719 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10720 | << 0 << CurE->getSourceRange(); |
| 10721 | break; |
| 10722 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10723 | |
| 10724 | // If we got an array subscript that express the whole dimension we |
| 10725 | // can have any array expressions before. If it only expressing part of |
| 10726 | // the dimension, we can only have unitary-size array expressions. |
| 10727 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10728 | E->getType())) |
| 10729 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10730 | |
| 10731 | // Record the component - we don't have any declaration associated. |
| 10732 | CurComponents.push_back( |
| 10733 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10734 | continue; |
| 10735 | } |
| 10736 | |
| 10737 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10738 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10739 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10740 | auto CurType = |
| 10741 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10742 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10743 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10744 | // If the type of a list item is a reference to a type T then the type |
| 10745 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10746 | if (CurType->isReferenceType()) |
| 10747 | CurType = CurType->getPointeeType(); |
| 10748 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10749 | bool IsPointer = CurType->isAnyPointerType(); |
| 10750 | |
| 10751 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10752 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10753 | << 0 << CurE->getSourceRange(); |
| 10754 | break; |
| 10755 | } |
| 10756 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10757 | bool NotWhole = |
| 10758 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10759 | bool NotUnity = |
| 10760 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10761 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10762 | if (AllowWholeSizeArraySection) { |
| 10763 | // Any array section is currently allowed. Allowing a whole size array |
| 10764 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10765 | // |
| 10766 | // If this array section refers to the whole dimension we can still |
| 10767 | // accept other array sections before this one, except if the base is a |
| 10768 | // pointer. Otherwise, only unitary sections are accepted. |
| 10769 | if (NotWhole || IsPointer) |
| 10770 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10771 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10772 | // A unity or whole array section is not allowed and that is not |
| 10773 | // compatible with the properties of the current array section. |
| 10774 | SemaRef.Diag( |
| 10775 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10776 | << CurE->getSourceRange(); |
| 10777 | break; |
| 10778 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10779 | |
| 10780 | // Record the component - we don't have any declaration associated. |
| 10781 | CurComponents.push_back( |
| 10782 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10783 | continue; |
| 10784 | } |
| 10785 | |
| 10786 | // If nothing else worked, this is not a valid map clause expression. |
| 10787 | SemaRef.Diag(ELoc, |
| 10788 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10789 | << ERange; |
| 10790 | break; |
| 10791 | } |
| 10792 | |
| 10793 | return RelevantExpr; |
| 10794 | } |
| 10795 | |
| 10796 | // Return true if expression E associated with value VD has conflicts with other |
| 10797 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10798 | static bool CheckMapConflicts( |
| 10799 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10800 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10801 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10802 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10803 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10804 | SourceLocation ELoc = E->getExprLoc(); |
| 10805 | SourceRange ERange = E->getSourceRange(); |
| 10806 | |
| 10807 | // In order to easily check the conflicts we need to match each component of |
| 10808 | // the expression under test with the components of the expressions that are |
| 10809 | // already in the stack. |
| 10810 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10811 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10812 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10813 | "Map clause expression with unexpected base!"); |
| 10814 | |
| 10815 | // Variables to help detecting enclosing problems in data environment nests. |
| 10816 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10817 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10818 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10819 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10820 | VD, CurrentRegionOnly, |
| 10821 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10822 | StackComponents, |
| 10823 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10824 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10825 | assert(!StackComponents.empty() && |
| 10826 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10827 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10828 | "Map clause expression with unexpected base!"); |
| 10829 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10830 | // The whole expression in the stack. |
| 10831 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10832 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10833 | // Expressions must start from the same base. Here we detect at which |
| 10834 | // point both expressions diverge from each other and see if we can |
| 10835 | // detect if the memory referred to both expressions is contiguous and |
| 10836 | // do not overlap. |
| 10837 | auto CI = CurComponents.rbegin(); |
| 10838 | auto CE = CurComponents.rend(); |
| 10839 | auto SI = StackComponents.rbegin(); |
| 10840 | auto SE = StackComponents.rend(); |
| 10841 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10842 | |
| 10843 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10844 | // At most one list item can be an array item derived from a given |
| 10845 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10846 | if (CurrentRegionOnly && |
| 10847 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10848 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10849 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10850 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10851 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10852 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10853 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10854 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10855 | diag::note_used_here) |
| 10856 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10857 | return true; |
| 10858 | } |
| 10859 | |
| 10860 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10861 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10862 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10863 | break; |
| 10864 | |
| 10865 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10866 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10867 | break; |
| 10868 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10869 | // Check if the extra components of the expressions in the enclosing |
| 10870 | // data environment are redundant for the current base declaration. |
| 10871 | // If they are, the maps completely overlap, which is legal. |
| 10872 | for (; SI != SE; ++SI) { |
| 10873 | QualType Type; |
| 10874 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10875 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10876 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10877 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10878 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10879 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10880 | Type = |
| 10881 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10882 | } |
| 10883 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10884 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10885 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10886 | break; |
| 10887 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10888 | |
| 10889 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10890 | // List items of map clauses in the same construct must not share |
| 10891 | // original storage. |
| 10892 | // |
| 10893 | // If the expressions are exactly the same or one is a subset of the |
| 10894 | // other, it means they are sharing storage. |
| 10895 | if (CI == CE && SI == SE) { |
| 10896 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10897 | if (CKind == OMPC_map) |
| 10898 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10899 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10900 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10901 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10902 | << ERange; |
| 10903 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10904 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10905 | << RE->getSourceRange(); |
| 10906 | return true; |
| 10907 | } else { |
| 10908 | // If we find the same expression in the enclosing data environment, |
| 10909 | // that is legal. |
| 10910 | IsEnclosedByDataEnvironmentExpr = true; |
| 10911 | return false; |
| 10912 | } |
| 10913 | } |
| 10914 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10915 | QualType DerivedType = |
| 10916 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10917 | SourceLocation DerivedLoc = |
| 10918 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10919 | |
| 10920 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10921 | // If the type of a list item is a reference to a type T then the type |
| 10922 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10923 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10924 | |
| 10925 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10926 | // A variable for which the type is pointer and an array section |
| 10927 | // derived from that variable must not appear as list items of map |
| 10928 | // clauses of the same construct. |
| 10929 | // |
| 10930 | // Also, cover one of the cases in: |
| 10931 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10932 | // If any part of the original storage of a list item has corresponding |
| 10933 | // storage in the device data environment, all of the original storage |
| 10934 | // must have corresponding storage in the device data environment. |
| 10935 | // |
| 10936 | if (DerivedType->isAnyPointerType()) { |
| 10937 | if (CI == CE || SI == SE) { |
| 10938 | SemaRef.Diag( |
| 10939 | DerivedLoc, |
| 10940 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10941 | << DerivedLoc; |
| 10942 | } else { |
| 10943 | assert(CI != CE && SI != SE); |
| 10944 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10945 | << DerivedLoc; |
| 10946 | } |
| 10947 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10948 | << RE->getSourceRange(); |
| 10949 | return true; |
| 10950 | } |
| 10951 | |
| 10952 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10953 | // List items of map clauses in the same construct must not share |
| 10954 | // original storage. |
| 10955 | // |
| 10956 | // An expression is a subset of the other. |
| 10957 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10958 | if (CKind == OMPC_map) |
| 10959 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10960 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10961 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10962 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10963 | << ERange; |
| 10964 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10965 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10966 | << RE->getSourceRange(); |
| 10967 | return true; |
| 10968 | } |
| 10969 | |
| 10970 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10971 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10972 | if (!CurrentRegionOnly && SI != SE) |
| 10973 | EnclosingExpr = RE; |
| 10974 | |
| 10975 | // The current expression is a subset of the expression in the data |
| 10976 | // environment. |
| 10977 | IsEnclosedByDataEnvironmentExpr |= |
| 10978 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10979 | |
| 10980 | return false; |
| 10981 | }); |
| 10982 | |
| 10983 | if (CurrentRegionOnly) |
| 10984 | return FoundError; |
| 10985 | |
| 10986 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10987 | // If any part of the original storage of a list item has corresponding |
| 10988 | // storage in the device data environment, all of the original storage must |
| 10989 | // have corresponding storage in the device data environment. |
| 10990 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10991 | // If a list item is an element of a structure, and a different element of |
| 10992 | // the structure has a corresponding list item in the device data environment |
| 10993 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10994 | // 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] | 10995 | // data environment prior to the task encountering the construct. |
| 10996 | // |
| 10997 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10998 | SemaRef.Diag(ELoc, |
| 10999 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 11000 | << ERange; |
| 11001 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 11002 | << EnclosingExpr->getSourceRange(); |
| 11003 | return true; |
| 11004 | } |
| 11005 | |
| 11006 | return FoundError; |
| 11007 | } |
| 11008 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11009 | namespace { |
| 11010 | // Utility struct that gathers all the related lists associated with a mappable |
| 11011 | // expression. |
| 11012 | struct MappableVarListInfo final { |
| 11013 | // The list of expressions. |
| 11014 | ArrayRef<Expr *> VarList; |
| 11015 | // The list of processed expressions. |
| 11016 | SmallVector<Expr *, 16> ProcessedVarList; |
| 11017 | // The mappble components for each expression. |
| 11018 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 11019 | // The base declaration of the variable. |
| 11020 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 11021 | |
| 11022 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 11023 | // We have a list of components and base declarations for each entry in the |
| 11024 | // variable list. |
| 11025 | VarComponents.reserve(VarList.size()); |
| 11026 | VarBaseDeclarations.reserve(VarList.size()); |
| 11027 | } |
| 11028 | }; |
| 11029 | } |
| 11030 | |
| 11031 | // Check the validity of the provided variable list for the provided clause kind |
| 11032 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 11033 | // components and variables are extracted and used to fill \a Vars, |
| 11034 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 11035 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 11036 | static void |
| 11037 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 11038 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 11039 | SourceLocation StartLoc, |
| 11040 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 11041 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11042 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 11043 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11044 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11045 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11046 | // Keep track of the mappable components and base declarations in this clause. |
| 11047 | // Each entry in the list is going to have a list of components associated. We |
| 11048 | // record each set of the components so that we can build the clause later on. |
| 11049 | // In the end we should have the same amount of declarations and component |
| 11050 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11051 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11052 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11053 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11054 | SourceLocation ELoc = RE->getExprLoc(); |
| 11055 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11056 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 11057 | |
| 11058 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 11059 | VE->isInstantiationDependent() || |
| 11060 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11061 | // We can only analyze this information once the missing information is |
| 11062 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11063 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11064 | continue; |
| 11065 | } |
| 11066 | |
| 11067 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11068 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11069 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11070 | SemaRef.Diag(ELoc, |
| 11071 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11072 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11073 | continue; |
| 11074 | } |
| 11075 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11076 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 11077 | ValueDecl *CurDeclaration = nullptr; |
| 11078 | |
| 11079 | // Obtain the array or member expression bases if required. Also, fill the |
| 11080 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11081 | auto *BE = |
| 11082 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11083 | if (!BE) |
| 11084 | continue; |
| 11085 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11086 | assert(!CurComponents.empty() && |
| 11087 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11088 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11089 | // For the following checks, we rely on the base declaration which is |
| 11090 | // expected to be associated with the last component. The declaration is |
| 11091 | // expected to be a variable or a field (if 'this' is being mapped). |
| 11092 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 11093 | assert(CurDeclaration && "Null decl on map clause."); |
| 11094 | assert( |
| 11095 | CurDeclaration->isCanonicalDecl() && |
| 11096 | "Expecting components to have associated only canonical declarations."); |
| 11097 | |
| 11098 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 11099 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11100 | |
| 11101 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 11102 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11103 | |
| 11104 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11105 | // threadprivate variables cannot appear in a map clause. |
| 11106 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 11107 | // threadprivate variables cannot appear in a from clause. |
| 11108 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 11109 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11110 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 11111 | << getOpenMPClauseName(CKind); |
| 11112 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11113 | continue; |
| 11114 | } |
| 11115 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11116 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 11117 | // A list item cannot appear in both a map clause and a data-sharing |
| 11118 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11119 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11120 | // Check conflicts with other map clause expressions. We check the conflicts |
| 11121 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11122 | // environment, because the restrictions are different. We only have to |
| 11123 | // check conflicts across regions for the map clauses. |
| 11124 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11125 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11126 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11127 | if (CKind == OMPC_map && |
| 11128 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11129 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11130 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11131 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11132 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11133 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 11134 | // If the type of a list item is a reference to a type T then the type will |
| 11135 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11136 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11137 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11138 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 11139 | // 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] | 11140 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11141 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11142 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 11143 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11144 | continue; |
| 11145 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11146 | if (CKind == OMPC_map) { |
| 11147 | // target enter data |
| 11148 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 11149 | // A map-type must be specified in all map clauses and must be either |
| 11150 | // to or alloc. |
| 11151 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 11152 | if (DKind == OMPD_target_enter_data && |
| 11153 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 11154 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11155 | << (IsMapTypeImplicit ? 1 : 0) |
| 11156 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11157 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11158 | continue; |
| 11159 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11160 | |
| 11161 | // target exit_data |
| 11162 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 11163 | // A map-type must be specified in all map clauses and must be either |
| 11164 | // from, release, or delete. |
| 11165 | if (DKind == OMPD_target_exit_data && |
| 11166 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 11167 | MapType == OMPC_MAP_delete)) { |
| 11168 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11169 | << (IsMapTypeImplicit ? 1 : 0) |
| 11170 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11171 | << getOpenMPDirectiveName(DKind); |
| 11172 | continue; |
| 11173 | } |
| 11174 | |
| 11175 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 11176 | // A list item cannot appear in both a map clause and a data-sharing |
| 11177 | // attribute clause on the same construct |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 11178 | if ((DKind == OMPD_target || DKind == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 11179 | DKind == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 11180 | DKind == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 11181 | DKind == OMPD_target_teams_distribute_parallel_for_simd || |
| 11182 | DKind == OMPD_target_teams_distribute_simd) && VD) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11183 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11184 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11185 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11186 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11187 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11188 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 11189 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 11190 | continue; |
| 11191 | } |
| 11192 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11193 | } |
| 11194 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11195 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11196 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11197 | |
| 11198 | // Store the components in the stack so that they can be used to check |
| 11199 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11200 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 11201 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11202 | |
| 11203 | // Save the components and declaration to create the clause. For purposes of |
| 11204 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 11205 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11206 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11207 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 11208 | CurComponents.end()); |
| 11209 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 11210 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11211 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11212 | } |
| 11213 | |
| 11214 | OMPClause * |
| 11215 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 11216 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 11217 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 11218 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 11219 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 11220 | MappableVarListInfo MVLI(VarList); |
| 11221 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 11222 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11223 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11224 | // We need to produce a map clause even if we don't have variables so that |
| 11225 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11226 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11227 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11228 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 11229 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11230 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11231 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11232 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 11233 | TypeResult ParsedType) { |
| 11234 | assert(ParsedType.isUsable()); |
| 11235 | |
| 11236 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 11237 | if (ReductionType.isNull()) |
| 11238 | return QualType(); |
| 11239 | |
| 11240 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 11241 | // A type name in a declare reduction directive cannot be a function type, an |
| 11242 | // array type, a reference type, or a type qualified with const, volatile or |
| 11243 | // restrict. |
| 11244 | if (ReductionType.hasQualifiers()) { |
| 11245 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 11246 | return QualType(); |
| 11247 | } |
| 11248 | |
| 11249 | if (ReductionType->isFunctionType()) { |
| 11250 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 11251 | return QualType(); |
| 11252 | } |
| 11253 | if (ReductionType->isReferenceType()) { |
| 11254 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 11255 | return QualType(); |
| 11256 | } |
| 11257 | if (ReductionType->isArrayType()) { |
| 11258 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 11259 | return QualType(); |
| 11260 | } |
| 11261 | return ReductionType; |
| 11262 | } |
| 11263 | |
| 11264 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 11265 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 11266 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 11267 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 11268 | SmallVector<Decl *, 8> Decls; |
| 11269 | Decls.reserve(ReductionTypes.size()); |
| 11270 | |
| 11271 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 11272 | ForRedeclaration); |
| 11273 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 11274 | // A reduction-identifier may not be re-declared in the current scope for the |
| 11275 | // same type or for a type that is compatible according to the base language |
| 11276 | // rules. |
| 11277 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 11278 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 11279 | bool InCompoundScope = true; |
| 11280 | if (S != nullptr) { |
| 11281 | // Find previous declaration with the same name not referenced in other |
| 11282 | // declarations. |
| 11283 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 11284 | InCompoundScope = |
| 11285 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 11286 | LookupName(Lookup, S); |
| 11287 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 11288 | /*AllowInlineNamespace=*/false); |
| 11289 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 11290 | auto Filter = Lookup.makeFilter(); |
| 11291 | while (Filter.hasNext()) { |
| 11292 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 11293 | if (InCompoundScope) { |
| 11294 | auto I = UsedAsPrevious.find(PrevDecl); |
| 11295 | if (I == UsedAsPrevious.end()) |
| 11296 | UsedAsPrevious[PrevDecl] = false; |
| 11297 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 11298 | UsedAsPrevious[D] = true; |
| 11299 | } |
| 11300 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 11301 | PrevDecl->getLocation(); |
| 11302 | } |
| 11303 | Filter.done(); |
| 11304 | if (InCompoundScope) { |
| 11305 | for (auto &PrevData : UsedAsPrevious) { |
| 11306 | if (!PrevData.second) { |
| 11307 | PrevDRD = PrevData.first; |
| 11308 | break; |
| 11309 | } |
| 11310 | } |
| 11311 | } |
| 11312 | } else if (PrevDeclInScope != nullptr) { |
| 11313 | auto *PrevDRDInScope = PrevDRD = |
| 11314 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 11315 | do { |
| 11316 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 11317 | PrevDRDInScope->getLocation(); |
| 11318 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 11319 | } while (PrevDRDInScope != nullptr); |
| 11320 | } |
| 11321 | for (auto &TyData : ReductionTypes) { |
| 11322 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 11323 | bool Invalid = false; |
| 11324 | if (I != PreviousRedeclTypes.end()) { |
| 11325 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 11326 | << TyData.first; |
| 11327 | Diag(I->second, diag::note_previous_definition); |
| 11328 | Invalid = true; |
| 11329 | } |
| 11330 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 11331 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 11332 | Name, TyData.first, PrevDRD); |
| 11333 | DC->addDecl(DRD); |
| 11334 | DRD->setAccess(AS); |
| 11335 | Decls.push_back(DRD); |
| 11336 | if (Invalid) |
| 11337 | DRD->setInvalidDecl(); |
| 11338 | else |
| 11339 | PrevDRD = DRD; |
| 11340 | } |
| 11341 | |
| 11342 | return DeclGroupPtrTy::make( |
| 11343 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 11344 | } |
| 11345 | |
| 11346 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 11347 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11348 | |
| 11349 | // Enter new function scope. |
| 11350 | PushFunctionScope(); |
| 11351 | getCurFunction()->setHasBranchProtectedScope(); |
| 11352 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 11353 | |
| 11354 | if (S != nullptr) |
| 11355 | PushDeclContext(S, DRD); |
| 11356 | else |
| 11357 | CurContext = DRD; |
| 11358 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11359 | PushExpressionEvaluationContext( |
| 11360 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11361 | |
| 11362 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11363 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 11364 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 11365 | // uses semantics of argument handles by value, but it should be passed by |
| 11366 | // reference. C lang does not support references, so pass all parameters as |
| 11367 | // pointers. |
| 11368 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11369 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11370 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11371 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 11372 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 11373 | // uses semantics of argument handles by value, but it should be passed by |
| 11374 | // reference. C lang does not support references, so pass all parameters as |
| 11375 | // pointers. |
| 11376 | // Create 'T omp_out;' variable. |
| 11377 | auto *OmpOutParm = |
| 11378 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11379 | if (S != nullptr) { |
| 11380 | PushOnScopeChains(OmpInParm, S); |
| 11381 | PushOnScopeChains(OmpOutParm, S); |
| 11382 | } else { |
| 11383 | DRD->addDecl(OmpInParm); |
| 11384 | DRD->addDecl(OmpOutParm); |
| 11385 | } |
| 11386 | } |
| 11387 | |
| 11388 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11389 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11390 | DiscardCleanupsInEvaluationContext(); |
| 11391 | PopExpressionEvaluationContext(); |
| 11392 | |
| 11393 | PopDeclContext(); |
| 11394 | PopFunctionScopeInfo(); |
| 11395 | |
| 11396 | if (Combiner != nullptr) |
| 11397 | DRD->setCombiner(Combiner); |
| 11398 | else |
| 11399 | DRD->setInvalidDecl(); |
| 11400 | } |
| 11401 | |
| 11402 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11403 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11404 | |
| 11405 | // Enter new function scope. |
| 11406 | PushFunctionScope(); |
| 11407 | getCurFunction()->setHasBranchProtectedScope(); |
| 11408 | |
| 11409 | if (S != nullptr) |
| 11410 | PushDeclContext(S, DRD); |
| 11411 | else |
| 11412 | CurContext = DRD; |
| 11413 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11414 | PushExpressionEvaluationContext( |
| 11415 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11416 | |
| 11417 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11418 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11419 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11420 | // uses semantics of argument handles by value, but it should be passed by |
| 11421 | // reference. C lang does not support references, so pass all parameters as |
| 11422 | // pointers. |
| 11423 | // Create 'T omp_priv;' variable. |
| 11424 | auto *OmpPrivParm = |
| 11425 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11426 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11427 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11428 | // uses semantics of argument handles by value, but it should be passed by |
| 11429 | // reference. C lang does not support references, so pass all parameters as |
| 11430 | // pointers. |
| 11431 | // Create 'T omp_orig;' variable. |
| 11432 | auto *OmpOrigParm = |
| 11433 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11434 | if (S != nullptr) { |
| 11435 | PushOnScopeChains(OmpPrivParm, S); |
| 11436 | PushOnScopeChains(OmpOrigParm, S); |
| 11437 | } else { |
| 11438 | DRD->addDecl(OmpPrivParm); |
| 11439 | DRD->addDecl(OmpOrigParm); |
| 11440 | } |
| 11441 | } |
| 11442 | |
| 11443 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11444 | Expr *Initializer) { |
| 11445 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11446 | DiscardCleanupsInEvaluationContext(); |
| 11447 | PopExpressionEvaluationContext(); |
| 11448 | |
| 11449 | PopDeclContext(); |
| 11450 | PopFunctionScopeInfo(); |
| 11451 | |
| 11452 | if (Initializer != nullptr) |
| 11453 | DRD->setInitializer(Initializer); |
| 11454 | else |
| 11455 | DRD->setInvalidDecl(); |
| 11456 | } |
| 11457 | |
| 11458 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11459 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11460 | for (auto *D : DeclReductions.get()) { |
| 11461 | if (IsValid) { |
| 11462 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11463 | if (S != nullptr) |
| 11464 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11465 | } else |
| 11466 | D->setInvalidDecl(); |
| 11467 | } |
| 11468 | return DeclReductions; |
| 11469 | } |
| 11470 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11471 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11472 | SourceLocation StartLoc, |
| 11473 | SourceLocation LParenLoc, |
| 11474 | SourceLocation EndLoc) { |
| 11475 | Expr *ValExpr = NumTeams; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11476 | Stmt *HelperValStmt = nullptr; |
| 11477 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11478 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11479 | // OpenMP [teams Constrcut, Restrictions] |
| 11480 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11481 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11482 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11483 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11484 | |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11485 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11486 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams); |
| 11487 | if (CaptureRegion != OMPD_unknown) { |
| 11488 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11489 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11490 | HelperValStmt = buildPreInits(Context, Captures); |
| 11491 | } |
| 11492 | |
| 11493 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 11494 | StartLoc, LParenLoc, EndLoc); |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11495 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11496 | |
| 11497 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11498 | SourceLocation StartLoc, |
| 11499 | SourceLocation LParenLoc, |
| 11500 | SourceLocation EndLoc) { |
| 11501 | Expr *ValExpr = ThreadLimit; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11502 | Stmt *HelperValStmt = nullptr; |
| 11503 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11504 | |
| 11505 | // OpenMP [teams Constrcut, Restrictions] |
| 11506 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11507 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11508 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11509 | return nullptr; |
| 11510 | |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11511 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11512 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_thread_limit); |
| 11513 | if (CaptureRegion != OMPD_unknown) { |
| 11514 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11515 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11516 | HelperValStmt = buildPreInits(Context, Captures); |
| 11517 | } |
| 11518 | |
| 11519 | return new (Context) OMPThreadLimitClause( |
| 11520 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11521 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11522 | |
| 11523 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11524 | SourceLocation StartLoc, |
| 11525 | SourceLocation LParenLoc, |
| 11526 | SourceLocation EndLoc) { |
| 11527 | Expr *ValExpr = Priority; |
| 11528 | |
| 11529 | // OpenMP [2.9.1, task Constrcut] |
| 11530 | // The priority-value is a non-negative numerical scalar expression. |
| 11531 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11532 | /*StrictlyPositive=*/false)) |
| 11533 | return nullptr; |
| 11534 | |
| 11535 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11536 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11537 | |
| 11538 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11539 | SourceLocation StartLoc, |
| 11540 | SourceLocation LParenLoc, |
| 11541 | SourceLocation EndLoc) { |
| 11542 | Expr *ValExpr = Grainsize; |
| 11543 | |
| 11544 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11545 | // The parameter of the grainsize clause must be a positive integer |
| 11546 | // expression. |
| 11547 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11548 | /*StrictlyPositive=*/true)) |
| 11549 | return nullptr; |
| 11550 | |
| 11551 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11552 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11553 | |
| 11554 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11555 | SourceLocation StartLoc, |
| 11556 | SourceLocation LParenLoc, |
| 11557 | SourceLocation EndLoc) { |
| 11558 | Expr *ValExpr = NumTasks; |
| 11559 | |
| 11560 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11561 | // The parameter of the num_tasks clause must be a positive integer |
| 11562 | // expression. |
| 11563 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11564 | /*StrictlyPositive=*/true)) |
| 11565 | return nullptr; |
| 11566 | |
| 11567 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11568 | } |
| 11569 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11570 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11571 | SourceLocation LParenLoc, |
| 11572 | SourceLocation EndLoc) { |
| 11573 | // OpenMP [2.13.2, critical construct, Description] |
| 11574 | // ... where hint-expression is an integer constant expression that evaluates |
| 11575 | // to a valid lock hint. |
| 11576 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11577 | if (HintExpr.isInvalid()) |
| 11578 | return nullptr; |
| 11579 | return new (Context) |
| 11580 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11581 | } |
| 11582 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11583 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11584 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11585 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11586 | SourceLocation EndLoc) { |
| 11587 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11588 | std::string Values; |
| 11589 | Values += "'"; |
| 11590 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11591 | Values += "'"; |
| 11592 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11593 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11594 | return nullptr; |
| 11595 | } |
| 11596 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11597 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11598 | if (ChunkSize) { |
| 11599 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11600 | !ChunkSize->isInstantiationDependent() && |
| 11601 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11602 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11603 | ExprResult Val = |
| 11604 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11605 | if (Val.isInvalid()) |
| 11606 | return nullptr; |
| 11607 | |
| 11608 | ValExpr = Val.get(); |
| 11609 | |
| 11610 | // OpenMP [2.7.1, Restrictions] |
| 11611 | // chunk_size must be a loop invariant integer expression with a positive |
| 11612 | // value. |
| 11613 | llvm::APSInt Result; |
| 11614 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11615 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11616 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11617 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11618 | return nullptr; |
| 11619 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11620 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11621 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11622 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11623 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11624 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11625 | } |
| 11626 | } |
| 11627 | } |
| 11628 | |
| 11629 | return new (Context) |
| 11630 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11631 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11632 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11633 | |
| 11634 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11635 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11636 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11637 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11638 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11639 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11640 | std::string Value; |
| 11641 | SourceLocation Loc; |
| 11642 | Value += "'"; |
| 11643 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11644 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11645 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11646 | Loc = MLoc; |
| 11647 | } else { |
| 11648 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11649 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11650 | Loc = KindLoc; |
| 11651 | } |
| 11652 | Value += "'"; |
| 11653 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11654 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11655 | return nullptr; |
| 11656 | } |
| 11657 | |
| 11658 | return new (Context) |
| 11659 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11660 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11661 | |
| 11662 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11663 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11664 | if (!CurLexicalContext->isFileContext() && |
| 11665 | !CurLexicalContext->isExternCContext() && |
| 11666 | !CurLexicalContext->isExternCXXContext()) { |
| 11667 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11668 | return false; |
| 11669 | } |
| 11670 | if (IsInOpenMPDeclareTargetContext) { |
| 11671 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11672 | return false; |
| 11673 | } |
| 11674 | |
| 11675 | IsInOpenMPDeclareTargetContext = true; |
| 11676 | return true; |
| 11677 | } |
| 11678 | |
| 11679 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11680 | assert(IsInOpenMPDeclareTargetContext && |
| 11681 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11682 | |
| 11683 | IsInOpenMPDeclareTargetContext = false; |
| 11684 | } |
| 11685 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11686 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 11687 | CXXScopeSpec &ScopeSpec, |
| 11688 | const DeclarationNameInfo &Id, |
| 11689 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11690 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11691 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11692 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11693 | |
| 11694 | if (Lookup.isAmbiguous()) |
| 11695 | return; |
| 11696 | Lookup.suppressDiagnostics(); |
| 11697 | |
| 11698 | if (!Lookup.isSingleResult()) { |
| 11699 | if (TypoCorrection Corrected = |
| 11700 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11701 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11702 | CTK_ErrorRecovery)) { |
| 11703 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11704 | << Id.getName()); |
| 11705 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11706 | return; |
| 11707 | } |
| 11708 | |
| 11709 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11710 | return; |
| 11711 | } |
| 11712 | |
| 11713 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11714 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11715 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11716 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11717 | |
| 11718 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11719 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11720 | ND->addAttr(A); |
| 11721 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11722 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11723 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11724 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11725 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11726 | << Id.getName(); |
| 11727 | } |
| 11728 | } else |
| 11729 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11730 | } |
| 11731 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11732 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11733 | Sema &SemaRef, Decl *D) { |
| 11734 | if (!D) |
| 11735 | return; |
| 11736 | Decl *LD = nullptr; |
| 11737 | if (isa<TagDecl>(D)) { |
| 11738 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11739 | } else if (isa<VarDecl>(D)) { |
| 11740 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11741 | |
| 11742 | // If this is an implicit variable that is legal and we do not need to do |
| 11743 | // anything. |
| 11744 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11745 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11746 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11747 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11748 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11749 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11750 | return; |
| 11751 | } |
| 11752 | |
| 11753 | } else if (isa<FunctionDecl>(D)) { |
| 11754 | const FunctionDecl *FD = nullptr; |
| 11755 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11756 | LD = const_cast<FunctionDecl *>(FD); |
| 11757 | |
| 11758 | // If the definition is associated with the current declaration in the |
| 11759 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11760 | // to do anything else. |
| 11761 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11762 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11763 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11764 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11765 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11766 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11767 | return; |
| 11768 | } |
| 11769 | } |
| 11770 | if (!LD) |
| 11771 | LD = D; |
| 11772 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11773 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11774 | // Outlined declaration is not declared target. |
| 11775 | if (LD->isOutOfLine()) { |
| 11776 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11777 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11778 | } else { |
| 11779 | DeclContext *DC = LD->getDeclContext(); |
| 11780 | while (DC) { |
| 11781 | if (isa<FunctionDecl>(DC) && |
| 11782 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11783 | break; |
| 11784 | DC = DC->getParent(); |
| 11785 | } |
| 11786 | if (DC) |
| 11787 | return; |
| 11788 | |
| 11789 | // Is not declared in target context. |
| 11790 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11791 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11792 | } |
| 11793 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11794 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11795 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11796 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11797 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11798 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11799 | } |
| 11800 | } |
| 11801 | |
| 11802 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11803 | Sema &SemaRef, DSAStackTy *Stack, |
| 11804 | ValueDecl *VD) { |
| 11805 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11806 | return true; |
| 11807 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11808 | return false; |
| 11809 | return true; |
| 11810 | } |
| 11811 | |
| 11812 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11813 | if (!D || D->isInvalidDecl()) |
| 11814 | return; |
| 11815 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11816 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11817 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11818 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11819 | if (DSAStack->isThreadPrivate(VD)) { |
| 11820 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11821 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11822 | return; |
| 11823 | } |
| 11824 | } |
| 11825 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11826 | // Problem if any with var declared with incomplete type will be reported |
| 11827 | // as normal, so no need to check it here. |
| 11828 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11829 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11830 | // Mark decl as declared target to prevent further diagnostic. |
| 11831 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11832 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11833 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11834 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11835 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11836 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11837 | } |
| 11838 | return; |
| 11839 | } |
| 11840 | } |
| 11841 | if (!E) { |
| 11842 | // Checking declaration inside declare target region. |
| 11843 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11844 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11845 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11846 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11847 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11848 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11849 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11850 | } |
| 11851 | return; |
| 11852 | } |
| 11853 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11854 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11855 | |
| 11856 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11857 | SourceLocation StartLoc, |
| 11858 | SourceLocation LParenLoc, |
| 11859 | SourceLocation EndLoc) { |
| 11860 | MappableVarListInfo MVLI(VarList); |
| 11861 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11862 | if (MVLI.ProcessedVarList.empty()) |
| 11863 | return nullptr; |
| 11864 | |
| 11865 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11866 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11867 | MVLI.VarComponents); |
| 11868 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11869 | |
| 11870 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11871 | SourceLocation StartLoc, |
| 11872 | SourceLocation LParenLoc, |
| 11873 | SourceLocation EndLoc) { |
| 11874 | MappableVarListInfo MVLI(VarList); |
| 11875 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11876 | if (MVLI.ProcessedVarList.empty()) |
| 11877 | return nullptr; |
| 11878 | |
| 11879 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11880 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11881 | MVLI.VarComponents); |
| 11882 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11883 | |
| 11884 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11885 | SourceLocation StartLoc, |
| 11886 | SourceLocation LParenLoc, |
| 11887 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11888 | MappableVarListInfo MVLI(VarList); |
| 11889 | SmallVector<Expr *, 8> PrivateCopies; |
| 11890 | SmallVector<Expr *, 8> Inits; |
| 11891 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11892 | for (auto &RefExpr : VarList) { |
| 11893 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11894 | SourceLocation ELoc; |
| 11895 | SourceRange ERange; |
| 11896 | Expr *SimpleRefExpr = RefExpr; |
| 11897 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11898 | if (Res.second) { |
| 11899 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11900 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11901 | PrivateCopies.push_back(nullptr); |
| 11902 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11903 | } |
| 11904 | ValueDecl *D = Res.first; |
| 11905 | if (!D) |
| 11906 | continue; |
| 11907 | |
| 11908 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11909 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11910 | |
| 11911 | auto *VD = dyn_cast<VarDecl>(D); |
| 11912 | |
| 11913 | // Item should be a pointer or reference to pointer. |
| 11914 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11915 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11916 | << 0 << RefExpr->getSourceRange(); |
| 11917 | continue; |
| 11918 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11919 | |
| 11920 | // Build the private variable and the expression that refers to it. |
| 11921 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11922 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11923 | if (VDPrivate->isInvalidDecl()) |
| 11924 | continue; |
| 11925 | |
| 11926 | CurContext->addDecl(VDPrivate); |
| 11927 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11928 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11929 | |
| 11930 | // Add temporary variable to initialize the private copy of the pointer. |
| 11931 | auto *VDInit = |
| 11932 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11933 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11934 | RefExpr->getExprLoc()); |
| 11935 | AddInitializerToDecl(VDPrivate, |
| 11936 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11937 | /*DirectInit=*/false); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11938 | |
| 11939 | // If required, build a capture to implement the privatization initialized |
| 11940 | // with the current list item value. |
| 11941 | DeclRefExpr *Ref = nullptr; |
| 11942 | if (!VD) |
| 11943 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11944 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11945 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11946 | Inits.push_back(VDInitRefExpr); |
| 11947 | |
| 11948 | // We need to add a data sharing attribute for this variable to make sure it |
| 11949 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11950 | // similar properties of a first private variable. |
| 11951 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11952 | |
| 11953 | // Create a mappable component for the list item. List items in this clause |
| 11954 | // only need a component. |
| 11955 | MVLI.VarBaseDeclarations.push_back(D); |
| 11956 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11957 | MVLI.VarComponents.back().push_back( |
| 11958 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11959 | } |
| 11960 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11961 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11962 | return nullptr; |
| 11963 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11964 | return OMPUseDevicePtrClause::Create( |
| 11965 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11966 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11967 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11968 | |
| 11969 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11970 | SourceLocation StartLoc, |
| 11971 | SourceLocation LParenLoc, |
| 11972 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11973 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11974 | for (auto &RefExpr : VarList) { |
Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 11975 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11976 | SourceLocation ELoc; |
| 11977 | SourceRange ERange; |
| 11978 | Expr *SimpleRefExpr = RefExpr; |
| 11979 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11980 | if (Res.second) { |
| 11981 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11982 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11983 | } |
| 11984 | ValueDecl *D = Res.first; |
| 11985 | if (!D) |
| 11986 | continue; |
| 11987 | |
| 11988 | QualType Type = D->getType(); |
| 11989 | // item should be a pointer or array or reference to pointer or array |
| 11990 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11991 | !Type.getNonReferenceType()->isArrayType()) { |
| 11992 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11993 | << 0 << RefExpr->getSourceRange(); |
| 11994 | continue; |
| 11995 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11996 | |
| 11997 | // Check if the declaration in the clause does not show up in any data |
| 11998 | // sharing attribute. |
| 11999 | auto DVar = DSAStack->getTopDSA(D, false); |
| 12000 | if (isOpenMPPrivate(DVar.CKind)) { |
| 12001 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 12002 | << getOpenMPClauseName(DVar.CKind) |
| 12003 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 12004 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 12005 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 12006 | continue; |
| 12007 | } |
| 12008 | |
| 12009 | Expr *ConflictExpr; |
| 12010 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12011 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12012 | [&ConflictExpr]( |
| 12013 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 12014 | OpenMPClauseKind) -> bool { |
| 12015 | ConflictExpr = R.front().getAssociatedExpression(); |
| 12016 | return true; |
| 12017 | })) { |
| 12018 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 12019 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 12020 | << ConflictExpr->getSourceRange(); |
| 12021 | continue; |
| 12022 | } |
| 12023 | |
| 12024 | // Store the components in the stack so that they can be used to check |
| 12025 | // against other clauses later on. |
| 12026 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 12027 | DSAStack->addMappableExpressionComponents( |
| 12028 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 12029 | |
| 12030 | // Record the expression we've just processed. |
| 12031 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 12032 | |
| 12033 | // Create a mappable component for the list item. List items in this clause |
| 12034 | // only need a component. We use a null declaration to signal fields in |
| 12035 | // 'this'. |
| 12036 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 12037 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 12038 | "Unexpected device pointer expression!"); |
| 12039 | MVLI.VarBaseDeclarations.push_back( |
| 12040 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 12041 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 12042 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12043 | } |
| 12044 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12045 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12046 | return nullptr; |
| 12047 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12048 | return OMPIsDevicePtrClause::Create( |
| 12049 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 12050 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12051 | } |