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 | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // Stack of data-sharing attributes for variables |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace { |
| 41 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 42 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 43 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 44 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 45 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 46 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 47 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 49 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 50 | bool operator()(T Kind) { |
| 51 | for (auto KindEl : Arr) |
| 52 | if (KindEl == Kind) |
| 53 | return true; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | ArrayRef<T> Arr; |
| 59 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 60 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 61 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 62 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 66 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 67 | |
| 68 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 69 | /// clauses and their data-sharing attributes. |
| 70 | class DSAStackTy { |
| 71 | public: |
| 72 | struct DSAVarData { |
| 73 | OpenMPDirectiveKind DKind; |
| 74 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 75 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 76 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 77 | SourceLocation ImplicitDSALoc; |
| 78 | DSAVarData() |
| 79 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 80 | PrivateCopy(nullptr), ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 81 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 82 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 83 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 84 | typedef SmallVector<Expr *, 4> MapInfo; |
| 85 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | struct DSAInfo { |
| 87 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 88 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 89 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 90 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 91 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 92 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 93 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 94 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 95 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 96 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 97 | |
| 98 | struct SharingMapTy { |
| 99 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 100 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 101 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 102 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 103 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 105 | OpenMPDirectiveKind Directive; |
| 106 | DeclarationNameInfo DirectiveName; |
| 107 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 108 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 109 | /// \brief first argument (Expr *) contains optional argument of the |
| 110 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 111 | /// clause, false otherwise. |
| 112 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 113 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 114 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 115 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 116 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 117 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 118 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 119 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 120 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 121 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 122 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 124 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 125 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 126 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 127 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 130 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 131 | |
| 132 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 133 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 134 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 135 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 136 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 137 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 138 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 139 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | |
| 141 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 142 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 143 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 144 | |
| 145 | /// \brief Checks if the variable is a local for OpenMP region. |
| 146 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 147 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 148 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 149 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 150 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 151 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 152 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 153 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 154 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 156 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 157 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 158 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 159 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 160 | Scope *CurScope, SourceLocation Loc) { |
| 161 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 162 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void pop() { |
| 166 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 167 | Stack.pop_back(); |
| 168 | } |
| 169 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 170 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 171 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 172 | } |
| 173 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 174 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 175 | auto I = Criticals.find(Name.getAsString()); |
| 176 | if (I != Criticals.end()) |
| 177 | return I->second; |
| 178 | return std::make_pair(nullptr, llvm::APSInt()); |
| 179 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 180 | /// \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] | 181 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 182 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 183 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 184 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 185 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 186 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 187 | /// \brief Check if the specified variable is a loop control variable for |
| 188 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 189 | /// \return The index of the loop control variable in the list of associated |
| 190 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 191 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 192 | /// \brief Check if the specified variable is a loop control variable for |
| 193 | /// parent region. |
| 194 | /// \return The index of the loop control variable in the list of associated |
| 195 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 196 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 197 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 198 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 199 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 200 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 201 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 202 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 203 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 204 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 205 | /// \brief Returns data sharing attributes from top of the stack for the |
| 206 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 207 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 208 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 209 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 210 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 211 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 212 | /// predicate. |
| 213 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 214 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 215 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 216 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 217 | /// match specified \a CPred predicate in any innermost directive which |
| 218 | /// matches \a DPred predicate. |
| 219 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 220 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 221 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 222 | /// \brief Checks if the specified variables has explicit data-sharing |
| 223 | /// attributes which match specified \a CPred predicate at the specified |
| 224 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 225 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 226 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 227 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 228 | |
| 229 | /// \brief Returns true if the directive at level \Level matches in the |
| 230 | /// specified \a DPred predicate. |
| 231 | bool hasExplicitDirective( |
| 232 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 233 | unsigned Level); |
| 234 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 235 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 236 | template <class NamedDirectivesPredicate> |
| 237 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 238 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 239 | /// \brief Returns currently analyzed directive. |
| 240 | OpenMPDirectiveKind getCurrentDirective() const { |
| 241 | return Stack.back().Directive; |
| 242 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 243 | /// \brief Returns parent directive. |
| 244 | OpenMPDirectiveKind getParentDirective() const { |
| 245 | if (Stack.size() > 2) |
| 246 | return Stack[Stack.size() - 2].Directive; |
| 247 | return OMPD_unknown; |
| 248 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 249 | /// \brief Return the directive associated with the provided scope. |
| 250 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 251 | |
| 252 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 253 | void setDefaultDSANone(SourceLocation Loc) { |
| 254 | Stack.back().DefaultAttr = DSA_none; |
| 255 | Stack.back().DefaultAttrLoc = Loc; |
| 256 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 257 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 258 | void setDefaultDSAShared(SourceLocation Loc) { |
| 259 | Stack.back().DefaultAttr = DSA_shared; |
| 260 | Stack.back().DefaultAttrLoc = Loc; |
| 261 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 262 | |
| 263 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 264 | return Stack.back().DefaultAttr; |
| 265 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 266 | SourceLocation getDefaultDSALocation() const { |
| 267 | return Stack.back().DefaultAttrLoc; |
| 268 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 269 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 270 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 271 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 272 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 273 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 276 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 277 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 278 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 279 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 280 | } |
| 281 | /// \brief Returns true, if parent region is ordered (has associated |
| 282 | /// 'ordered' clause), false - otherwise. |
| 283 | bool isParentOrderedRegion() const { |
| 284 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 285 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 286 | return false; |
| 287 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 288 | /// \brief Returns optional parameter for the ordered region. |
| 289 | Expr *getParentOrderedRegionParam() const { |
| 290 | if (Stack.size() > 2) |
| 291 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 292 | return nullptr; |
| 293 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 294 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 295 | void setNowaitRegion(bool IsNowait = true) { |
| 296 | Stack.back().NowaitRegion = IsNowait; |
| 297 | } |
| 298 | /// \brief Returns true, if parent region is nowait (has associated |
| 299 | /// 'nowait' clause), false - otherwise. |
| 300 | bool isParentNowaitRegion() const { |
| 301 | if (Stack.size() > 2) |
| 302 | return Stack[Stack.size() - 2].NowaitRegion; |
| 303 | return false; |
| 304 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 305 | /// \brief Marks parent region as cancel region. |
| 306 | void setParentCancelRegion(bool Cancel = true) { |
| 307 | if (Stack.size() > 2) |
| 308 | Stack[Stack.size() - 2].CancelRegion = |
| 309 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 310 | } |
| 311 | /// \brief Return true if current region has inner cancel construct. |
| 312 | bool isCancelRegion() const { |
| 313 | return Stack.back().CancelRegion; |
| 314 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 315 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 316 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 317 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 318 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 319 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 320 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 321 | /// \brief Marks current target region as one with closely nested teams |
| 322 | /// region. |
| 323 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 324 | if (Stack.size() > 2) |
| 325 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 326 | } |
| 327 | /// \brief Returns true, if current region has closely nested teams region. |
| 328 | bool hasInnerTeamsRegion() const { |
| 329 | return getInnerTeamsRegionLoc().isValid(); |
| 330 | } |
| 331 | /// \brief Returns location of the nested teams region (if any). |
| 332 | SourceLocation getInnerTeamsRegionLoc() const { |
| 333 | if (Stack.size() > 1) |
| 334 | return Stack.back().InnerTeamsRegionLoc; |
| 335 | return SourceLocation(); |
| 336 | } |
| 337 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 338 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 339 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 340 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 341 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 342 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 343 | // found. |
| 344 | template <class MapInfoCheck> |
| 345 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 346 | MapInfoCheck Check) { |
| 347 | auto SI = Stack.rbegin(); |
| 348 | auto SE = Stack.rend(); |
| 349 | |
| 350 | if (SI == SE) |
| 351 | return false; |
| 352 | |
| 353 | if (CurrentRegionOnly) { |
| 354 | SE = std::next(SI); |
| 355 | } else { |
| 356 | ++SI; |
| 357 | } |
| 358 | |
| 359 | for (; SI != SE; ++SI) { |
| 360 | auto MI = SI->MappedDecls.find(VD); |
| 361 | if (MI != SI->MappedDecls.end()) { |
| 362 | for (Expr *E : MI->second) { |
| 363 | if (Check(E)) |
| 364 | return true; |
| 365 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 368 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 371 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 372 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 373 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 376 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 377 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 378 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 379 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 380 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 381 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 382 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 383 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 384 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 385 | auto *VD = dyn_cast<VarDecl>(D); |
| 386 | auto *FD = dyn_cast<FieldDecl>(D); |
| 387 | if (VD != nullptr) { |
| 388 | VD = VD->getCanonicalDecl(); |
| 389 | D = VD; |
| 390 | } else { |
| 391 | assert(FD); |
| 392 | FD = FD->getCanonicalDecl(); |
| 393 | D = FD; |
| 394 | } |
| 395 | return D; |
| 396 | } |
| 397 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 398 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 399 | ValueDecl *D) { |
| 400 | D = getCanonicalDecl(D); |
| 401 | auto *VD = dyn_cast<VarDecl>(D); |
| 402 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 403 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 404 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 405 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 406 | // in a region but not in construct] |
| 407 | // File-scope or namespace-scope variables referenced in called routines |
| 408 | // in the region are shared unless they appear in a threadprivate |
| 409 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 410 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 411 | DVar.CKind = OMPC_shared; |
| 412 | |
| 413 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 414 | // in a region but not in construct] |
| 415 | // Variables with static storage duration that are declared in called |
| 416 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 417 | if (VD && VD->hasGlobalStorage()) |
| 418 | DVar.CKind = OMPC_shared; |
| 419 | |
| 420 | // Non-static data members are shared by default. |
| 421 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 422 | DVar.CKind = OMPC_shared; |
| 423 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 424 | return DVar; |
| 425 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 426 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 428 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 429 | // in a Construct, C/C++, predetermined, p.1] |
| 430 | // Variables with automatic storage duration that are declared in a scope |
| 431 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 432 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 433 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 434 | DVar.CKind = OMPC_private; |
| 435 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 438 | // Explicitly specified attributes and local variables with predetermined |
| 439 | // attributes. |
| 440 | if (Iter->SharingMap.count(D)) { |
| 441 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 442 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 444 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | return DVar; |
| 446 | } |
| 447 | |
| 448 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 449 | // in a Construct, C/C++, implicitly determined, p.1] |
| 450 | // In a parallel or task construct, the data-sharing attributes of these |
| 451 | // variables are determined by the default clause, if present. |
| 452 | switch (Iter->DefaultAttr) { |
| 453 | case DSA_shared: |
| 454 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 455 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 456 | return DVar; |
| 457 | case DSA_none: |
| 458 | return DVar; |
| 459 | case DSA_unspecified: |
| 460 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 461 | // in a Construct, implicitly determined, p.2] |
| 462 | // In a parallel construct, if no default clause is present, these |
| 463 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 464 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 465 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 466 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 467 | DVar.CKind = OMPC_shared; |
| 468 | return DVar; |
| 469 | } |
| 470 | |
| 471 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 472 | // in a Construct, implicitly determined, p.4] |
| 473 | // In a task construct, if no default clause is present, a variable that in |
| 474 | // the enclosing context is determined to be shared by all implicit tasks |
| 475 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | if (DVar.DKind == OMPD_task) { |
| 477 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 478 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 479 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 480 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 481 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 482 | // in a Construct, implicitly determined, p.6] |
| 483 | // In a task construct, if no default clause is present, a variable |
| 484 | // whose data-sharing attribute is not determined by the rules above is |
| 485 | // firstprivate. |
| 486 | DVarTemp = getDSA(I, D); |
| 487 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 488 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 489 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 490 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | return DVar; |
| 492 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 493 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 494 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 495 | } |
| 496 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 498 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 499 | return DVar; |
| 500 | } |
| 501 | } |
| 502 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 503 | // in a Construct, implicitly determined, p.3] |
| 504 | // For constructs other than task, if no default clause is present, these |
| 505 | // variables inherit their data-sharing attributes from the enclosing |
| 506 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 507 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 510 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 511 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 512 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 513 | auto It = Stack.back().AlignedMap.find(D); |
| 514 | if (It == Stack.back().AlignedMap.end()) { |
| 515 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 516 | Stack.back().AlignedMap[D] = NewDE; |
| 517 | return nullptr; |
| 518 | } else { |
| 519 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 520 | return It->second; |
| 521 | } |
| 522 | return nullptr; |
| 523 | } |
| 524 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 526 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 527 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 528 | Stack.back().LCVMap.insert(std::make_pair(D, Stack.back().LCVMap.size() + 1)); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 531 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 532 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 534 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 535 | } |
| 536 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 538 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 539 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 540 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 541 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 542 | : 0; |
| 543 | } |
| 544 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 545 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 546 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 547 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 548 | return nullptr; |
| 549 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 550 | if (Pair.second == I) |
| 551 | return Pair.first; |
| 552 | } |
| 553 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 556 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 557 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 558 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 559 | if (A == OMPC_threadprivate) { |
| 560 | Stack[0].SharingMap[D].Attributes = A; |
| 561 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 562 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 563 | } else { |
| 564 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 565 | Stack.back().SharingMap[D].Attributes = A; |
| 566 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 567 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 568 | if (PrivateCopy) |
| 569 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 573 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 574 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 575 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 576 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 577 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 578 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 579 | ++I; |
| 580 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 581 | if (I == E) |
| 582 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 583 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 584 | Scope *CurScope = getCurScope(); |
| 585 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 587 | } |
| 588 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 589 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 590 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 593 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 594 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 595 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 596 | DeclContext *DC = SemaRef.CurContext; |
| 597 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 598 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 599 | VarDecl *Decl = |
| 600 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 601 | if (Attrs) { |
| 602 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 603 | I != E; ++I) |
| 604 | Decl->addAttr(*I); |
| 605 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 606 | Decl->setImplicit(); |
| 607 | return Decl; |
| 608 | } |
| 609 | |
| 610 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 611 | SourceLocation Loc, |
| 612 | bool RefersToCapture = false) { |
| 613 | D->setReferenced(); |
| 614 | D->markUsed(S.Context); |
| 615 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 616 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 617 | VK_LValue); |
| 618 | } |
| 619 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 620 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 621 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 622 | DSAVarData DVar; |
| 623 | |
| 624 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 625 | // in a Construct, C/C++, predetermined, p.1] |
| 626 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 627 | auto *VD = dyn_cast<VarDecl>(D); |
| 628 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 629 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 630 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 631 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 632 | (VD && VD->getStorageClass() == SC_Register && |
| 633 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 634 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 635 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 636 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 637 | } |
| 638 | if (Stack[0].SharingMap.count(D)) { |
| 639 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 640 | DVar.CKind = OMPC_threadprivate; |
| 641 | return DVar; |
| 642 | } |
| 643 | |
| 644 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 645 | // in a Construct, C/C++, predetermined, p.4] |
| 646 | // Static data members are shared. |
| 647 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 648 | // in a Construct, C/C++, predetermined, p.7] |
| 649 | // Variables with static storage duration that are declared in a scope |
| 650 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 651 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 652 | DSAVarData DVarTemp = |
| 653 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 654 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 655 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 656 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 657 | DVar.CKind = OMPC_shared; |
| 658 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 662 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 663 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 664 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 665 | // in a Construct, C/C++, predetermined, p.6] |
| 666 | // Variables with const qualified type having no mutable member are |
| 667 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 668 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 669 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 670 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 671 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 672 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 674 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 675 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 676 | // Variables with const-qualified type having no mutable member may be |
| 677 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 678 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 679 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 680 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 681 | return DVar; |
| 682 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 683 | DVar.CKind = OMPC_shared; |
| 684 | return DVar; |
| 685 | } |
| 686 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 687 | // Explicitly specified attributes and local variables with predetermined |
| 688 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 689 | auto StartI = std::next(Stack.rbegin()); |
| 690 | auto EndI = std::prev(Stack.rend()); |
| 691 | if (FromParent && StartI != EndI) { |
| 692 | StartI = std::next(StartI); |
| 693 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 694 | auto I = std::prev(StartI); |
| 695 | if (I->SharingMap.count(D)) { |
| 696 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 697 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 698 | DVar.CKind = I->SharingMap[D].Attributes; |
| 699 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | return DVar; |
| 703 | } |
| 704 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 705 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 706 | bool FromParent) { |
| 707 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | auto StartI = Stack.rbegin(); |
| 709 | auto EndI = std::prev(Stack.rend()); |
| 710 | if (FromParent && StartI != EndI) { |
| 711 | StartI = std::next(StartI); |
| 712 | } |
| 713 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 716 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 717 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 718 | DirectivesPredicate DPred, |
| 719 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 720 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 721 | auto StartI = std::next(Stack.rbegin()); |
| 722 | auto EndI = std::prev(Stack.rend()); |
| 723 | if (FromParent && StartI != EndI) { |
| 724 | StartI = std::next(StartI); |
| 725 | } |
| 726 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 727 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 728 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 729 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 730 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 731 | return DVar; |
| 732 | } |
| 733 | return DSAVarData(); |
| 734 | } |
| 735 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 736 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 737 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 738 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 739 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 740 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 741 | auto StartI = std::next(Stack.rbegin()); |
| 742 | auto EndI = std::prev(Stack.rend()); |
| 743 | if (FromParent && StartI != EndI) { |
| 744 | StartI = std::next(StartI); |
| 745 | } |
| 746 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 747 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 748 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 749 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 750 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 751 | return DVar; |
| 752 | return DSAVarData(); |
| 753 | } |
| 754 | return DSAVarData(); |
| 755 | } |
| 756 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 757 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 758 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 759 | unsigned Level) { |
| 760 | if (CPred(ClauseKindMode)) |
| 761 | return true; |
| 762 | if (isClauseParsingMode()) |
| 763 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 764 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 765 | auto StartI = Stack.rbegin(); |
| 766 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 767 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 768 | return false; |
| 769 | std::advance(StartI, Level); |
| 770 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 771 | CPred(StartI->SharingMap[D].Attributes); |
| 772 | } |
| 773 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 774 | bool DSAStackTy::hasExplicitDirective( |
| 775 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 776 | unsigned Level) { |
| 777 | if (isClauseParsingMode()) |
| 778 | ++Level; |
| 779 | auto StartI = Stack.rbegin(); |
| 780 | auto EndI = std::prev(Stack.rend()); |
| 781 | if (std::distance(StartI, EndI) <= (int)Level) |
| 782 | return false; |
| 783 | std::advance(StartI, Level); |
| 784 | return DPred(StartI->Directive); |
| 785 | } |
| 786 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 787 | template <class NamedDirectivesPredicate> |
| 788 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 789 | auto StartI = std::next(Stack.rbegin()); |
| 790 | auto EndI = std::prev(Stack.rend()); |
| 791 | if (FromParent && StartI != EndI) { |
| 792 | StartI = std::next(StartI); |
| 793 | } |
| 794 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 795 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 796 | return true; |
| 797 | } |
| 798 | return false; |
| 799 | } |
| 800 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 801 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 802 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 803 | if (I->CurScope == S) |
| 804 | return I->Directive; |
| 805 | return OMPD_unknown; |
| 806 | } |
| 807 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 808 | void Sema::InitDataSharingAttributesStack() { |
| 809 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 810 | } |
| 811 | |
| 812 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 813 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 814 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 815 | const CapturedRegionScopeInfo *RSI) { |
| 816 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 817 | |
| 818 | auto &Ctx = getASTContext(); |
| 819 | bool IsByRef = true; |
| 820 | |
| 821 | // Find the directive that is associated with the provided scope. |
| 822 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 823 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 824 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 825 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 826 | // This table summarizes how a given variable should be passed to the device |
| 827 | // given its type and the clauses where it appears. This table is based on |
| 828 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 829 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 830 | // |
| 831 | // ========================================================================= |
| 832 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 833 | // | |(tofrom:scalar)| | pvt | | | | |
| 834 | // ========================================================================= |
| 835 | // | scl | | | | - | | bycopy| |
| 836 | // | scl | | - | x | - | - | bycopy| |
| 837 | // | scl | | x | - | - | - | null | |
| 838 | // | scl | x | | | - | | byref | |
| 839 | // | scl | x | - | x | - | - | bycopy| |
| 840 | // | scl | x | x | - | - | - | null | |
| 841 | // | scl | | - | - | - | x | byref | |
| 842 | // | scl | x | - | - | - | x | byref | |
| 843 | // |
| 844 | // | agg | n.a. | | | - | | byref | |
| 845 | // | agg | n.a. | - | x | - | - | byref | |
| 846 | // | agg | n.a. | x | - | - | - | null | |
| 847 | // | agg | n.a. | - | - | - | x | byref | |
| 848 | // | agg | n.a. | - | - | - | x[] | byref | |
| 849 | // |
| 850 | // | ptr | n.a. | | | - | | bycopy| |
| 851 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 852 | // | ptr | n.a. | x | - | - | - | null | |
| 853 | // | ptr | n.a. | - | - | - | x | byref | |
| 854 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 855 | // | ptr | n.a. | - | - | x | | bycopy| |
| 856 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 857 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 858 | // ========================================================================= |
| 859 | // Legend: |
| 860 | // scl - scalar |
| 861 | // ptr - pointer |
| 862 | // agg - aggregate |
| 863 | // x - applies |
| 864 | // - - invalid in this combination |
| 865 | // [] - mapped with an array section |
| 866 | // byref - should be mapped by reference |
| 867 | // byval - should be mapped by value |
| 868 | // null - initialize a local variable to null on the device |
| 869 | // |
| 870 | // Observations: |
| 871 | // - All scalar declarations that show up in a map clause have to be passed |
| 872 | // by reference, because they may have been mapped in the enclosing data |
| 873 | // environment. |
| 874 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 875 | // passed by reference, regardless the result in the table above. |
| 876 | // - For pointers mapped by value that have either an implicit map or an |
| 877 | // array section, the runtime library may pass the NULL value to the |
| 878 | // device instead of the value passed to it by the compiler. |
| 879 | |
| 880 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 881 | // values requires having the map, private, and firstprivate clauses SEMA |
| 882 | // and parsing in place, which we don't yet. |
| 883 | |
| 884 | if (Ty->isReferenceType()) |
| 885 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 886 | IsByRef = !Ty->isScalarType(); |
| 887 | } |
| 888 | |
| 889 | // When passing data by value, we need to make sure it fits the uintptr size |
| 890 | // and alignment, because the runtime library only deals with uintptr types. |
| 891 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 892 | // instead. |
| 893 | if (!IsByRef && |
| 894 | (Ctx.getTypeSizeInChars(Ty) > |
| 895 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 896 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 897 | IsByRef = true; |
| 898 | |
| 899 | return IsByRef; |
| 900 | } |
| 901 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 902 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 903 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 904 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 905 | |
| 906 | // If we are attempting to capture a global variable in a directive with |
| 907 | // 'target' we return true so that this global is also mapped to the device. |
| 908 | // |
| 909 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 910 | // then it should not be captured. Therefore, an extra check has to be |
| 911 | // inserted here once support for 'declare target' is added. |
| 912 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 913 | auto *VD = dyn_cast<VarDecl>(D); |
| 914 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 915 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 916 | !DSAStack->isClauseParsingMode()) |
| 917 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 918 | if (DSAStack->getCurScope() && |
| 919 | DSAStack->hasDirective( |
| 920 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 921 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 922 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 923 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 924 | false)) |
| 925 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 928 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 929 | (!DSAStack->isClauseParsingMode() || |
| 930 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 931 | if (DSAStack->isLoopControlVariable(D) || |
| 932 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 933 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 934 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 935 | return VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 936 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 937 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 938 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 939 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 940 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 941 | if (DVarPrivate.CKind != OMPC_unknown) |
| 942 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 943 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 944 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 947 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 948 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 949 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 950 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 953 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 954 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 955 | // Return true if the current level is no longer enclosed in a target region. |
| 956 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 957 | auto *VD = dyn_cast<VarDecl>(D); |
| 958 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 959 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 960 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 963 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 964 | |
| 965 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 966 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 967 | Scope *CurScope, SourceLocation Loc) { |
| 968 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 969 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 970 | } |
| 971 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 972 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 973 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 976 | void Sema::EndOpenMPClause() { |
| 977 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 980 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 981 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 982 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 983 | // clause requires an accessible, unambiguous default constructor for the |
| 984 | // class type, unless the list item is also specified in a firstprivate |
| 985 | // clause. |
| 986 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 987 | for (auto *C : D->clauses()) { |
| 988 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 989 | SmallVector<Expr *, 8> PrivateCopies; |
| 990 | for (auto *DE : Clause->varlists()) { |
| 991 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 992 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 993 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 994 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 995 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 996 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 997 | QualType Type = VD->getType().getNonReferenceType(); |
| 998 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 999 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1000 | // Generate helper private variable and initialize it with the |
| 1001 | // default value. The address of the original variable is replaced |
| 1002 | // by the address of the new private variable in CodeGen. This new |
| 1003 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1004 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1005 | auto *VDPrivate = buildVarDecl( |
| 1006 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1007 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1008 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1009 | if (VDPrivate->isInvalidDecl()) |
| 1010 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1011 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1012 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1013 | } else { |
| 1014 | // The variable is also a firstprivate, so initialization sequence |
| 1015 | // for private copy is generated already. |
| 1016 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1017 | } |
| 1018 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1019 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1020 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1021 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1026 | DSAStack->pop(); |
| 1027 | DiscardCleanupsInEvaluationContext(); |
| 1028 | PopExpressionEvaluationContext(); |
| 1029 | } |
| 1030 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1031 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1032 | Expr *NumIterations, Sema &SemaRef, |
| 1033 | Scope *S); |
| 1034 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1035 | namespace { |
| 1036 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1037 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1038 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1039 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1040 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1041 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1042 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1043 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1044 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1045 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1046 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1047 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1048 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1049 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1051 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1052 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1053 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1054 | |
| 1055 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1056 | CXXScopeSpec &ScopeSpec, |
| 1057 | const DeclarationNameInfo &Id) { |
| 1058 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1059 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1060 | |
| 1061 | if (Lookup.isAmbiguous()) |
| 1062 | return ExprError(); |
| 1063 | |
| 1064 | VarDecl *VD; |
| 1065 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1066 | if (TypoCorrection Corrected = CorrectTypo( |
| 1067 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1068 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1069 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1070 | PDiag(Lookup.empty() |
| 1071 | ? diag::err_undeclared_var_use_suggest |
| 1072 | : diag::err_omp_expected_var_arg_suggest) |
| 1073 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1074 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1075 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1076 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1077 | : diag::err_omp_expected_var_arg) |
| 1078 | << Id.getName(); |
| 1079 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1080 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1081 | } else { |
| 1082 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1083 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1084 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1085 | return ExprError(); |
| 1086 | } |
| 1087 | } |
| 1088 | Lookup.suppressDiagnostics(); |
| 1089 | |
| 1090 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1091 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1092 | if (!VD->hasGlobalStorage()) { |
| 1093 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1094 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1095 | bool IsDecl = |
| 1096 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1097 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1098 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1099 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1100 | return ExprError(); |
| 1101 | } |
| 1102 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1103 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1104 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1105 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1106 | // A threadprivate directive for file-scope variables must appear outside |
| 1107 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1108 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1109 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1110 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1111 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1112 | bool IsDecl = |
| 1113 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1114 | Diag(VD->getLocation(), |
| 1115 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1116 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1117 | return ExprError(); |
| 1118 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1119 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1120 | // A threadprivate directive for static class member variables must appear |
| 1121 | // in the class definition, in the same scope in which the member |
| 1122 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1123 | if (CanonicalVD->isStaticDataMember() && |
| 1124 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1125 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1126 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1127 | bool IsDecl = |
| 1128 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1129 | Diag(VD->getLocation(), |
| 1130 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1131 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1132 | return ExprError(); |
| 1133 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1135 | // A threadprivate directive for namespace-scope variables must appear |
| 1136 | // outside any definition or declaration other than the namespace |
| 1137 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1138 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1139 | (!getCurLexicalContext()->isFileContext() || |
| 1140 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1141 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1142 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1143 | bool IsDecl = |
| 1144 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1145 | Diag(VD->getLocation(), |
| 1146 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1147 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1148 | return ExprError(); |
| 1149 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1150 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1151 | // A threadprivate directive for static block-scope variables must appear |
| 1152 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1153 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1154 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1155 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1156 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1157 | bool IsDecl = |
| 1158 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1159 | Diag(VD->getLocation(), |
| 1160 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1161 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1162 | return ExprError(); |
| 1163 | } |
| 1164 | |
| 1165 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1166 | // A threadprivate directive must lexically precede all references to any |
| 1167 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1168 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1169 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1170 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1171 | return ExprError(); |
| 1172 | } |
| 1173 | |
| 1174 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1175 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1176 | SourceLocation(), VD, |
| 1177 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1178 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1181 | Sema::DeclGroupPtrTy |
| 1182 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1183 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1184 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1185 | CurContext->addDecl(D); |
| 1186 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1187 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1188 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1191 | namespace { |
| 1192 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1193 | Sema &SemaRef; |
| 1194 | |
| 1195 | public: |
| 1196 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1197 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1198 | if (VD->hasLocalStorage()) { |
| 1199 | SemaRef.Diag(E->getLocStart(), |
| 1200 | diag::err_omp_local_var_in_threadprivate_init) |
| 1201 | << E->getSourceRange(); |
| 1202 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1203 | << VD << VD->getSourceRange(); |
| 1204 | return true; |
| 1205 | } |
| 1206 | } |
| 1207 | return false; |
| 1208 | } |
| 1209 | bool VisitStmt(const Stmt *S) { |
| 1210 | for (auto Child : S->children()) { |
| 1211 | if (Child && Visit(Child)) |
| 1212 | return true; |
| 1213 | } |
| 1214 | return false; |
| 1215 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1216 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1217 | }; |
| 1218 | } // namespace |
| 1219 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1220 | OMPThreadPrivateDecl * |
| 1221 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1222 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1223 | for (auto &RefExpr : VarList) { |
| 1224 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1225 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1226 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1227 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1228 | // Mark variable as used. |
| 1229 | VD->setReferenced(); |
| 1230 | VD->markUsed(Context); |
| 1231 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1232 | QualType QType = VD->getType(); |
| 1233 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1234 | // It will be analyzed later. |
| 1235 | Vars.push_back(DE); |
| 1236 | continue; |
| 1237 | } |
| 1238 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1239 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1240 | // A threadprivate variable must not have an incomplete type. |
| 1241 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1242 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1243 | continue; |
| 1244 | } |
| 1245 | |
| 1246 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1247 | // A threadprivate variable must not have a reference type. |
| 1248 | if (VD->getType()->isReferenceType()) { |
| 1249 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1250 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1251 | bool IsDecl = |
| 1252 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1253 | Diag(VD->getLocation(), |
| 1254 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1255 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1256 | continue; |
| 1257 | } |
| 1258 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1259 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1260 | // the corresponding diagnostic. |
| 1261 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1262 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1263 | getLangOpts().OpenMPUseTLS && |
| 1264 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1265 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1266 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1267 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1268 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1269 | bool IsDecl = |
| 1270 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1271 | Diag(VD->getLocation(), |
| 1272 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1273 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1274 | continue; |
| 1275 | } |
| 1276 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1277 | // Check if initial value of threadprivate variable reference variable with |
| 1278 | // local storage (it is not supported by runtime). |
| 1279 | if (auto Init = VD->getAnyInitializer()) { |
| 1280 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1281 | if (Checker.Visit(Init)) |
| 1282 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1285 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1286 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1287 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1288 | Context, SourceRange(Loc, Loc))); |
| 1289 | if (auto *ML = Context.getASTMutationListener()) |
| 1290 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1291 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1292 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1293 | if (!Vars.empty()) { |
| 1294 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1295 | Vars); |
| 1296 | D->setAccess(AS_public); |
| 1297 | } |
| 1298 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1299 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1300 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1301 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1302 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1303 | bool IsLoopIterVar = false) { |
| 1304 | if (DVar.RefExpr) { |
| 1305 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1306 | << getOpenMPClauseName(DVar.CKind); |
| 1307 | return; |
| 1308 | } |
| 1309 | enum { |
| 1310 | PDSA_StaticMemberShared, |
| 1311 | PDSA_StaticLocalVarShared, |
| 1312 | PDSA_LoopIterVarPrivate, |
| 1313 | PDSA_LoopIterVarLinear, |
| 1314 | PDSA_LoopIterVarLastprivate, |
| 1315 | PDSA_ConstVarShared, |
| 1316 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1317 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1318 | PDSA_LocalVarPrivate, |
| 1319 | PDSA_Implicit |
| 1320 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1321 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1322 | auto ReportLoc = D->getLocation(); |
| 1323 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1324 | if (IsLoopIterVar) { |
| 1325 | if (DVar.CKind == OMPC_private) |
| 1326 | Reason = PDSA_LoopIterVarPrivate; |
| 1327 | else if (DVar.CKind == OMPC_lastprivate) |
| 1328 | Reason = PDSA_LoopIterVarLastprivate; |
| 1329 | else |
| 1330 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1331 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1332 | Reason = PDSA_TaskVarFirstprivate; |
| 1333 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1334 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1335 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1336 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1337 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1338 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1339 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1340 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1341 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1342 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1343 | ReportHint = true; |
| 1344 | Reason = PDSA_LocalVarPrivate; |
| 1345 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1346 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1347 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1348 | << Reason << ReportHint |
| 1349 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1350 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1351 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1352 | << getOpenMPClauseName(DVar.CKind); |
| 1353 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1356 | namespace { |
| 1357 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1358 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1359 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | bool ErrorFound; |
| 1361 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1362 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1363 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1364 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1365 | public: |
| 1366 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1367 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1368 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1369 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1370 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1371 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1372 | auto DVar = Stack->getTopDSA(VD, false); |
| 1373 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1374 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1375 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | auto ELoc = E->getExprLoc(); |
| 1377 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1378 | // The default(none) clause requires that each variable that is referenced |
| 1379 | // in the construct, and does not have a predetermined data-sharing |
| 1380 | // attribute, must have its data-sharing attribute explicitly determined |
| 1381 | // by being listed in a data-sharing attribute clause. |
| 1382 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1383 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1384 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1385 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1390 | // A list item that appears in a reduction clause of the innermost |
| 1391 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1392 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1393 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1394 | [](OpenMPDirectiveKind K) -> bool { |
| 1395 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1396 | isOpenMPWorksharingDirective(K) || |
| 1397 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1398 | }, |
| 1399 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1400 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1401 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1402 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1403 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1404 | return; |
| 1405 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1406 | |
| 1407 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1408 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1409 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1410 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1411 | } |
| 1412 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1413 | void VisitMemberExpr(MemberExpr *E) { |
| 1414 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1415 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1416 | auto DVar = Stack->getTopDSA(FD, false); |
| 1417 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1418 | // so. |
| 1419 | if (DVar.RefExpr) |
| 1420 | return; |
| 1421 | |
| 1422 | auto ELoc = E->getExprLoc(); |
| 1423 | auto DKind = Stack->getCurrentDirective(); |
| 1424 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1425 | // A list item that appears in a reduction clause of the innermost |
| 1426 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1427 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1428 | DVar = |
| 1429 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1430 | [](OpenMPDirectiveKind K) -> bool { |
| 1431 | return isOpenMPParallelDirective(K) || |
| 1432 | isOpenMPWorksharingDirective(K) || |
| 1433 | isOpenMPTeamsDirective(K); |
| 1434 | }, |
| 1435 | false); |
| 1436 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1437 | ErrorFound = true; |
| 1438 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1439 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1440 | return; |
| 1441 | } |
| 1442 | |
| 1443 | // Define implicit data-sharing attributes for task. |
| 1444 | DVar = Stack->getImplicitDSA(FD, false); |
| 1445 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1446 | ImplicitFirstprivate.push_back(E); |
| 1447 | } |
| 1448 | } |
| 1449 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1450 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1451 | for (auto *C : S->clauses()) { |
| 1452 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1453 | // for task directives. |
| 1454 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1455 | for (auto *CC : C->children()) { |
| 1456 | if (CC) |
| 1457 | Visit(CC); |
| 1458 | } |
| 1459 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1460 | } |
| 1461 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1462 | for (auto *C : S->children()) { |
| 1463 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1464 | Visit(C); |
| 1465 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1466 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | |
| 1468 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1469 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1470 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1471 | return VarsWithInheritedDSA; |
| 1472 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1473 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1474 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1475 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1477 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1478 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1479 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1480 | switch (DKind) { |
| 1481 | case OMPD_parallel: { |
| 1482 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1483 | QualType KmpInt32PtrTy = |
| 1484 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1485 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1486 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1487 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1488 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1489 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1490 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1491 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1495 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1496 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1497 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1498 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1499 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | } |
| 1502 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1503 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1504 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1505 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1506 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1507 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1510 | case OMPD_for_simd: { |
| 1511 | Sema::CapturedParamNameType Params[] = { |
| 1512 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1513 | }; |
| 1514 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1515 | Params); |
| 1516 | break; |
| 1517 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1518 | case OMPD_sections: { |
| 1519 | Sema::CapturedParamNameType Params[] = { |
| 1520 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1521 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1522 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1523 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1524 | break; |
| 1525 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1526 | case OMPD_section: { |
| 1527 | Sema::CapturedParamNameType Params[] = { |
| 1528 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1529 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1530 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1531 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1532 | break; |
| 1533 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1534 | case OMPD_single: { |
| 1535 | Sema::CapturedParamNameType Params[] = { |
| 1536 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1537 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1538 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1539 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1542 | case OMPD_master: { |
| 1543 | Sema::CapturedParamNameType Params[] = { |
| 1544 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1545 | }; |
| 1546 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1547 | Params); |
| 1548 | break; |
| 1549 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1550 | case OMPD_critical: { |
| 1551 | Sema::CapturedParamNameType Params[] = { |
| 1552 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1553 | }; |
| 1554 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1555 | Params); |
| 1556 | break; |
| 1557 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1558 | case OMPD_parallel_for: { |
| 1559 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1560 | QualType KmpInt32PtrTy = |
| 1561 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1562 | Sema::CapturedParamNameType Params[] = { |
| 1563 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1564 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1565 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1566 | }; |
| 1567 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1568 | Params); |
| 1569 | break; |
| 1570 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1571 | case OMPD_parallel_for_simd: { |
| 1572 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1573 | QualType KmpInt32PtrTy = |
| 1574 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1575 | Sema::CapturedParamNameType Params[] = { |
| 1576 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1577 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1578 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1579 | }; |
| 1580 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1581 | Params); |
| 1582 | break; |
| 1583 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1584 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1585 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1586 | QualType KmpInt32PtrTy = |
| 1587 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1588 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1589 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1590 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1591 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1592 | }; |
| 1593 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1594 | Params); |
| 1595 | break; |
| 1596 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1597 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1598 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1599 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1600 | FunctionProtoType::ExtProtoInfo EPI; |
| 1601 | EPI.Variadic = true; |
| 1602 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1603 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1604 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1605 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1606 | std::make_pair(".privates.", |
| 1607 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1608 | std::make_pair( |
| 1609 | ".copy_fn.", |
| 1610 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1611 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1612 | }; |
| 1613 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1614 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1615 | // Mark this captured region as inlined, because we don't use outlined |
| 1616 | // function directly. |
| 1617 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1618 | AlwaysInlineAttr::CreateImplicit( |
| 1619 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1620 | break; |
| 1621 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1622 | case OMPD_ordered: { |
| 1623 | Sema::CapturedParamNameType Params[] = { |
| 1624 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1625 | }; |
| 1626 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1627 | Params); |
| 1628 | break; |
| 1629 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1630 | case OMPD_atomic: { |
| 1631 | Sema::CapturedParamNameType Params[] = { |
| 1632 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1633 | }; |
| 1634 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1635 | Params); |
| 1636 | break; |
| 1637 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1638 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1639 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1640 | case OMPD_target_parallel: |
| 1641 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1642 | Sema::CapturedParamNameType Params[] = { |
| 1643 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1644 | }; |
| 1645 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1646 | Params); |
| 1647 | break; |
| 1648 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1649 | case OMPD_teams: { |
| 1650 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1651 | QualType KmpInt32PtrTy = |
| 1652 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1653 | Sema::CapturedParamNameType Params[] = { |
| 1654 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1655 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1656 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1657 | }; |
| 1658 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1659 | Params); |
| 1660 | break; |
| 1661 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1662 | case OMPD_taskgroup: { |
| 1663 | Sema::CapturedParamNameType Params[] = { |
| 1664 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1665 | }; |
| 1666 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1667 | Params); |
| 1668 | break; |
| 1669 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1670 | case OMPD_taskloop: { |
| 1671 | Sema::CapturedParamNameType Params[] = { |
| 1672 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1673 | }; |
| 1674 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1675 | Params); |
| 1676 | break; |
| 1677 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1678 | case OMPD_taskloop_simd: { |
| 1679 | Sema::CapturedParamNameType Params[] = { |
| 1680 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1681 | }; |
| 1682 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1683 | Params); |
| 1684 | break; |
| 1685 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1686 | case OMPD_distribute: { |
| 1687 | Sema::CapturedParamNameType Params[] = { |
| 1688 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1689 | }; |
| 1690 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1691 | Params); |
| 1692 | break; |
| 1693 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1694 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1695 | case OMPD_taskyield: |
| 1696 | case OMPD_barrier: |
| 1697 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1698 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1699 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1700 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1701 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1702 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1703 | case OMPD_declare_reduction: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1704 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1705 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1706 | llvm_unreachable("Unknown OpenMP directive"); |
| 1707 | } |
| 1708 | } |
| 1709 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1710 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1711 | Expr *CaptureExpr, bool WithInit) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1712 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1713 | ASTContext &C = S.getASTContext(); |
| 1714 | Expr *Init = CaptureExpr->IgnoreImpCasts(); |
| 1715 | QualType Ty = Init->getType(); |
| 1716 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1717 | if (S.getLangOpts().CPlusPlus) |
| 1718 | Ty = C.getLValueReferenceType(Ty); |
| 1719 | else { |
| 1720 | Ty = C.getPointerType(Ty); |
| 1721 | ExprResult Res = |
| 1722 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1723 | if (!Res.isUsable()) |
| 1724 | return nullptr; |
| 1725 | Init = Res.get(); |
| 1726 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1727 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1728 | } |
| 1729 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1730 | if (!WithInit) |
| 1731 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1732 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1733 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1734 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1735 | return CED; |
| 1736 | } |
| 1737 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1738 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1739 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1740 | OMPCapturedExprDecl *CD; |
| 1741 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1742 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1743 | else |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1744 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1745 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1746 | SourceLocation()); |
| 1747 | } |
| 1748 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1749 | static DeclRefExpr *buildCapture(Sema &S, Expr *CaptureExpr) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1750 | auto *CD = |
| 1751 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1752 | CaptureExpr, /*WithInit=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1753 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1754 | SourceLocation()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1757 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1758 | ArrayRef<OMPClause *> Clauses) { |
| 1759 | if (!S.isUsable()) { |
| 1760 | ActOnCapturedRegionError(); |
| 1761 | return StmtError(); |
| 1762 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1763 | |
| 1764 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1765 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1766 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1767 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1768 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1769 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1770 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1771 | (getLangOpts().OpenMPUseTLS && |
| 1772 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1773 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1774 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1775 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1776 | for (auto *VarRef : Clause->children()) { |
| 1777 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1778 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1779 | } |
| 1780 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1781 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1782 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1783 | // Mark all variables in private list clauses as used in inner region. |
| 1784 | // Required for proper codegen of combined directives. |
| 1785 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1786 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1787 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1788 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1789 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1790 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1791 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1792 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1793 | if (auto *E = C->getPostUpdateExpr()) |
| 1794 | MarkDeclarationsReferencedInExpr(E); |
| 1795 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1796 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1797 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1798 | SC = cast<OMPScheduleClause>(Clause); |
| 1799 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1800 | OC = cast<OMPOrderedClause>(Clause); |
| 1801 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1802 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1803 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1804 | bool ErrorFound = false; |
| 1805 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1806 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1807 | // specified. |
| 1808 | if (SC && |
| 1809 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1810 | SC->getSecondScheduleModifier() == |
| 1811 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1812 | OC) { |
| 1813 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1814 | ? SC->getFirstScheduleModifierLoc() |
| 1815 | : SC->getSecondScheduleModifierLoc(), |
| 1816 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1817 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1818 | ErrorFound = true; |
| 1819 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1820 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1821 | for (auto *C : LCs) { |
| 1822 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1823 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1824 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1825 | ErrorFound = true; |
| 1826 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1827 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1828 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1829 | OC->getNumForLoops()) { |
| 1830 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1831 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1832 | ErrorFound = true; |
| 1833 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1834 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1835 | ActOnCapturedRegionError(); |
| 1836 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1837 | } |
| 1838 | return ActOnCapturedRegionEnd(S.get()); |
| 1839 | } |
| 1840 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1841 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1842 | OpenMPDirectiveKind CurrentRegion, |
| 1843 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1844 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1845 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1846 | // Allowed nesting of constructs |
| 1847 | // +------------------+-----------------+------------------------------------+ |
| 1848 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1849 | // +------------------+-----------------+------------------------------------+ |
| 1850 | // | parallel | parallel | * | |
| 1851 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1852 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1853 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1854 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1855 | // | parallel | simd | * | |
| 1856 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1857 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1858 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1859 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1860 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1861 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1862 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1863 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1864 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1865 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1866 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1867 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1868 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1869 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1870 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1871 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1872 | // | parallel | target parallel | * | |
| 1873 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1874 | // | parallel | target enter | * | |
| 1875 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1876 | // | parallel | target exit | * | |
| 1877 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1878 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1879 | // | parallel | cancellation | | |
| 1880 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1881 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1882 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1883 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1884 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1885 | // +------------------+-----------------+------------------------------------+ |
| 1886 | // | for | parallel | * | |
| 1887 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1888 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1889 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1890 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1891 | // | for | simd | * | |
| 1892 | // | for | sections | + | |
| 1893 | // | for | section | + | |
| 1894 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1895 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1896 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1897 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1898 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1899 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1900 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1901 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1902 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1903 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1904 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1905 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1906 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1907 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1908 | // | for | target parallel | * | |
| 1909 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1910 | // | for | target enter | * | |
| 1911 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1912 | // | for | target exit | * | |
| 1913 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1914 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1915 | // | for | cancellation | | |
| 1916 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1917 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1918 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1919 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1920 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1921 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1922 | // | master | parallel | * | |
| 1923 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1924 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1925 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1926 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1927 | // | master | simd | * | |
| 1928 | // | master | sections | + | |
| 1929 | // | master | section | + | |
| 1930 | // | master | single | + | |
| 1931 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1932 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1933 | // | master |parallel sections| * | |
| 1934 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1935 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1936 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1937 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1938 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1939 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1940 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1941 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1942 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1943 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1944 | // | master | target parallel | * | |
| 1945 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1946 | // | master | target enter | * | |
| 1947 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1948 | // | master | target exit | * | |
| 1949 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1950 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1951 | // | master | cancellation | | |
| 1952 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1953 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1954 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1955 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1956 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1957 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1958 | // | critical | parallel | * | |
| 1959 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1960 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1961 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1962 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1963 | // | critical | simd | * | |
| 1964 | // | critical | sections | + | |
| 1965 | // | critical | section | + | |
| 1966 | // | critical | single | + | |
| 1967 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1968 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1969 | // | critical |parallel sections| * | |
| 1970 | // | critical | task | * | |
| 1971 | // | critical | taskyield | * | |
| 1972 | // | critical | barrier | + | |
| 1973 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1974 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1975 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1976 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1977 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1978 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1979 | // | critical | target parallel | * | |
| 1980 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1981 | // | critical | target enter | * | |
| 1982 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1983 | // | critical | target exit | * | |
| 1984 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1985 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1986 | // | critical | cancellation | | |
| 1987 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1988 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1989 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1990 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1991 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1992 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1993 | // | simd | parallel | | |
| 1994 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1995 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1996 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1997 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 1998 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1999 | // | simd | sections | | |
| 2000 | // | simd | section | | |
| 2001 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2002 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2003 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2004 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2005 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2006 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2007 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2008 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2009 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2010 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2011 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2012 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2013 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2014 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2015 | // | simd | target parallel | | |
| 2016 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2017 | // | simd | target enter | | |
| 2018 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2019 | // | simd | target exit | | |
| 2020 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2021 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2022 | // | simd | cancellation | | |
| 2023 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2024 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2025 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2026 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2027 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2028 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2029 | // | for simd | parallel | | |
| 2030 | // | for simd | for | | |
| 2031 | // | for simd | for simd | | |
| 2032 | // | for simd | master | | |
| 2033 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2034 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2035 | // | for simd | sections | | |
| 2036 | // | for simd | section | | |
| 2037 | // | for simd | single | | |
| 2038 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2039 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2040 | // | for simd |parallel sections| | |
| 2041 | // | for simd | task | | |
| 2042 | // | for simd | taskyield | | |
| 2043 | // | for simd | barrier | | |
| 2044 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2045 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2046 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2047 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2048 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2049 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2050 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2051 | // | for simd | target parallel | | |
| 2052 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2053 | // | for simd | target enter | | |
| 2054 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2055 | // | for simd | target exit | | |
| 2056 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2057 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2058 | // | for simd | cancellation | | |
| 2059 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2060 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2061 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2062 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2063 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2064 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2065 | // | parallel for simd| parallel | | |
| 2066 | // | parallel for simd| for | | |
| 2067 | // | parallel for simd| for simd | | |
| 2068 | // | parallel for simd| master | | |
| 2069 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2070 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2071 | // | parallel for simd| sections | | |
| 2072 | // | parallel for simd| section | | |
| 2073 | // | parallel for simd| single | | |
| 2074 | // | parallel for simd| parallel for | | |
| 2075 | // | parallel for simd|parallel for simd| | |
| 2076 | // | parallel for simd|parallel sections| | |
| 2077 | // | parallel for simd| task | | |
| 2078 | // | parallel for simd| taskyield | | |
| 2079 | // | parallel for simd| barrier | | |
| 2080 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2081 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2082 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2083 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2084 | // | parallel for simd| atomic | | |
| 2085 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2086 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2087 | // | parallel for simd| target parallel | | |
| 2088 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2089 | // | parallel for simd| target enter | | |
| 2090 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2091 | // | parallel for simd| target exit | | |
| 2092 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2093 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2094 | // | parallel for simd| cancellation | | |
| 2095 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2096 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2097 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2098 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2099 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2100 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2101 | // | sections | parallel | * | |
| 2102 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2103 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2104 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2105 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2106 | // | sections | simd | * | |
| 2107 | // | sections | sections | + | |
| 2108 | // | sections | section | * | |
| 2109 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2110 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2111 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2112 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2113 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2114 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2115 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2116 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2117 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2118 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2119 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2120 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2121 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2122 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2123 | // | sections | target parallel | * | |
| 2124 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2125 | // | sections | target enter | * | |
| 2126 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2127 | // | sections | target exit | * | |
| 2128 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2129 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2130 | // | sections | cancellation | | |
| 2131 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2132 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2133 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2134 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2135 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2136 | // +------------------+-----------------+------------------------------------+ |
| 2137 | // | section | parallel | * | |
| 2138 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2139 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2140 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2141 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2142 | // | section | simd | * | |
| 2143 | // | section | sections | + | |
| 2144 | // | section | section | + | |
| 2145 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2146 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2147 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2148 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2149 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2150 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2151 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2152 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2153 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2154 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2155 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2156 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2157 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2158 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2159 | // | section | target parallel | * | |
| 2160 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2161 | // | section | target enter | * | |
| 2162 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2163 | // | section | target exit | * | |
| 2164 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2165 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2166 | // | section | cancellation | | |
| 2167 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2168 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2169 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2170 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2171 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2172 | // +------------------+-----------------+------------------------------------+ |
| 2173 | // | single | parallel | * | |
| 2174 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2175 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2176 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2177 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2178 | // | single | simd | * | |
| 2179 | // | single | sections | + | |
| 2180 | // | single | section | + | |
| 2181 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2182 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2183 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2184 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2185 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2186 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2187 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2188 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2189 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2190 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2191 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2192 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2193 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2194 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2195 | // | single | target parallel | * | |
| 2196 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2197 | // | single | target enter | * | |
| 2198 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2199 | // | single | target exit | * | |
| 2200 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2201 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2202 | // | single | cancellation | | |
| 2203 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2204 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2205 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2206 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2207 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2208 | // +------------------+-----------------+------------------------------------+ |
| 2209 | // | parallel for | parallel | * | |
| 2210 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2211 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2212 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2213 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2214 | // | parallel for | simd | * | |
| 2215 | // | parallel for | sections | + | |
| 2216 | // | parallel for | section | + | |
| 2217 | // | parallel for | single | + | |
| 2218 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2219 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2220 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2221 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2222 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2223 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2224 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2225 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2226 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2227 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2228 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2229 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2230 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2231 | // | parallel for | target parallel | * | |
| 2232 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2233 | // | parallel for | target enter | * | |
| 2234 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2235 | // | parallel for | target exit | * | |
| 2236 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2237 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2238 | // | parallel for | cancellation | | |
| 2239 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2240 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2241 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2242 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2243 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2244 | // +------------------+-----------------+------------------------------------+ |
| 2245 | // | parallel sections| parallel | * | |
| 2246 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2247 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2248 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2249 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2250 | // | parallel sections| simd | * | |
| 2251 | // | parallel sections| sections | + | |
| 2252 | // | parallel sections| section | * | |
| 2253 | // | parallel sections| single | + | |
| 2254 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2255 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2256 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2257 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2258 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2259 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2260 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2261 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2262 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2263 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2264 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2265 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2266 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2267 | // | parallel sections| target parallel | * | |
| 2268 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2269 | // | parallel sections| target enter | * | |
| 2270 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2271 | // | parallel sections| target exit | * | |
| 2272 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2273 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2274 | // | parallel sections| cancellation | | |
| 2275 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2276 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2277 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2278 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2279 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2280 | // +------------------+-----------------+------------------------------------+ |
| 2281 | // | task | parallel | * | |
| 2282 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2283 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2284 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2285 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2286 | // | task | simd | * | |
| 2287 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2288 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2289 | // | task | single | + | |
| 2290 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2291 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2292 | // | task |parallel sections| * | |
| 2293 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2294 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2295 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2296 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2297 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2298 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2299 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2300 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2301 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2302 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2303 | // | task | target parallel | * | |
| 2304 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2305 | // | task | target enter | * | |
| 2306 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2307 | // | task | target exit | * | |
| 2308 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2309 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2310 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2311 | // | | point | ! | |
| 2312 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2313 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2314 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2315 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2316 | // +------------------+-----------------+------------------------------------+ |
| 2317 | // | ordered | parallel | * | |
| 2318 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2319 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2320 | // | ordered | master | * | |
| 2321 | // | ordered | critical | * | |
| 2322 | // | ordered | simd | * | |
| 2323 | // | ordered | sections | + | |
| 2324 | // | ordered | section | + | |
| 2325 | // | ordered | single | + | |
| 2326 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2327 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2328 | // | ordered |parallel sections| * | |
| 2329 | // | ordered | task | * | |
| 2330 | // | ordered | taskyield | * | |
| 2331 | // | ordered | barrier | + | |
| 2332 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2333 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2334 | // | ordered | flush | * | |
| 2335 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2336 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2337 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2338 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2339 | // | ordered | target parallel | * | |
| 2340 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2341 | // | ordered | target enter | * | |
| 2342 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2343 | // | ordered | target exit | * | |
| 2344 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2345 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2346 | // | ordered | cancellation | | |
| 2347 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2348 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2349 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2350 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2351 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2352 | // +------------------+-----------------+------------------------------------+ |
| 2353 | // | atomic | parallel | | |
| 2354 | // | atomic | for | | |
| 2355 | // | atomic | for simd | | |
| 2356 | // | atomic | master | | |
| 2357 | // | atomic | critical | | |
| 2358 | // | atomic | simd | | |
| 2359 | // | atomic | sections | | |
| 2360 | // | atomic | section | | |
| 2361 | // | atomic | single | | |
| 2362 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2363 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2364 | // | atomic |parallel sections| | |
| 2365 | // | atomic | task | | |
| 2366 | // | atomic | taskyield | | |
| 2367 | // | atomic | barrier | | |
| 2368 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2369 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2370 | // | atomic | flush | | |
| 2371 | // | atomic | ordered | | |
| 2372 | // | atomic | atomic | | |
| 2373 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2374 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2375 | // | atomic | target parallel | | |
| 2376 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2377 | // | atomic | target enter | | |
| 2378 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2379 | // | atomic | target exit | | |
| 2380 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2381 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2382 | // | atomic | cancellation | | |
| 2383 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2384 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2385 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2386 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2387 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2388 | // +------------------+-----------------+------------------------------------+ |
| 2389 | // | target | parallel | * | |
| 2390 | // | target | for | * | |
| 2391 | // | target | for simd | * | |
| 2392 | // | target | master | * | |
| 2393 | // | target | critical | * | |
| 2394 | // | target | simd | * | |
| 2395 | // | target | sections | * | |
| 2396 | // | target | section | * | |
| 2397 | // | target | single | * | |
| 2398 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2399 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2400 | // | target |parallel sections| * | |
| 2401 | // | target | task | * | |
| 2402 | // | target | taskyield | * | |
| 2403 | // | target | barrier | * | |
| 2404 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2405 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2406 | // | target | flush | * | |
| 2407 | // | target | ordered | * | |
| 2408 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2409 | // | target | target | | |
| 2410 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2411 | // | target | target parallel | | |
| 2412 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2413 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2414 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2415 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2416 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2417 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2418 | // | target | cancellation | | |
| 2419 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2420 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2421 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2422 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2423 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2424 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2425 | // | target parallel | parallel | * | |
| 2426 | // | target parallel | for | * | |
| 2427 | // | target parallel | for simd | * | |
| 2428 | // | target parallel | master | * | |
| 2429 | // | target parallel | critical | * | |
| 2430 | // | target parallel | simd | * | |
| 2431 | // | target parallel | sections | * | |
| 2432 | // | target parallel | section | * | |
| 2433 | // | target parallel | single | * | |
| 2434 | // | target parallel | parallel for | * | |
| 2435 | // | target parallel |parallel for simd| * | |
| 2436 | // | target parallel |parallel sections| * | |
| 2437 | // | target parallel | task | * | |
| 2438 | // | target parallel | taskyield | * | |
| 2439 | // | target parallel | barrier | * | |
| 2440 | // | target parallel | taskwait | * | |
| 2441 | // | target parallel | taskgroup | * | |
| 2442 | // | target parallel | flush | * | |
| 2443 | // | target parallel | ordered | * | |
| 2444 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2445 | // | target parallel | target | | |
| 2446 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2447 | // | target parallel | target parallel | | |
| 2448 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2449 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2450 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2451 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2452 | // | | data | | |
| 2453 | // | target parallel | teams | | |
| 2454 | // | target parallel | cancellation | | |
| 2455 | // | | point | ! | |
| 2456 | // | target parallel | cancel | ! | |
| 2457 | // | target parallel | taskloop | * | |
| 2458 | // | target parallel | taskloop simd | * | |
| 2459 | // | target parallel | distribute | | |
| 2460 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2461 | // | target parallel | parallel | * | |
| 2462 | // | for | | | |
| 2463 | // | target parallel | for | * | |
| 2464 | // | for | | | |
| 2465 | // | target parallel | for simd | * | |
| 2466 | // | for | | | |
| 2467 | // | target parallel | master | * | |
| 2468 | // | for | | | |
| 2469 | // | target parallel | critical | * | |
| 2470 | // | for | | | |
| 2471 | // | target parallel | simd | * | |
| 2472 | // | for | | | |
| 2473 | // | target parallel | sections | * | |
| 2474 | // | for | | | |
| 2475 | // | target parallel | section | * | |
| 2476 | // | for | | | |
| 2477 | // | target parallel | single | * | |
| 2478 | // | for | | | |
| 2479 | // | target parallel | parallel for | * | |
| 2480 | // | for | | | |
| 2481 | // | target parallel |parallel for simd| * | |
| 2482 | // | for | | | |
| 2483 | // | target parallel |parallel sections| * | |
| 2484 | // | for | | | |
| 2485 | // | target parallel | task | * | |
| 2486 | // | for | | | |
| 2487 | // | target parallel | taskyield | * | |
| 2488 | // | for | | | |
| 2489 | // | target parallel | barrier | * | |
| 2490 | // | for | | | |
| 2491 | // | target parallel | taskwait | * | |
| 2492 | // | for | | | |
| 2493 | // | target parallel | taskgroup | * | |
| 2494 | // | for | | | |
| 2495 | // | target parallel | flush | * | |
| 2496 | // | for | | | |
| 2497 | // | target parallel | ordered | * | |
| 2498 | // | for | | | |
| 2499 | // | target parallel | atomic | * | |
| 2500 | // | for | | | |
| 2501 | // | target parallel | target | | |
| 2502 | // | for | | | |
| 2503 | // | target parallel | target parallel | | |
| 2504 | // | for | | | |
| 2505 | // | target parallel | target parallel | | |
| 2506 | // | for | for | | |
| 2507 | // | target parallel | target enter | | |
| 2508 | // | for | data | | |
| 2509 | // | target parallel | target exit | | |
| 2510 | // | for | data | | |
| 2511 | // | target parallel | teams | | |
| 2512 | // | for | | | |
| 2513 | // | target parallel | cancellation | | |
| 2514 | // | for | point | ! | |
| 2515 | // | target parallel | cancel | ! | |
| 2516 | // | for | | | |
| 2517 | // | target parallel | taskloop | * | |
| 2518 | // | for | | | |
| 2519 | // | target parallel | taskloop simd | * | |
| 2520 | // | for | | | |
| 2521 | // | target parallel | distribute | | |
| 2522 | // | for | | | |
| 2523 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2524 | // | teams | parallel | * | |
| 2525 | // | teams | for | + | |
| 2526 | // | teams | for simd | + | |
| 2527 | // | teams | master | + | |
| 2528 | // | teams | critical | + | |
| 2529 | // | teams | simd | + | |
| 2530 | // | teams | sections | + | |
| 2531 | // | teams | section | + | |
| 2532 | // | teams | single | + | |
| 2533 | // | teams | parallel for | * | |
| 2534 | // | teams |parallel for simd| * | |
| 2535 | // | teams |parallel sections| * | |
| 2536 | // | teams | task | + | |
| 2537 | // | teams | taskyield | + | |
| 2538 | // | teams | barrier | + | |
| 2539 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2540 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2541 | // | teams | flush | + | |
| 2542 | // | teams | ordered | + | |
| 2543 | // | teams | atomic | + | |
| 2544 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2545 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2546 | // | teams | target parallel | + | |
| 2547 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2548 | // | teams | target enter | + | |
| 2549 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2550 | // | teams | target exit | + | |
| 2551 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2552 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2553 | // | teams | cancellation | | |
| 2554 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2555 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2556 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2557 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2558 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2559 | // +------------------+-----------------+------------------------------------+ |
| 2560 | // | taskloop | parallel | * | |
| 2561 | // | taskloop | for | + | |
| 2562 | // | taskloop | for simd | + | |
| 2563 | // | taskloop | master | + | |
| 2564 | // | taskloop | critical | * | |
| 2565 | // | taskloop | simd | * | |
| 2566 | // | taskloop | sections | + | |
| 2567 | // | taskloop | section | + | |
| 2568 | // | taskloop | single | + | |
| 2569 | // | taskloop | parallel for | * | |
| 2570 | // | taskloop |parallel for simd| * | |
| 2571 | // | taskloop |parallel sections| * | |
| 2572 | // | taskloop | task | * | |
| 2573 | // | taskloop | taskyield | * | |
| 2574 | // | taskloop | barrier | + | |
| 2575 | // | taskloop | taskwait | * | |
| 2576 | // | taskloop | taskgroup | * | |
| 2577 | // | taskloop | flush | * | |
| 2578 | // | taskloop | ordered | + | |
| 2579 | // | taskloop | atomic | * | |
| 2580 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2581 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2582 | // | taskloop | target parallel | * | |
| 2583 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2584 | // | taskloop | target enter | * | |
| 2585 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2586 | // | taskloop | target exit | * | |
| 2587 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2588 | // | taskloop | teams | + | |
| 2589 | // | taskloop | cancellation | | |
| 2590 | // | | point | | |
| 2591 | // | taskloop | cancel | | |
| 2592 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2593 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2594 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2595 | // | taskloop simd | parallel | | |
| 2596 | // | taskloop simd | for | | |
| 2597 | // | taskloop simd | for simd | | |
| 2598 | // | taskloop simd | master | | |
| 2599 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2600 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2601 | // | taskloop simd | sections | | |
| 2602 | // | taskloop simd | section | | |
| 2603 | // | taskloop simd | single | | |
| 2604 | // | taskloop simd | parallel for | | |
| 2605 | // | taskloop simd |parallel for simd| | |
| 2606 | // | taskloop simd |parallel sections| | |
| 2607 | // | taskloop simd | task | | |
| 2608 | // | taskloop simd | taskyield | | |
| 2609 | // | taskloop simd | barrier | | |
| 2610 | // | taskloop simd | taskwait | | |
| 2611 | // | taskloop simd | taskgroup | | |
| 2612 | // | taskloop simd | flush | | |
| 2613 | // | taskloop simd | ordered | + (with simd clause) | |
| 2614 | // | taskloop simd | atomic | | |
| 2615 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2616 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2617 | // | taskloop simd | target parallel | | |
| 2618 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2619 | // | taskloop simd | target enter | | |
| 2620 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2621 | // | taskloop simd | target exit | | |
| 2622 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2623 | // | taskloop simd | teams | | |
| 2624 | // | taskloop simd | cancellation | | |
| 2625 | // | | point | | |
| 2626 | // | taskloop simd | cancel | | |
| 2627 | // | taskloop simd | taskloop | | |
| 2628 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2629 | // | taskloop simd | distribute | | |
| 2630 | // +------------------+-----------------+------------------------------------+ |
| 2631 | // | distribute | parallel | * | |
| 2632 | // | distribute | for | * | |
| 2633 | // | distribute | for simd | * | |
| 2634 | // | distribute | master | * | |
| 2635 | // | distribute | critical | * | |
| 2636 | // | distribute | simd | * | |
| 2637 | // | distribute | sections | * | |
| 2638 | // | distribute | section | * | |
| 2639 | // | distribute | single | * | |
| 2640 | // | distribute | parallel for | * | |
| 2641 | // | distribute |parallel for simd| * | |
| 2642 | // | distribute |parallel sections| * | |
| 2643 | // | distribute | task | * | |
| 2644 | // | distribute | taskyield | * | |
| 2645 | // | distribute | barrier | * | |
| 2646 | // | distribute | taskwait | * | |
| 2647 | // | distribute | taskgroup | * | |
| 2648 | // | distribute | flush | * | |
| 2649 | // | distribute | ordered | + | |
| 2650 | // | distribute | atomic | * | |
| 2651 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2652 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2653 | // | distribute | target parallel | | |
| 2654 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2655 | // | distribute | target enter | | |
| 2656 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2657 | // | distribute | target exit | | |
| 2658 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2659 | // | distribute | teams | | |
| 2660 | // | distribute | cancellation | + | |
| 2661 | // | | point | | |
| 2662 | // | distribute | cancel | + | |
| 2663 | // | distribute | taskloop | * | |
| 2664 | // | distribute | taskloop simd | * | |
| 2665 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2666 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2667 | if (Stack->getCurScope()) { |
| 2668 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2669 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2670 | bool NestingProhibited = false; |
| 2671 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2672 | enum { |
| 2673 | NoRecommend, |
| 2674 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2675 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2676 | ShouldBeInTargetRegion, |
| 2677 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2678 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2679 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2680 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2681 | // OpenMP [2.16, Nesting of Regions] |
| 2682 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2683 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2684 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2685 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2686 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2687 | return true; |
| 2688 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2689 | if (ParentRegion == OMPD_atomic) { |
| 2690 | // OpenMP [2.16, Nesting of Regions] |
| 2691 | // OpenMP constructs may not be nested inside an atomic region. |
| 2692 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2693 | return true; |
| 2694 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2695 | if (CurrentRegion == OMPD_section) { |
| 2696 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2697 | // Orphaned section directives are prohibited. That is, the section |
| 2698 | // directives must appear within the sections construct and must not be |
| 2699 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2700 | if (ParentRegion != OMPD_sections && |
| 2701 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2702 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2703 | << (ParentRegion != OMPD_unknown) |
| 2704 | << getOpenMPDirectiveName(ParentRegion); |
| 2705 | return true; |
| 2706 | } |
| 2707 | return false; |
| 2708 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2709 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2710 | // called from OpenMP regions with the required preconditions). |
| 2711 | if (ParentRegion == OMPD_unknown) |
| 2712 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2713 | if (CurrentRegion == OMPD_cancellation_point || |
| 2714 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2715 | // OpenMP [2.16, Nesting of Regions] |
| 2716 | // A cancellation point construct for which construct-type-clause is |
| 2717 | // taskgroup must be nested inside a task construct. A cancellation |
| 2718 | // point construct for which construct-type-clause is not taskgroup must |
| 2719 | // be closely nested inside an OpenMP construct that matches the type |
| 2720 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2721 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2722 | // nested inside a task construct. A cancel construct for which |
| 2723 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2724 | // OpenMP construct that matches the type specified in |
| 2725 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2726 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2727 | !((CancelRegion == OMPD_parallel && |
| 2728 | (ParentRegion == OMPD_parallel || |
| 2729 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2730 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2731 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2732 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2733 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2734 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2735 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2736 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2737 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2738 | // OpenMP [2.16, Nesting of Regions] |
| 2739 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2740 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2741 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2742 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2743 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2744 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2745 | // OpenMP [2.16, Nesting of Regions] |
| 2746 | // A critical region may not be nested (closely or otherwise) inside a |
| 2747 | // critical region with the same name. Note that this restriction is not |
| 2748 | // sufficient to prevent deadlock. |
| 2749 | SourceLocation PreviousCriticalLoc; |
| 2750 | bool DeadLock = |
| 2751 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2752 | OpenMPDirectiveKind K, |
| 2753 | const DeclarationNameInfo &DNI, |
| 2754 | SourceLocation Loc) |
| 2755 | ->bool { |
| 2756 | if (K == OMPD_critical && |
| 2757 | DNI.getName() == CurrentName.getName()) { |
| 2758 | PreviousCriticalLoc = Loc; |
| 2759 | return true; |
| 2760 | } else |
| 2761 | return false; |
| 2762 | }, |
| 2763 | false /* skip top directive */); |
| 2764 | if (DeadLock) { |
| 2765 | SemaRef.Diag(StartLoc, |
| 2766 | diag::err_omp_prohibited_region_critical_same_name) |
| 2767 | << CurrentName.getName(); |
| 2768 | if (PreviousCriticalLoc.isValid()) |
| 2769 | SemaRef.Diag(PreviousCriticalLoc, |
| 2770 | diag::note_omp_previous_critical_region); |
| 2771 | return true; |
| 2772 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2773 | } else if (CurrentRegion == OMPD_barrier) { |
| 2774 | // OpenMP [2.16, Nesting of Regions] |
| 2775 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2776 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2777 | NestingProhibited = |
| 2778 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2779 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2780 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2781 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2782 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2783 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2784 | // OpenMP [2.16, Nesting of Regions] |
| 2785 | // A worksharing region may not be closely nested inside a worksharing, |
| 2786 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2787 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2788 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2789 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2790 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2791 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2792 | Recommend = ShouldBeInParallelRegion; |
| 2793 | } else if (CurrentRegion == OMPD_ordered) { |
| 2794 | // OpenMP [2.16, Nesting of Regions] |
| 2795 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2796 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2797 | // An ordered region must be closely nested inside a loop region (or |
| 2798 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2799 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2800 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2801 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2802 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2803 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2804 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2805 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2806 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2807 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2808 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2809 | // OpenMP [2.16, Nesting of Regions] |
| 2810 | // If specified, a teams construct must be contained within a target |
| 2811 | // construct. |
| 2812 | NestingProhibited = ParentRegion != OMPD_target; |
| 2813 | Recommend = ShouldBeInTargetRegion; |
| 2814 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2815 | } |
| 2816 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2817 | // OpenMP [2.16, Nesting of Regions] |
| 2818 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2819 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2820 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2821 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2822 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2823 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2824 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2825 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2826 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2827 | // The region associated with the distribute construct must be strictly |
| 2828 | // nested inside a teams region |
| 2829 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2830 | Recommend = ShouldBeInTeamsRegion; |
| 2831 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2832 | if (!NestingProhibited && |
| 2833 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2834 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2835 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2836 | // If a target, target update, target data, target enter data, or |
| 2837 | // target exit data construct is encountered during execution of a |
| 2838 | // target region, the behavior is unspecified. |
| 2839 | NestingProhibited = Stack->hasDirective( |
| 2840 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2841 | const DeclarationNameInfo &DNI, |
| 2842 | SourceLocation Loc) -> bool { |
| 2843 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2844 | OffendingRegion = K; |
| 2845 | return true; |
| 2846 | } else |
| 2847 | return false; |
| 2848 | }, |
| 2849 | false /* don't skip top directive */); |
| 2850 | CloseNesting = false; |
| 2851 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2852 | if (NestingProhibited) { |
| 2853 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2854 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2855 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2856 | return true; |
| 2857 | } |
| 2858 | } |
| 2859 | return false; |
| 2860 | } |
| 2861 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2862 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2863 | ArrayRef<OMPClause *> Clauses, |
| 2864 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2865 | bool ErrorFound = false; |
| 2866 | unsigned NamedModifiersNumber = 0; |
| 2867 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2868 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2869 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2870 | for (const auto *C : Clauses) { |
| 2871 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2872 | // At most one if clause without a directive-name-modifier can appear on |
| 2873 | // the directive. |
| 2874 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2875 | if (FoundNameModifiers[CurNM]) { |
| 2876 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2877 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2878 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2879 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2880 | } else if (CurNM != OMPD_unknown) { |
| 2881 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2882 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2883 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2884 | FoundNameModifiers[CurNM] = IC; |
| 2885 | if (CurNM == OMPD_unknown) |
| 2886 | continue; |
| 2887 | // Check if the specified name modifier is allowed for the current |
| 2888 | // directive. |
| 2889 | // At most one if clause with the particular directive-name-modifier can |
| 2890 | // appear on the directive. |
| 2891 | bool MatchFound = false; |
| 2892 | for (auto NM : AllowedNameModifiers) { |
| 2893 | if (CurNM == NM) { |
| 2894 | MatchFound = true; |
| 2895 | break; |
| 2896 | } |
| 2897 | } |
| 2898 | if (!MatchFound) { |
| 2899 | S.Diag(IC->getNameModifierLoc(), |
| 2900 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2901 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2902 | ErrorFound = true; |
| 2903 | } |
| 2904 | } |
| 2905 | } |
| 2906 | // If any if clause on the directive includes a directive-name-modifier then |
| 2907 | // all if clauses on the directive must include a directive-name-modifier. |
| 2908 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2909 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2910 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2911 | diag::err_omp_no_more_if_clause); |
| 2912 | } else { |
| 2913 | std::string Values; |
| 2914 | std::string Sep(", "); |
| 2915 | unsigned AllowedCnt = 0; |
| 2916 | unsigned TotalAllowedNum = |
| 2917 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2918 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2919 | ++Cnt) { |
| 2920 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2921 | if (!FoundNameModifiers[NM]) { |
| 2922 | Values += "'"; |
| 2923 | Values += getOpenMPDirectiveName(NM); |
| 2924 | Values += "'"; |
| 2925 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2926 | Values += " or "; |
| 2927 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2928 | Values += Sep; |
| 2929 | ++AllowedCnt; |
| 2930 | } |
| 2931 | } |
| 2932 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2933 | diag::err_omp_unnamed_if_clause) |
| 2934 | << (TotalAllowedNum > 1) << Values; |
| 2935 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2936 | for (auto Loc : NameModifierLoc) { |
| 2937 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2938 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2939 | ErrorFound = true; |
| 2940 | } |
| 2941 | return ErrorFound; |
| 2942 | } |
| 2943 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2944 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2945 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2946 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2947 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2948 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2949 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2950 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2951 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2952 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2953 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2954 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2955 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2956 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2957 | if (AStmt) { |
| 2958 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2959 | |
| 2960 | // Check default data sharing attributes for referenced variables. |
| 2961 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2962 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2963 | if (DSAChecker.isErrorFound()) |
| 2964 | return StmtError(); |
| 2965 | // Generate list of implicitly defined firstprivate variables. |
| 2966 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2967 | |
| 2968 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2969 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2970 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2971 | SourceLocation(), SourceLocation())) { |
| 2972 | ClausesWithImplicit.push_back(Implicit); |
| 2973 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2974 | DSAChecker.getImplicitFirstprivate().size(); |
| 2975 | } else |
| 2976 | ErrorFound = true; |
| 2977 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2978 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2979 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2980 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2981 | switch (Kind) { |
| 2982 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2983 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2984 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2985 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2986 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2987 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2988 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2989 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2990 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2991 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2992 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2993 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2994 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2995 | case OMPD_for_simd: |
| 2996 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2997 | EndLoc, VarsWithInheritedDSA); |
| 2998 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2999 | case OMPD_sections: |
| 3000 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3001 | EndLoc); |
| 3002 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3003 | case OMPD_section: |
| 3004 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3005 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3006 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3007 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3008 | case OMPD_single: |
| 3009 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3010 | EndLoc); |
| 3011 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3012 | case OMPD_master: |
| 3013 | assert(ClausesWithImplicit.empty() && |
| 3014 | "No clauses are allowed for 'omp master' directive"); |
| 3015 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3016 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3017 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3018 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3019 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3020 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3021 | case OMPD_parallel_for: |
| 3022 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3023 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3024 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3025 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3026 | case OMPD_parallel_for_simd: |
| 3027 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3028 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3029 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3030 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3031 | case OMPD_parallel_sections: |
| 3032 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3033 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3034 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3035 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3036 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3037 | Res = |
| 3038 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3039 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3040 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3041 | case OMPD_taskyield: |
| 3042 | assert(ClausesWithImplicit.empty() && |
| 3043 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3044 | assert(AStmt == nullptr && |
| 3045 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3046 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3047 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3048 | case OMPD_barrier: |
| 3049 | assert(ClausesWithImplicit.empty() && |
| 3050 | "No clauses are allowed for 'omp barrier' directive"); |
| 3051 | assert(AStmt == nullptr && |
| 3052 | "No associated statement allowed for 'omp barrier' directive"); |
| 3053 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3054 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3055 | case OMPD_taskwait: |
| 3056 | assert(ClausesWithImplicit.empty() && |
| 3057 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3058 | assert(AStmt == nullptr && |
| 3059 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3060 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3061 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3062 | case OMPD_taskgroup: |
| 3063 | assert(ClausesWithImplicit.empty() && |
| 3064 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3065 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3066 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3067 | case OMPD_flush: |
| 3068 | assert(AStmt == nullptr && |
| 3069 | "No associated statement allowed for 'omp flush' directive"); |
| 3070 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3071 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3072 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3073 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3074 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3075 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3076 | case OMPD_atomic: |
| 3077 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3078 | EndLoc); |
| 3079 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3080 | case OMPD_teams: |
| 3081 | Res = |
| 3082 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3083 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3084 | case OMPD_target: |
| 3085 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3086 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3087 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3088 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3089 | case OMPD_target_parallel: |
| 3090 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3091 | StartLoc, EndLoc); |
| 3092 | AllowedNameModifiers.push_back(OMPD_target); |
| 3093 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3094 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3095 | case OMPD_target_parallel_for: |
| 3096 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3097 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3098 | AllowedNameModifiers.push_back(OMPD_target); |
| 3099 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3100 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3101 | case OMPD_cancellation_point: |
| 3102 | assert(ClausesWithImplicit.empty() && |
| 3103 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3104 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3105 | "cancellation point' directive"); |
| 3106 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3107 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3108 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3109 | assert(AStmt == nullptr && |
| 3110 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3111 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3112 | CancelRegion); |
| 3113 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3114 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3115 | case OMPD_target_data: |
| 3116 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3117 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3118 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3119 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3120 | case OMPD_target_enter_data: |
| 3121 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3122 | EndLoc); |
| 3123 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3124 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3125 | case OMPD_target_exit_data: |
| 3126 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3127 | EndLoc); |
| 3128 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3129 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3130 | case OMPD_taskloop: |
| 3131 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3132 | EndLoc, VarsWithInheritedDSA); |
| 3133 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3134 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3135 | case OMPD_taskloop_simd: |
| 3136 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3137 | EndLoc, VarsWithInheritedDSA); |
| 3138 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3139 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3140 | case OMPD_distribute: |
| 3141 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3142 | EndLoc, VarsWithInheritedDSA); |
| 3143 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3144 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3145 | case OMPD_declare_reduction: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3146 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3147 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3148 | llvm_unreachable("Unknown OpenMP directive"); |
| 3149 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3150 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3151 | for (auto P : VarsWithInheritedDSA) { |
| 3152 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3153 | << P.first << P.second->getSourceRange(); |
| 3154 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3155 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3156 | |
| 3157 | if (!AllowedNameModifiers.empty()) |
| 3158 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3159 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3160 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3161 | if (ErrorFound) |
| 3162 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3163 | return Res; |
| 3164 | } |
| 3165 | |
| 3166 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3167 | Stmt *AStmt, |
| 3168 | SourceLocation StartLoc, |
| 3169 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3170 | if (!AStmt) |
| 3171 | return StmtError(); |
| 3172 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3173 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3174 | // 1.2.2 OpenMP Language Terminology |
| 3175 | // Structured block - An executable statement with a single entry at the |
| 3176 | // top and a single exit at the bottom. |
| 3177 | // The point of exit cannot be a branch out of the structured block. |
| 3178 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3179 | CS->getCapturedDecl()->setNothrow(); |
| 3180 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3181 | getCurFunction()->setHasBranchProtectedScope(); |
| 3182 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3183 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3184 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3187 | namespace { |
| 3188 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3189 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3190 | /// for IR generation. |
| 3191 | class OpenMPIterationSpaceChecker { |
| 3192 | /// \brief Reference to Sema. |
| 3193 | Sema &SemaRef; |
| 3194 | /// \brief A location for diagnostics (when there is no some better location). |
| 3195 | SourceLocation DefaultLoc; |
| 3196 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3197 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3198 | /// \brief A source location for referring to loop init later. |
| 3199 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3200 | /// \brief A source location for referring to condition later. |
| 3201 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3202 | /// \brief A source location for referring to increment later. |
| 3203 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3204 | /// \brief Loop variable. |
| 3205 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3206 | /// \brief Reference to loop variable. |
| 3207 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3208 | /// \brief Lower bound (initializer for the var). |
| 3209 | Expr *LB; |
| 3210 | /// \brief Upper bound. |
| 3211 | Expr *UB; |
| 3212 | /// \brief Loop step (increment). |
| 3213 | Expr *Step; |
| 3214 | /// \brief This flag is true when condition is one of: |
| 3215 | /// Var < UB |
| 3216 | /// Var <= UB |
| 3217 | /// UB > Var |
| 3218 | /// UB >= Var |
| 3219 | bool TestIsLessOp; |
| 3220 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3221 | bool TestIsStrictOp; |
| 3222 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3223 | bool SubtractStep; |
| 3224 | |
| 3225 | public: |
| 3226 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3227 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3228 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3229 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3230 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3231 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3232 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3233 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3234 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3235 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3236 | /// for less/greater and for strict/non-strict comparison. |
| 3237 | bool CheckCond(Expr *S); |
| 3238 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3239 | /// does not conform, otherwise save loop step (#Step). |
| 3240 | bool CheckInc(Expr *S); |
| 3241 | /// \brief Return the loop counter variable. |
| 3242 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3243 | /// \brief Return the reference expression to loop counter variable. |
| 3244 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3245 | /// \brief Source range of the loop init. |
| 3246 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3247 | /// \brief Source range of the loop condition. |
| 3248 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3249 | /// \brief Source range of the loop increment. |
| 3250 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3251 | /// \brief True if the step should be subtracted. |
| 3252 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3253 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3254 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3255 | /// \brief Build the precondition expression for the loops. |
| 3256 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3257 | /// \brief Build reference expression to the counter be used for codegen. |
| 3258 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3259 | /// \brief Build reference expression to the private counter be used for |
| 3260 | /// codegen. |
| 3261 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3262 | /// \brief Build initization of the counter be used for codegen. |
| 3263 | Expr *BuildCounterInit() const; |
| 3264 | /// \brief Build step of the counter be used for codegen. |
| 3265 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3266 | /// \brief Return true if any expression is dependent. |
| 3267 | bool Dependent() const; |
| 3268 | |
| 3269 | private: |
| 3270 | /// \brief Check the right-hand side of an assignment in the increment |
| 3271 | /// expression. |
| 3272 | bool CheckIncRHS(Expr *RHS); |
| 3273 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3274 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3275 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3276 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3277 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3278 | /// \brief Helper to set loop increment. |
| 3279 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3280 | }; |
| 3281 | |
| 3282 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3283 | if (!Var) { |
| 3284 | assert(!LB && !UB && !Step); |
| 3285 | return false; |
| 3286 | } |
| 3287 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3288 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3289 | } |
| 3290 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3291 | template <typename T> |
| 3292 | static T *getExprAsWritten(T *E) { |
| 3293 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3294 | E = ExprTemp->getSubExpr(); |
| 3295 | |
| 3296 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3297 | E = MTE->GetTemporaryExpr(); |
| 3298 | |
| 3299 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3300 | E = Binder->getSubExpr(); |
| 3301 | |
| 3302 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3303 | E = ICE->getSubExprAsWritten(); |
| 3304 | return E->IgnoreParens(); |
| 3305 | } |
| 3306 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3307 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3308 | DeclRefExpr *NewVarRefExpr, |
| 3309 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3310 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3311 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3312 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3313 | if (!NewVar || !NewLB) |
| 3314 | return true; |
| 3315 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3316 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3317 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3318 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3319 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3320 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3321 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3322 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3323 | LB = NewLB; |
| 3324 | return false; |
| 3325 | } |
| 3326 | |
| 3327 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3328 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3329 | // State consistency checking to ensure correct usage. |
| 3330 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3331 | !TestIsLessOp && !TestIsStrictOp); |
| 3332 | if (!NewUB) |
| 3333 | return true; |
| 3334 | UB = NewUB; |
| 3335 | TestIsLessOp = LessOp; |
| 3336 | TestIsStrictOp = StrictOp; |
| 3337 | ConditionSrcRange = SR; |
| 3338 | ConditionLoc = SL; |
| 3339 | return false; |
| 3340 | } |
| 3341 | |
| 3342 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3343 | // State consistency checking to ensure correct usage. |
| 3344 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3345 | if (!NewStep) |
| 3346 | return true; |
| 3347 | if (!NewStep->isValueDependent()) { |
| 3348 | // Check that the step is integer expression. |
| 3349 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3350 | ExprResult Val = |
| 3351 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3352 | if (Val.isInvalid()) |
| 3353 | return true; |
| 3354 | NewStep = Val.get(); |
| 3355 | |
| 3356 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3357 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3358 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3359 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3360 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3361 | // the loop. |
| 3362 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3363 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3364 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3365 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3366 | // the loop. |
| 3367 | llvm::APSInt Result; |
| 3368 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3369 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3370 | bool IsConstNeg = |
| 3371 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3372 | bool IsConstPos = |
| 3373 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3374 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3375 | if (UB && (IsConstZero || |
| 3376 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3377 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3378 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3379 | diag::err_omp_loop_incr_not_compatible) |
| 3380 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3381 | SemaRef.Diag(ConditionLoc, |
| 3382 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3383 | << TestIsLessOp << ConditionSrcRange; |
| 3384 | return true; |
| 3385 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3386 | if (TestIsLessOp == Subtract) { |
| 3387 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3388 | NewStep).get(); |
| 3389 | Subtract = !Subtract; |
| 3390 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | Step = NewStep; |
| 3394 | SubtractStep = Subtract; |
| 3395 | return false; |
| 3396 | } |
| 3397 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3398 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3399 | // Check init-expr for canonical loop form and save loop counter |
| 3400 | // variable - #Var and its initialization value - #LB. |
| 3401 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3402 | // var = lb |
| 3403 | // integer-type var = lb |
| 3404 | // random-access-iterator-type var = lb |
| 3405 | // pointer-type var = lb |
| 3406 | // |
| 3407 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3408 | if (EmitDiags) { |
| 3409 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3410 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3411 | return true; |
| 3412 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3413 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3414 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3415 | S = E->IgnoreParens(); |
| 3416 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3417 | if (BO->getOpcode() == BO_Assign) |
| 3418 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3419 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3420 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3421 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3422 | if (DS->isSingleDecl()) { |
| 3423 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3424 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3425 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3426 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3427 | SemaRef.Diag(S->getLocStart(), |
| 3428 | diag::ext_omp_loop_not_canonical_init) |
| 3429 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3430 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | } |
| 3434 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3435 | if (CE->getOperator() == OO_Equal) |
| 3436 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3437 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3438 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3439 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3440 | if (EmitDiags) { |
| 3441 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3442 | << S->getSourceRange(); |
| 3443 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3444 | return true; |
| 3445 | } |
| 3446 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3447 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3448 | /// variable (which may be the loop variable) if possible. |
| 3449 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3450 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3451 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3452 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3453 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3454 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3455 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3456 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3457 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3458 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3459 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3460 | if (!DRE) |
| 3461 | return nullptr; |
| 3462 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3463 | } |
| 3464 | |
| 3465 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3466 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3467 | // less/greater and for strict/non-strict comparison. |
| 3468 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3469 | // var relational-op b |
| 3470 | // b relational-op var |
| 3471 | // |
| 3472 | if (!S) { |
| 3473 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3474 | return true; |
| 3475 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3476 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3477 | SourceLocation CondLoc = S->getLocStart(); |
| 3478 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3479 | if (BO->isRelationalOp()) { |
| 3480 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3481 | return SetUB(BO->getRHS(), |
| 3482 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3483 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3484 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3485 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3486 | return SetUB(BO->getLHS(), |
| 3487 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3488 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3489 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3490 | } |
| 3491 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3492 | if (CE->getNumArgs() == 2) { |
| 3493 | auto Op = CE->getOperator(); |
| 3494 | switch (Op) { |
| 3495 | case OO_Greater: |
| 3496 | case OO_GreaterEqual: |
| 3497 | case OO_Less: |
| 3498 | case OO_LessEqual: |
| 3499 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3500 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3501 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3502 | CE->getOperatorLoc()); |
| 3503 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3504 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3505 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3506 | CE->getOperatorLoc()); |
| 3507 | break; |
| 3508 | default: |
| 3509 | break; |
| 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3514 | << S->getSourceRange() << Var; |
| 3515 | return true; |
| 3516 | } |
| 3517 | |
| 3518 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3519 | // RHS of canonical loop form increment can be: |
| 3520 | // var + incr |
| 3521 | // incr + var |
| 3522 | // var - incr |
| 3523 | // |
| 3524 | RHS = RHS->IgnoreParenImpCasts(); |
| 3525 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3526 | if (BO->isAdditiveOp()) { |
| 3527 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3528 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3529 | return SetStep(BO->getRHS(), !IsAdd); |
| 3530 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3531 | return SetStep(BO->getLHS(), false); |
| 3532 | } |
| 3533 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3534 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3535 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3536 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3537 | return SetStep(CE->getArg(1), !IsAdd); |
| 3538 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3539 | return SetStep(CE->getArg(0), false); |
| 3540 | } |
| 3541 | } |
| 3542 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3543 | << RHS->getSourceRange() << Var; |
| 3544 | return true; |
| 3545 | } |
| 3546 | |
| 3547 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3548 | // Check incr-expr for canonical loop form and return true if it |
| 3549 | // does not conform. |
| 3550 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3551 | // ++var |
| 3552 | // var++ |
| 3553 | // --var |
| 3554 | // var-- |
| 3555 | // var += incr |
| 3556 | // var -= incr |
| 3557 | // var = var + incr |
| 3558 | // var = incr + var |
| 3559 | // var = var - incr |
| 3560 | // |
| 3561 | if (!S) { |
| 3562 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3563 | return true; |
| 3564 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3565 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3566 | S = S->IgnoreParens(); |
| 3567 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3568 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3569 | return SetStep( |
| 3570 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3571 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3572 | false); |
| 3573 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3574 | switch (BO->getOpcode()) { |
| 3575 | case BO_AddAssign: |
| 3576 | case BO_SubAssign: |
| 3577 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3578 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3579 | break; |
| 3580 | case BO_Assign: |
| 3581 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3582 | return CheckIncRHS(BO->getRHS()); |
| 3583 | break; |
| 3584 | default: |
| 3585 | break; |
| 3586 | } |
| 3587 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3588 | switch (CE->getOperator()) { |
| 3589 | case OO_PlusPlus: |
| 3590 | case OO_MinusMinus: |
| 3591 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3592 | return SetStep( |
| 3593 | SemaRef.ActOnIntegerConstant( |
| 3594 | CE->getLocStart(), |
| 3595 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3596 | false); |
| 3597 | break; |
| 3598 | case OO_PlusEqual: |
| 3599 | case OO_MinusEqual: |
| 3600 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3601 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3602 | break; |
| 3603 | case OO_Equal: |
| 3604 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3605 | return CheckIncRHS(CE->getArg(1)); |
| 3606 | break; |
| 3607 | default: |
| 3608 | break; |
| 3609 | } |
| 3610 | } |
| 3611 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3612 | << S->getSourceRange() << Var; |
| 3613 | return true; |
| 3614 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3615 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3616 | namespace { |
| 3617 | // Transform variables declared in GNU statement expressions to new ones to |
| 3618 | // avoid crash on codegen. |
| 3619 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3620 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3621 | |
| 3622 | public: |
| 3623 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3624 | |
| 3625 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3626 | if (auto *VD = cast<VarDecl>(D)) |
| 3627 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3628 | !isa<ImplicitParamDecl>(D)) { |
| 3629 | auto *NewVD = VarDecl::Create( |
| 3630 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3631 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3632 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3633 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3634 | NewVD->setInit(VD->getInit()); |
| 3635 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3636 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3637 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3638 | NewVD->setCXXForRangeDecl(VD->isCXXForRangeDecl()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3639 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3640 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3641 | NewVD->setPreviousDeclInSameBlockScope( |
| 3642 | VD->isPreviousDeclInSameBlockScope()); |
| 3643 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3644 | if (VD->hasAttrs()) |
| 3645 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3646 | transformedLocalDecl(VD, NewVD); |
| 3647 | return NewVD; |
| 3648 | } |
| 3649 | return BaseTransform::TransformDefinition(Loc, D); |
| 3650 | } |
| 3651 | |
| 3652 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3653 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3654 | if (E->getDecl() != NewD) { |
| 3655 | NewD->setReferenced(); |
| 3656 | NewD->markUsed(SemaRef.Context); |
| 3657 | return DeclRefExpr::Create( |
| 3658 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3659 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3660 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3661 | } |
| 3662 | return BaseTransform::TransformDeclRefExpr(E); |
| 3663 | } |
| 3664 | }; |
| 3665 | } |
| 3666 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3667 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3668 | Expr * |
| 3669 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3670 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3671 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3672 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3673 | auto VarType = Var->getType().getNonReferenceType(); |
| 3674 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3675 | SemaRef.getLangOpts().CPlusPlus) { |
| 3676 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3677 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3678 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3679 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3680 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3681 | if (!Upper || !Lower) |
| 3682 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3683 | if (!SemaRef.Context.hasSameType(Upper->getType(), UBExpr->getType())) { |
| 3684 | Upper = SemaRef |
| 3685 | .PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3686 | Sema::AA_Converting, |
| 3687 | /*AllowExplicit=*/true) |
| 3688 | .get(); |
| 3689 | } |
| 3690 | if (!SemaRef.Context.hasSameType(Lower->getType(), LBExpr->getType())) { |
| 3691 | Lower = SemaRef |
| 3692 | .PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3693 | Sema::AA_Converting, |
| 3694 | /*AllowExplicit=*/true) |
| 3695 | .get(); |
| 3696 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3697 | if (!Upper || !Lower) |
| 3698 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3699 | |
| 3700 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3701 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3702 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3703 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3704 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3705 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3706 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3707 | return nullptr; |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | if (!Diff.isUsable()) |
| 3712 | return nullptr; |
| 3713 | |
| 3714 | // Upper - Lower [- 1] |
| 3715 | if (TestIsStrictOp) |
| 3716 | Diff = SemaRef.BuildBinOp( |
| 3717 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3718 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3719 | if (!Diff.isUsable()) |
| 3720 | return nullptr; |
| 3721 | |
| 3722 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3723 | auto *StepNoImp = Step->IgnoreImplicit(); |
| 3724 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3725 | if (NewStep.isInvalid()) |
| 3726 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3727 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3728 | StepNoImp->getType())) { |
| 3729 | NewStep = SemaRef.PerformImplicitConversion( |
| 3730 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3731 | /*AllowExplicit=*/true); |
| 3732 | if (NewStep.isInvalid()) |
| 3733 | return nullptr; |
| 3734 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3735 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3736 | if (!Diff.isUsable()) |
| 3737 | return nullptr; |
| 3738 | |
| 3739 | // Parentheses (for dumping/debugging purposes only). |
| 3740 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3741 | if (!Diff.isUsable()) |
| 3742 | return nullptr; |
| 3743 | |
| 3744 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3745 | NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3746 | if (NewStep.isInvalid()) |
| 3747 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3748 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3749 | StepNoImp->getType())) { |
| 3750 | NewStep = SemaRef.PerformImplicitConversion( |
| 3751 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3752 | /*AllowExplicit=*/true); |
| 3753 | if (NewStep.isInvalid()) |
| 3754 | return nullptr; |
| 3755 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3756 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3757 | if (!Diff.isUsable()) |
| 3758 | return nullptr; |
| 3759 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3760 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3761 | QualType Type = Diff.get()->getType(); |
| 3762 | auto &C = SemaRef.Context; |
| 3763 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3764 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3765 | if (!Type->isIntegerType() || UseVarType) { |
| 3766 | unsigned NewSize = |
| 3767 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3768 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3769 | : Type->hasSignedIntegerRepresentation(); |
| 3770 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3771 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3772 | Diff = SemaRef.PerformImplicitConversion( |
| 3773 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3774 | if (!Diff.isUsable()) |
| 3775 | return nullptr; |
| 3776 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3777 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3778 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3779 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3780 | if (NewSize != C.getTypeSize(Type)) { |
| 3781 | if (NewSize < C.getTypeSize(Type)) { |
| 3782 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3783 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3784 | << InitSrcRange << ConditionSrcRange; |
| 3785 | } |
| 3786 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3787 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3788 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3789 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3790 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3791 | Sema::AA_Converting, true); |
| 3792 | if (!Diff.isUsable()) |
| 3793 | return nullptr; |
| 3794 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3795 | } |
| 3796 | } |
| 3797 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3798 | return Diff.get(); |
| 3799 | } |
| 3800 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3801 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3802 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3803 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3804 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3805 | TransformToNewDefs Transform(SemaRef); |
| 3806 | |
| 3807 | auto NewLB = Transform.TransformExpr(LB); |
| 3808 | auto NewUB = Transform.TransformExpr(UB); |
| 3809 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3810 | return Cond; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3811 | if (!SemaRef.Context.hasSameType(NewLB.get()->getType(), LB->getType())) { |
| 3812 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3813 | Sema::AA_Converting, |
| 3814 | /*AllowExplicit=*/true); |
| 3815 | } |
| 3816 | if (!SemaRef.Context.hasSameType(NewUB.get()->getType(), UB->getType())) { |
| 3817 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3818 | Sema::AA_Converting, |
| 3819 | /*AllowExplicit=*/true); |
| 3820 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3821 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3822 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3823 | auto CondExpr = SemaRef.BuildBinOp( |
| 3824 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3825 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3826 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3827 | if (CondExpr.isUsable()) { |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3828 | if (!SemaRef.Context.hasSameType(CondExpr.get()->getType(), |
| 3829 | SemaRef.Context.BoolTy)) |
| 3830 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3831 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3832 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3833 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3834 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3835 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3836 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3837 | } |
| 3838 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3839 | /// \brief Build reference expression to the counter be used for codegen. |
| 3840 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3841 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3842 | DefaultLoc); |
| 3843 | } |
| 3844 | |
| 3845 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3846 | if (Var && !Var->isInvalidDecl()) { |
| 3847 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3848 | auto *PrivateVar = |
| 3849 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3850 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3851 | if (PrivateVar->isInvalidDecl()) |
| 3852 | return nullptr; |
| 3853 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3854 | } |
| 3855 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | /// \brief Build initization of the counter be used for codegen. |
| 3859 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3860 | |
| 3861 | /// \brief Build step of the counter be used for codegen. |
| 3862 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3863 | |
| 3864 | /// \brief Iteration space of a single for loop. |
| 3865 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3866 | /// \brief Condition of the loop. |
| 3867 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3868 | /// \brief This expression calculates the number of iterations in the loop. |
| 3869 | /// It is always possible to calculate it before starting the loop. |
| 3870 | Expr *NumIterations; |
| 3871 | /// \brief The loop counter variable. |
| 3872 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3873 | /// \brief Private loop counter variable. |
| 3874 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3875 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3876 | Expr *CounterInit; |
| 3877 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3878 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3879 | Expr *CounterStep; |
| 3880 | /// \brief Should step be subtracted? |
| 3881 | bool Subtract; |
| 3882 | /// \brief Source range of the loop init. |
| 3883 | SourceRange InitSrcRange; |
| 3884 | /// \brief Source range of the loop condition. |
| 3885 | SourceRange CondSrcRange; |
| 3886 | /// \brief Source range of the loop increment. |
| 3887 | SourceRange IncSrcRange; |
| 3888 | }; |
| 3889 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3890 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3891 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3892 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3893 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3894 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3895 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3896 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3897 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3898 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3899 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3900 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3901 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3905 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3906 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3907 | static bool CheckOpenMPIterationSpace( |
| 3908 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3909 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3910 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3911 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3912 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3913 | // OpenMP [2.6, Canonical Loop Form] |
| 3914 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3915 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3916 | if (!For) { |
| 3917 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3918 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3919 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3920 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3921 | if (NestedLoopCount > 1) { |
| 3922 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3923 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3924 | diag::note_omp_collapse_ordered_expr) |
| 3925 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3926 | << OrderedLoopCountExpr->getSourceRange(); |
| 3927 | else if (CollapseLoopCountExpr) |
| 3928 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3929 | diag::note_omp_collapse_ordered_expr) |
| 3930 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3931 | else |
| 3932 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3933 | diag::note_omp_collapse_ordered_expr) |
| 3934 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3935 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3936 | return true; |
| 3937 | } |
| 3938 | assert(For->getBody()); |
| 3939 | |
| 3940 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3941 | |
| 3942 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3943 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3944 | if (ISC.CheckInit(Init)) { |
| 3945 | return true; |
| 3946 | } |
| 3947 | |
| 3948 | bool HasErrors = false; |
| 3949 | |
| 3950 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3951 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3952 | |
| 3953 | // OpenMP [2.6, Canonical Loop Form] |
| 3954 | // Var is one of the following: |
| 3955 | // A variable of signed or unsigned integer type. |
| 3956 | // For C++, a variable of a random access iterator type. |
| 3957 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3958 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3959 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3960 | !VarType->isPointerType() && |
| 3961 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3962 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3963 | << SemaRef.getLangOpts().CPlusPlus; |
| 3964 | HasErrors = true; |
| 3965 | } |
| 3966 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3967 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3968 | // Construct |
| 3969 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3970 | // parallel for construct is (are) private. |
| 3971 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3972 | // with just one associated for-loop is linear with a constant-linear-step |
| 3973 | // that is the increment of the associated for-loop. |
| 3974 | // Exclude loop var from the list of variables with implicitly defined data |
| 3975 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3976 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3977 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3978 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3979 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3980 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3981 | // with just one associated for-loop may be listed in a linear clause with a |
| 3982 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3983 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3984 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3985 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3986 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3987 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3988 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3989 | auto PredeterminedCKind = |
| 3990 | isOpenMPSimdDirective(DKind) |
| 3991 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3992 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3993 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3994 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3995 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3996 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3997 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3998 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3999 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4000 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4001 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4002 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 4003 | if (DVar.RefExpr == nullptr) |
| 4004 | DVar.CKind = PredeterminedCKind; |
| 4005 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4006 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4007 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4008 | // Make the loop iteration variable private (for worksharing constructs), |
| 4009 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4010 | // lastprivate (for simd directives with several collapsed or ordered |
| 4011 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 4012 | if (DVar.CKind == OMPC_unknown) |
| 4013 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 4014 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4015 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4018 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4019 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4020 | // Check test-expr. |
| 4021 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4022 | |
| 4023 | // Check incr-expr. |
| 4024 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 4025 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4026 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4027 | return HasErrors; |
| 4028 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4029 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4030 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4031 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4032 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4033 | isOpenMPTaskLoopDirective(DKind) || |
| 4034 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4035 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4036 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4037 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4038 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4039 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4040 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4041 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4042 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4043 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4044 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4045 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4046 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4047 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4048 | ResultIterSpace.CounterInit == nullptr || |
| 4049 | ResultIterSpace.CounterStep == nullptr); |
| 4050 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4051 | return HasErrors; |
| 4052 | } |
| 4053 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4054 | /// \brief Build 'VarRef = Start. |
| 4055 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4056 | ExprResult VarRef, ExprResult Start) { |
| 4057 | TransformToNewDefs Transform(SemaRef); |
| 4058 | // Build 'VarRef = Start. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4059 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4060 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4061 | if (NewStart.isInvalid()) |
| 4062 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4063 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4064 | StartNoImp->getType())) { |
| 4065 | NewStart = SemaRef.PerformImplicitConversion( |
| 4066 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4067 | /*AllowExplicit=*/true); |
| 4068 | if (NewStart.isInvalid()) |
| 4069 | return ExprError(); |
| 4070 | } |
| 4071 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4072 | VarRef.get()->getType())) { |
| 4073 | NewStart = SemaRef.PerformImplicitConversion( |
| 4074 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4075 | /*AllowExplicit=*/true); |
| 4076 | if (!NewStart.isUsable()) |
| 4077 | return ExprError(); |
| 4078 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4079 | |
| 4080 | auto Init = |
| 4081 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4082 | return Init; |
| 4083 | } |
| 4084 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4085 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 4086 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 4087 | SourceLocation Loc, ExprResult VarRef, |
| 4088 | ExprResult Start, ExprResult Iter, |
| 4089 | ExprResult Step, bool Subtract) { |
| 4090 | // Add parentheses (for debugging purposes only). |
| 4091 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4092 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4093 | !Step.isUsable()) |
| 4094 | return ExprError(); |
| 4095 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4096 | auto *StepNoImp = Step.get()->IgnoreImplicit(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4097 | TransformToNewDefs Transform(SemaRef); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4098 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4099 | if (NewStep.isInvalid()) |
| 4100 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4101 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 4102 | StepNoImp->getType())) { |
| 4103 | NewStep = SemaRef.PerformImplicitConversion( |
| 4104 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 4105 | /*AllowExplicit=*/true); |
| 4106 | if (NewStep.isInvalid()) |
| 4107 | return ExprError(); |
| 4108 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4109 | ExprResult Update = |
| 4110 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4111 | if (!Update.isUsable()) |
| 4112 | return ExprError(); |
| 4113 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4114 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4115 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4116 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4117 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4118 | if (NewStart.isInvalid()) |
| 4119 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4120 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4121 | StartNoImp->getType())) { |
| 4122 | NewStart = SemaRef.PerformImplicitConversion( |
| 4123 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4124 | /*AllowExplicit=*/true); |
| 4125 | if (NewStart.isInvalid()) |
| 4126 | return ExprError(); |
| 4127 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4128 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4129 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4130 | ExprResult SavedUpdate = Update; |
| 4131 | ExprResult UpdateVal; |
| 4132 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4133 | NewStart.get()->getType()->isOverloadableType() || |
| 4134 | Update.get()->getType()->isOverloadableType()) { |
| 4135 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4136 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4137 | Update = |
| 4138 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4139 | if (Update.isUsable()) { |
| 4140 | UpdateVal = |
| 4141 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4142 | VarRef.get(), SavedUpdate.get()); |
| 4143 | if (UpdateVal.isUsable()) { |
| 4144 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4145 | UpdateVal.get()); |
| 4146 | } |
| 4147 | } |
| 4148 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4149 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4150 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4151 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4152 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4153 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4154 | NewStart.get(), SavedUpdate.get()); |
| 4155 | if (!Update.isUsable()) |
| 4156 | return ExprError(); |
| 4157 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4158 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4159 | VarRef.get()->getType())) { |
| 4160 | Update = SemaRef.PerformImplicitConversion( |
| 4161 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4162 | if (!Update.isUsable()) |
| 4163 | return ExprError(); |
| 4164 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4165 | |
| 4166 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4167 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4168 | return Update; |
| 4169 | } |
| 4170 | |
| 4171 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4172 | /// bits. |
| 4173 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4174 | Sema &SemaRef) { |
| 4175 | if (E == nullptr) |
| 4176 | return ExprError(); |
| 4177 | auto &C = SemaRef.Context; |
| 4178 | QualType OldType = E->getType(); |
| 4179 | unsigned HasBits = C.getTypeSize(OldType); |
| 4180 | if (HasBits >= Bits) |
| 4181 | return ExprResult(E); |
| 4182 | // OK to convert to signed, because new type has more bits than old. |
| 4183 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4184 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4185 | true); |
| 4186 | } |
| 4187 | |
| 4188 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4189 | /// into \a Bits bits. |
| 4190 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4191 | if (E == nullptr) |
| 4192 | return false; |
| 4193 | llvm::APSInt Result; |
| 4194 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4195 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4196 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | /// \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] | 4200 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4201 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4202 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4203 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4204 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4205 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4206 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4207 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4208 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4209 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4210 | // Found 'collapse' clause - calculate collapse number. |
| 4211 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4212 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4213 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4214 | } |
| 4215 | if (OrderedLoopCountExpr) { |
| 4216 | // Found 'ordered' clause - calculate collapse number. |
| 4217 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4218 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4219 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4220 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4221 | diag::err_omp_wrong_ordered_loop_count) |
| 4222 | << OrderedLoopCountExpr->getSourceRange(); |
| 4223 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4224 | diag::note_collapse_loop_count) |
| 4225 | << CollapseLoopCountExpr->getSourceRange(); |
| 4226 | } |
| 4227 | NestedLoopCount = Result.getLimitedValue(); |
| 4228 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4229 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4230 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4231 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4232 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4233 | IterSpaces.resize(NestedLoopCount); |
| 4234 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4235 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4236 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4237 | NestedLoopCount, CollapseLoopCountExpr, |
| 4238 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 4239 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4240 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4241 | // 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] | 4242 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4243 | // All loops associated with the construct must be perfectly nested; that |
| 4244 | // is, there must be no intervening code nor any OpenMP directive between |
| 4245 | // any two loops. |
| 4246 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4249 | Built.clear(/* size */ NestedLoopCount); |
| 4250 | |
| 4251 | if (SemaRef.CurContext->isDependentContext()) |
| 4252 | return NestedLoopCount; |
| 4253 | |
| 4254 | // An example of what is generated for the following code: |
| 4255 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4256 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4257 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4258 | // for (k = 0; k < NK; ++k) |
| 4259 | // for (j = J0; j < NJ; j+=2) { |
| 4260 | // <loop body> |
| 4261 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4262 | // |
| 4263 | // We generate the code below. |
| 4264 | // Note: the loop body may be outlined in CodeGen. |
| 4265 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4266 | // iterations and operator+= to calculate counter value. |
| 4267 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4268 | // or i64 is currently supported). |
| 4269 | // |
| 4270 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4271 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4272 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4273 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4274 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4275 | // <loop body (using local i and j)> |
| 4276 | // } |
| 4277 | // i = NI; // assign final values of counters |
| 4278 | // j = NJ; |
| 4279 | // |
| 4280 | |
| 4281 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4282 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4283 | // Precondition tests if there is at least one iteration (all conditions are |
| 4284 | // true). |
| 4285 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4286 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4287 | ExprResult LastIteration32 = WidenIterationCount( |
| 4288 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4289 | N0->IgnoreImpCasts(), N0->getType(), |
| 4290 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4291 | .get(), |
| 4292 | SemaRef); |
| 4293 | ExprResult LastIteration64 = WidenIterationCount( |
| 4294 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4295 | N0->IgnoreImpCasts(), N0->getType(), |
| 4296 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4297 | .get(), |
| 4298 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4299 | |
| 4300 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4301 | return NestedLoopCount; |
| 4302 | |
| 4303 | auto &C = SemaRef.Context; |
| 4304 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4305 | |
| 4306 | Scope *CurScope = DSA.getCurScope(); |
| 4307 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4308 | if (PreCond.isUsable()) { |
| 4309 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4310 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4311 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4312 | auto N = IterSpaces[Cnt].NumIterations; |
| 4313 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4314 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4315 | LastIteration32 = SemaRef.BuildBinOp( |
| 4316 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4317 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4318 | Sema::AA_Converting, |
| 4319 | /*AllowExplicit=*/true) |
| 4320 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4321 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4322 | LastIteration64 = SemaRef.BuildBinOp( |
| 4323 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4324 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4325 | Sema::AA_Converting, |
| 4326 | /*AllowExplicit=*/true) |
| 4327 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | // Choose either the 32-bit or 64-bit version. |
| 4331 | ExprResult LastIteration = LastIteration64; |
| 4332 | if (LastIteration32.isUsable() && |
| 4333 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4334 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4335 | FitsInto( |
| 4336 | 32 /* Bits */, |
| 4337 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4338 | LastIteration64.get(), SemaRef))) |
| 4339 | LastIteration = LastIteration32; |
| 4340 | |
| 4341 | if (!LastIteration.isUsable()) |
| 4342 | return 0; |
| 4343 | |
| 4344 | // Save the number of iterations. |
| 4345 | ExprResult NumIterations = LastIteration; |
| 4346 | { |
| 4347 | LastIteration = SemaRef.BuildBinOp( |
| 4348 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4349 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4350 | if (!LastIteration.isUsable()) |
| 4351 | return 0; |
| 4352 | } |
| 4353 | |
| 4354 | // Calculate the last iteration number beforehand instead of doing this on |
| 4355 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4356 | llvm::APSInt Result; |
| 4357 | bool IsConstant = |
| 4358 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4359 | ExprResult CalcLastIteration; |
| 4360 | if (!IsConstant) { |
| 4361 | SourceLocation SaveLoc; |
| 4362 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4363 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4364 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4365 | ExprResult SaveRef = buildDeclRefExpr( |
| 4366 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4367 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4368 | SaveRef.get(), LastIteration.get()); |
| 4369 | LastIteration = SaveRef; |
| 4370 | |
| 4371 | // Prepare SaveRef + 1. |
| 4372 | NumIterations = SemaRef.BuildBinOp( |
| 4373 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4374 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4375 | if (!NumIterations.isUsable()) |
| 4376 | return 0; |
| 4377 | } |
| 4378 | |
| 4379 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4380 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4381 | QualType VType = LastIteration.get()->getType(); |
| 4382 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4383 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4384 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4385 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4386 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4387 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4388 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4389 | SemaRef.AddInitializerToDecl( |
| 4390 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4391 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4392 | |
| 4393 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4394 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4395 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4396 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4397 | /*DirectInit*/ false, |
| 4398 | /*TypeMayContainAuto*/ false); |
| 4399 | |
| 4400 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4401 | // This will be used to implement clause 'lastprivate'. |
| 4402 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4403 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4404 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4405 | SemaRef.AddInitializerToDecl( |
| 4406 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4407 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4408 | |
| 4409 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4410 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4411 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4412 | SemaRef.AddInitializerToDecl( |
| 4413 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4414 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4415 | |
| 4416 | // Build expression: UB = min(UB, LastIteration) |
| 4417 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4418 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4419 | UB.get(), LastIteration.get()); |
| 4420 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4421 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4422 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4423 | CondOp.get()); |
| 4424 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4425 | } |
| 4426 | |
| 4427 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4428 | ExprResult IV; |
| 4429 | ExprResult Init; |
| 4430 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4431 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4432 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4433 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4434 | isOpenMPTaskLoopDirective(DKind) || |
| 4435 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4436 | ? LB.get() |
| 4437 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4438 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4439 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4440 | } |
| 4441 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4442 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4443 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4444 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4445 | (isOpenMPWorksharingDirective(DKind) || |
| 4446 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4447 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4448 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4449 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4450 | |
| 4451 | // Loop increment (IV = IV + 1) |
| 4452 | SourceLocation IncLoc; |
| 4453 | ExprResult Inc = |
| 4454 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4455 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4456 | if (!Inc.isUsable()) |
| 4457 | return 0; |
| 4458 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4459 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4460 | if (!Inc.isUsable()) |
| 4461 | return 0; |
| 4462 | |
| 4463 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4464 | // Used for directives with static scheduling. |
| 4465 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4466 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4467 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4468 | // LB + ST |
| 4469 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4470 | if (!NextLB.isUsable()) |
| 4471 | return 0; |
| 4472 | // LB = LB + ST |
| 4473 | NextLB = |
| 4474 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4475 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4476 | if (!NextLB.isUsable()) |
| 4477 | return 0; |
| 4478 | // UB + ST |
| 4479 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4480 | if (!NextUB.isUsable()) |
| 4481 | return 0; |
| 4482 | // UB = UB + ST |
| 4483 | NextUB = |
| 4484 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4485 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4486 | if (!NextUB.isUsable()) |
| 4487 | return 0; |
| 4488 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4489 | |
| 4490 | // Build updates and final values of the loop counters. |
| 4491 | bool HasErrors = false; |
| 4492 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4493 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4494 | Built.Updates.resize(NestedLoopCount); |
| 4495 | Built.Finals.resize(NestedLoopCount); |
| 4496 | { |
| 4497 | ExprResult Div; |
| 4498 | // Go from inner nested loop to outer. |
| 4499 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4500 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4501 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4502 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4503 | // where Div is product of previous iterations' IS.NumIters. |
| 4504 | ExprResult Iter; |
| 4505 | if (Div.isUsable()) { |
| 4506 | Iter = |
| 4507 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4508 | } else { |
| 4509 | Iter = IV; |
| 4510 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4511 | "unusable div expected on first iteration only"); |
| 4512 | } |
| 4513 | |
| 4514 | if (Cnt != 0 && Iter.isUsable()) |
| 4515 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4516 | IS.NumIterations); |
| 4517 | if (!Iter.isUsable()) { |
| 4518 | HasErrors = true; |
| 4519 | break; |
| 4520 | } |
| 4521 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4522 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4523 | auto *CounterVar = buildDeclRefExpr( |
| 4524 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4525 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4526 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4527 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4528 | IS.CounterInit); |
| 4529 | if (!Init.isUsable()) { |
| 4530 | HasErrors = true; |
| 4531 | break; |
| 4532 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4533 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4534 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4535 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4536 | if (!Update.isUsable()) { |
| 4537 | HasErrors = true; |
| 4538 | break; |
| 4539 | } |
| 4540 | |
| 4541 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4542 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4543 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4544 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4545 | if (!Final.isUsable()) { |
| 4546 | HasErrors = true; |
| 4547 | break; |
| 4548 | } |
| 4549 | |
| 4550 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4551 | if (Cnt != 0) { |
| 4552 | if (Div.isUnset()) |
| 4553 | Div = IS.NumIterations; |
| 4554 | else |
| 4555 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4556 | IS.NumIterations); |
| 4557 | |
| 4558 | // Add parentheses (for debugging purposes only). |
| 4559 | if (Div.isUsable()) |
| 4560 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4561 | if (!Div.isUsable()) { |
| 4562 | HasErrors = true; |
| 4563 | break; |
| 4564 | } |
| 4565 | } |
| 4566 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4567 | HasErrors = true; |
| 4568 | break; |
| 4569 | } |
| 4570 | // Save results |
| 4571 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4572 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4573 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4574 | Built.Updates[Cnt] = Update.get(); |
| 4575 | Built.Finals[Cnt] = Final.get(); |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | if (HasErrors) |
| 4580 | return 0; |
| 4581 | |
| 4582 | // Save results |
| 4583 | Built.IterationVarRef = IV.get(); |
| 4584 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4585 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4586 | Built.CalcLastIteration = |
| 4587 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4588 | Built.PreCond = PreCond.get(); |
| 4589 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4590 | Built.Init = Init.get(); |
| 4591 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4592 | Built.LB = LB.get(); |
| 4593 | Built.UB = UB.get(); |
| 4594 | Built.IL = IL.get(); |
| 4595 | Built.ST = ST.get(); |
| 4596 | Built.EUB = EUB.get(); |
| 4597 | Built.NLB = NextLB.get(); |
| 4598 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4599 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4600 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4603 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4604 | auto CollapseClauses = |
| 4605 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4606 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4607 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4608 | return nullptr; |
| 4609 | } |
| 4610 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4611 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4612 | auto OrderedClauses = |
| 4613 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4614 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4615 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4616 | return nullptr; |
| 4617 | } |
| 4618 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4619 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4620 | const Expr *Safelen) { |
| 4621 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4622 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4623 | Simdlen->isInstantiationDependent() || |
| 4624 | Simdlen->containsUnexpandedParameterPack()) |
| 4625 | return false; |
| 4626 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4627 | Safelen->isInstantiationDependent() || |
| 4628 | Safelen->containsUnexpandedParameterPack()) |
| 4629 | return false; |
| 4630 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4631 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4632 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4633 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4634 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4635 | if (SimdlenRes > SafelenRes) { |
| 4636 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4637 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4638 | return true; |
| 4639 | } |
| 4640 | return false; |
| 4641 | } |
| 4642 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4643 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4644 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4645 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4646 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4647 | if (!AStmt) |
| 4648 | return StmtError(); |
| 4649 | |
| 4650 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4651 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4652 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4653 | // define the nested loops number. |
| 4654 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4655 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4656 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4657 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4658 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4659 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4660 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4661 | "omp simd loop exprs were not built"); |
| 4662 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4663 | if (!CurContext->isDependentContext()) { |
| 4664 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4665 | for (auto C : Clauses) { |
| 4666 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4667 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4668 | B.NumIterations, *this, CurScope)) |
| 4669 | return StmtError(); |
| 4670 | } |
| 4671 | } |
| 4672 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4673 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4674 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4675 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4676 | OMPSafelenClause *Safelen = nullptr; |
| 4677 | OMPSimdlenClause *Simdlen = nullptr; |
| 4678 | for (auto *Clause : Clauses) { |
| 4679 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4680 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4681 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4682 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4683 | if (Safelen && Simdlen) |
| 4684 | break; |
| 4685 | } |
| 4686 | if (Simdlen && Safelen && |
| 4687 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4688 | Safelen->getSafelen())) |
| 4689 | return StmtError(); |
| 4690 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4691 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4692 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4693 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4696 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4697 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4698 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4699 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4700 | if (!AStmt) |
| 4701 | return StmtError(); |
| 4702 | |
| 4703 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4704 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4705 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4706 | // define the nested loops number. |
| 4707 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4708 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4709 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4710 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4711 | return StmtError(); |
| 4712 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4713 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4714 | "omp for loop exprs were not built"); |
| 4715 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4716 | if (!CurContext->isDependentContext()) { |
| 4717 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4718 | for (auto C : Clauses) { |
| 4719 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4720 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4721 | B.NumIterations, *this, CurScope)) |
| 4722 | return StmtError(); |
| 4723 | } |
| 4724 | } |
| 4725 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4726 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4727 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4728 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4731 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4732 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4733 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4734 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4735 | if (!AStmt) |
| 4736 | return StmtError(); |
| 4737 | |
| 4738 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4739 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4740 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4741 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4742 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4743 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4744 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4745 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4746 | if (NestedLoopCount == 0) |
| 4747 | return StmtError(); |
| 4748 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4749 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4750 | "omp for simd loop exprs were not built"); |
| 4751 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4752 | if (!CurContext->isDependentContext()) { |
| 4753 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4754 | for (auto C : Clauses) { |
| 4755 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4756 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4757 | B.NumIterations, *this, CurScope)) |
| 4758 | return StmtError(); |
| 4759 | } |
| 4760 | } |
| 4761 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4762 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4763 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4764 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4765 | OMPSafelenClause *Safelen = nullptr; |
| 4766 | OMPSimdlenClause *Simdlen = nullptr; |
| 4767 | for (auto *Clause : Clauses) { |
| 4768 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4769 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4770 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4771 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4772 | if (Safelen && Simdlen) |
| 4773 | break; |
| 4774 | } |
| 4775 | if (Simdlen && Safelen && |
| 4776 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4777 | Safelen->getSafelen())) |
| 4778 | return StmtError(); |
| 4779 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4780 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4781 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4782 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4785 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4786 | Stmt *AStmt, |
| 4787 | SourceLocation StartLoc, |
| 4788 | SourceLocation EndLoc) { |
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"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4793 | auto BaseStmt = AStmt; |
| 4794 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4795 | BaseStmt = CS->getCapturedStmt(); |
| 4796 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4797 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4798 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4799 | return StmtError(); |
| 4800 | // All associated statements must be '#pragma omp section' except for |
| 4801 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4802 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4803 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4804 | if (SectionStmt) |
| 4805 | Diag(SectionStmt->getLocStart(), |
| 4806 | diag::err_omp_sections_substmt_not_section); |
| 4807 | return StmtError(); |
| 4808 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4809 | cast<OMPSectionDirective>(SectionStmt) |
| 4810 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4811 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4812 | } else { |
| 4813 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4814 | return StmtError(); |
| 4815 | } |
| 4816 | |
| 4817 | getCurFunction()->setHasBranchProtectedScope(); |
| 4818 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4819 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4820 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4823 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4824 | SourceLocation StartLoc, |
| 4825 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4826 | if (!AStmt) |
| 4827 | return StmtError(); |
| 4828 | |
| 4829 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4830 | |
| 4831 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4832 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4833 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4834 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4835 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4838 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4839 | Stmt *AStmt, |
| 4840 | SourceLocation StartLoc, |
| 4841 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4842 | if (!AStmt) |
| 4843 | return StmtError(); |
| 4844 | |
| 4845 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4846 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4847 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4848 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4849 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4850 | // The copyprivate clause must not be used with the nowait clause. |
| 4851 | OMPClause *Nowait = nullptr; |
| 4852 | OMPClause *Copyprivate = nullptr; |
| 4853 | for (auto *Clause : Clauses) { |
| 4854 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4855 | Nowait = Clause; |
| 4856 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4857 | Copyprivate = Clause; |
| 4858 | if (Copyprivate && Nowait) { |
| 4859 | Diag(Copyprivate->getLocStart(), |
| 4860 | diag::err_omp_single_copyprivate_with_nowait); |
| 4861 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4862 | return StmtError(); |
| 4863 | } |
| 4864 | } |
| 4865 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4866 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4867 | } |
| 4868 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4869 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4870 | SourceLocation StartLoc, |
| 4871 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4872 | if (!AStmt) |
| 4873 | return StmtError(); |
| 4874 | |
| 4875 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4876 | |
| 4877 | getCurFunction()->setHasBranchProtectedScope(); |
| 4878 | |
| 4879 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4880 | } |
| 4881 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4882 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4883 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4884 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4885 | if (!AStmt) |
| 4886 | return StmtError(); |
| 4887 | |
| 4888 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4889 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4890 | bool ErrorFound = false; |
| 4891 | llvm::APSInt Hint; |
| 4892 | SourceLocation HintLoc; |
| 4893 | bool DependentHint = false; |
| 4894 | for (auto *C : Clauses) { |
| 4895 | if (C->getClauseKind() == OMPC_hint) { |
| 4896 | if (!DirName.getName()) { |
| 4897 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4898 | ErrorFound = true; |
| 4899 | } |
| 4900 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4901 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4902 | E->isInstantiationDependent()) |
| 4903 | DependentHint = true; |
| 4904 | else { |
| 4905 | Hint = E->EvaluateKnownConstInt(Context); |
| 4906 | HintLoc = C->getLocStart(); |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | if (ErrorFound) |
| 4911 | return StmtError(); |
| 4912 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4913 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4914 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4915 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4916 | if (HintLoc.isValid()) { |
| 4917 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4918 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4919 | } else |
| 4920 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4921 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4922 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4923 | << 1 |
| 4924 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4925 | /*Radix=*/10, /*Signed=*/false); |
| 4926 | } else |
| 4927 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4928 | } |
| 4929 | } |
| 4930 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4931 | getCurFunction()->setHasBranchProtectedScope(); |
| 4932 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4933 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4934 | Clauses, AStmt); |
| 4935 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4936 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4937 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4938 | } |
| 4939 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4940 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4941 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4942 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4943 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4944 | if (!AStmt) |
| 4945 | return StmtError(); |
| 4946 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4947 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4948 | // 1.2.2 OpenMP Language Terminology |
| 4949 | // Structured block - An executable statement with a single entry at the |
| 4950 | // top and a single exit at the bottom. |
| 4951 | // The point of exit cannot be a branch out of the structured block. |
| 4952 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4953 | CS->getCapturedDecl()->setNothrow(); |
| 4954 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4955 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4956 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4957 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4958 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4959 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4960 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4961 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4962 | if (NestedLoopCount == 0) |
| 4963 | return StmtError(); |
| 4964 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4965 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4966 | "omp parallel for loop exprs were not built"); |
| 4967 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4968 | if (!CurContext->isDependentContext()) { |
| 4969 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4970 | for (auto C : Clauses) { |
| 4971 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4972 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4973 | B.NumIterations, *this, CurScope)) |
| 4974 | return StmtError(); |
| 4975 | } |
| 4976 | } |
| 4977 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4978 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4979 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4980 | NestedLoopCount, Clauses, AStmt, B, |
| 4981 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4984 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4985 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4986 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4987 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4988 | if (!AStmt) |
| 4989 | return StmtError(); |
| 4990 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4991 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4992 | // 1.2.2 OpenMP Language Terminology |
| 4993 | // Structured block - An executable statement with a single entry at the |
| 4994 | // top and a single exit at the bottom. |
| 4995 | // The point of exit cannot be a branch out of the structured block. |
| 4996 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4997 | CS->getCapturedDecl()->setNothrow(); |
| 4998 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4999 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5000 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5001 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5002 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5003 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5004 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5005 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5006 | if (NestedLoopCount == 0) |
| 5007 | return StmtError(); |
| 5008 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5009 | if (!CurContext->isDependentContext()) { |
| 5010 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5011 | for (auto C : Clauses) { |
| 5012 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5013 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5014 | B.NumIterations, *this, CurScope)) |
| 5015 | return StmtError(); |
| 5016 | } |
| 5017 | } |
| 5018 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5019 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5020 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5021 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5022 | OMPSafelenClause *Safelen = nullptr; |
| 5023 | OMPSimdlenClause *Simdlen = nullptr; |
| 5024 | for (auto *Clause : Clauses) { |
| 5025 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5026 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5027 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5028 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5029 | if (Safelen && Simdlen) |
| 5030 | break; |
| 5031 | } |
| 5032 | if (Simdlen && Safelen && |
| 5033 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5034 | Safelen->getSafelen())) |
| 5035 | return StmtError(); |
| 5036 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5037 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5038 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5039 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5040 | } |
| 5041 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5042 | StmtResult |
| 5043 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5044 | Stmt *AStmt, SourceLocation StartLoc, |
| 5045 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5046 | if (!AStmt) |
| 5047 | return StmtError(); |
| 5048 | |
| 5049 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5050 | auto BaseStmt = AStmt; |
| 5051 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5052 | BaseStmt = CS->getCapturedStmt(); |
| 5053 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5054 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5055 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5056 | return StmtError(); |
| 5057 | // All associated statements must be '#pragma omp section' except for |
| 5058 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5059 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5060 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5061 | if (SectionStmt) |
| 5062 | Diag(SectionStmt->getLocStart(), |
| 5063 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5064 | return StmtError(); |
| 5065 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5066 | cast<OMPSectionDirective>(SectionStmt) |
| 5067 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5068 | } |
| 5069 | } else { |
| 5070 | Diag(AStmt->getLocStart(), |
| 5071 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5072 | return StmtError(); |
| 5073 | } |
| 5074 | |
| 5075 | getCurFunction()->setHasBranchProtectedScope(); |
| 5076 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5077 | return OMPParallelSectionsDirective::Create( |
| 5078 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5081 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5082 | Stmt *AStmt, SourceLocation StartLoc, |
| 5083 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5084 | if (!AStmt) |
| 5085 | return StmtError(); |
| 5086 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5087 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5088 | // 1.2.2 OpenMP Language Terminology |
| 5089 | // Structured block - An executable statement with a single entry at the |
| 5090 | // top and a single exit at the bottom. |
| 5091 | // The point of exit cannot be a branch out of the structured block. |
| 5092 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5093 | CS->getCapturedDecl()->setNothrow(); |
| 5094 | |
| 5095 | getCurFunction()->setHasBranchProtectedScope(); |
| 5096 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5097 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5098 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5101 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5102 | SourceLocation EndLoc) { |
| 5103 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5104 | } |
| 5105 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5106 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5107 | SourceLocation EndLoc) { |
| 5108 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5109 | } |
| 5110 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5111 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5112 | SourceLocation EndLoc) { |
| 5113 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5114 | } |
| 5115 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5116 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5117 | SourceLocation StartLoc, |
| 5118 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5119 | if (!AStmt) |
| 5120 | return StmtError(); |
| 5121 | |
| 5122 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5123 | |
| 5124 | getCurFunction()->setHasBranchProtectedScope(); |
| 5125 | |
| 5126 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5127 | } |
| 5128 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5129 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5130 | SourceLocation StartLoc, |
| 5131 | SourceLocation EndLoc) { |
| 5132 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5133 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5134 | } |
| 5135 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5136 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5137 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5138 | SourceLocation StartLoc, |
| 5139 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5140 | OMPClause *DependFound = nullptr; |
| 5141 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5142 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5143 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5144 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5145 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5146 | for (auto *C : Clauses) { |
| 5147 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5148 | DependFound = C; |
| 5149 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5150 | if (DependSourceClause) { |
| 5151 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5152 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5153 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5154 | ErrorFound = true; |
| 5155 | } else |
| 5156 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5157 | if (DependSinkClause) { |
| 5158 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5159 | << 0; |
| 5160 | ErrorFound = true; |
| 5161 | } |
| 5162 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5163 | if (DependSourceClause) { |
| 5164 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5165 | << 1; |
| 5166 | ErrorFound = true; |
| 5167 | } |
| 5168 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5169 | } |
| 5170 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5171 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5172 | else if (C->getClauseKind() == OMPC_simd) |
| 5173 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5174 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5175 | if (!ErrorFound && !SC && |
| 5176 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5177 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5178 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5179 | // that can appear in the simd region. |
| 5180 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5181 | ErrorFound = true; |
| 5182 | } else if (DependFound && (TC || SC)) { |
| 5183 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5184 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5185 | ErrorFound = true; |
| 5186 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5187 | Diag(DependFound->getLocStart(), |
| 5188 | diag::err_omp_ordered_directive_without_param); |
| 5189 | ErrorFound = true; |
| 5190 | } else if (TC || Clauses.empty()) { |
| 5191 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5192 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5193 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5194 | << (TC != nullptr); |
| 5195 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5196 | ErrorFound = true; |
| 5197 | } |
| 5198 | } |
| 5199 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5200 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5201 | |
| 5202 | if (AStmt) { |
| 5203 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5204 | |
| 5205 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5206 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5207 | |
| 5208 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5209 | } |
| 5210 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5211 | namespace { |
| 5212 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5213 | /// construct. |
| 5214 | class OpenMPAtomicUpdateChecker { |
| 5215 | /// \brief Error results for atomic update expressions. |
| 5216 | enum ExprAnalysisErrorCode { |
| 5217 | /// \brief A statement is not an expression statement. |
| 5218 | NotAnExpression, |
| 5219 | /// \brief Expression is not builtin binary or unary operation. |
| 5220 | NotABinaryOrUnaryExpression, |
| 5221 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5222 | NotAnUnaryIncDecExpression, |
| 5223 | /// \brief An expression is not of scalar type. |
| 5224 | NotAScalarType, |
| 5225 | /// \brief A binary operation is not an assignment operation. |
| 5226 | NotAnAssignmentOp, |
| 5227 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5228 | NotABinaryExpression, |
| 5229 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5230 | /// expression. |
| 5231 | NotABinaryOperator, |
| 5232 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5233 | /// part. |
| 5234 | NotAnUpdateExpression, |
| 5235 | /// \brief No errors is found. |
| 5236 | NoError |
| 5237 | }; |
| 5238 | /// \brief Reference to Sema. |
| 5239 | Sema &SemaRef; |
| 5240 | /// \brief A location for note diagnostics (when error is found). |
| 5241 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5242 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5243 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5244 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5245 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5246 | /// \brief Helper expression of the form |
| 5247 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5248 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5249 | Expr *UpdateExpr; |
| 5250 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5251 | /// important for non-associative operations. |
| 5252 | bool IsXLHSInRHSPart; |
| 5253 | BinaryOperatorKind Op; |
| 5254 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5255 | /// \brief true if the source expression is a postfix unary operation, false |
| 5256 | /// if it is a prefix unary operation. |
| 5257 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5258 | |
| 5259 | public: |
| 5260 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5261 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5262 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5263 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5264 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5265 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5266 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5267 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5268 | /// \param NoteId Diagnostic note for the main error message. |
| 5269 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5270 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5271 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5272 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5273 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5274 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5275 | /// \brief Return the update expression used in calculation of the updated |
| 5276 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5277 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5278 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5279 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5280 | /// false otherwise. |
| 5281 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5282 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5283 | /// \brief true if the source expression is a postfix unary operation, false |
| 5284 | /// if it is a prefix unary operation. |
| 5285 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5286 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5287 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5288 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5289 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5290 | }; |
| 5291 | } // namespace |
| 5292 | |
| 5293 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5294 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5295 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5296 | SourceLocation ErrorLoc, NoteLoc; |
| 5297 | SourceRange ErrorRange, NoteRange; |
| 5298 | // Allowed constructs are: |
| 5299 | // x = x binop expr; |
| 5300 | // x = expr binop x; |
| 5301 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5302 | X = AtomicBinOp->getLHS(); |
| 5303 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5304 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5305 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5306 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5307 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5308 | Op = AtomicInnerBinOp->getOpcode(); |
| 5309 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5310 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5311 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5312 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5313 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5314 | /*Canonical=*/true); |
| 5315 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5316 | /*Canonical=*/true); |
| 5317 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5318 | /*Canonical=*/true); |
| 5319 | if (XId == LHSId) { |
| 5320 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5321 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5322 | } else if (XId == RHSId) { |
| 5323 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5324 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5325 | } else { |
| 5326 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5327 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5328 | NoteLoc = X->getExprLoc(); |
| 5329 | NoteRange = X->getSourceRange(); |
| 5330 | ErrorFound = NotAnUpdateExpression; |
| 5331 | } |
| 5332 | } else { |
| 5333 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5334 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5335 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5336 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5337 | ErrorFound = NotABinaryOperator; |
| 5338 | } |
| 5339 | } else { |
| 5340 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5341 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5342 | ErrorFound = NotABinaryExpression; |
| 5343 | } |
| 5344 | } else { |
| 5345 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5346 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5347 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5348 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5349 | ErrorFound = NotAnAssignmentOp; |
| 5350 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5351 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5352 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5353 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5354 | return true; |
| 5355 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5356 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5357 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5361 | unsigned NoteId) { |
| 5362 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5363 | SourceLocation ErrorLoc, NoteLoc; |
| 5364 | SourceRange ErrorRange, NoteRange; |
| 5365 | // Allowed constructs are: |
| 5366 | // x++; |
| 5367 | // x--; |
| 5368 | // ++x; |
| 5369 | // --x; |
| 5370 | // x binop= expr; |
| 5371 | // x = x binop expr; |
| 5372 | // x = expr binop x; |
| 5373 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5374 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5375 | if (AtomicBody->getType()->isScalarType() || |
| 5376 | AtomicBody->isInstantiationDependent()) { |
| 5377 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5378 | AtomicBody->IgnoreParenImpCasts())) { |
| 5379 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5380 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5381 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5382 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5383 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5384 | X = AtomicCompAssignOp->getLHS(); |
| 5385 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5386 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5387 | AtomicBody->IgnoreParenImpCasts())) { |
| 5388 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5389 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5390 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5391 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5392 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5393 | // Check for Unary Operation |
| 5394 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5395 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5396 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5397 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5398 | X = AtomicUnaryOp->getSubExpr(); |
| 5399 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5400 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5401 | } else { |
| 5402 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5403 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5404 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5405 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5406 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5407 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5408 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5409 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5410 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5411 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5412 | } |
| 5413 | } else { |
| 5414 | ErrorFound = NotAScalarType; |
| 5415 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5416 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5417 | } |
| 5418 | } else { |
| 5419 | ErrorFound = NotAnExpression; |
| 5420 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5421 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5422 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5423 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5424 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5425 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5426 | return true; |
| 5427 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5428 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5429 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5430 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5431 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5432 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5433 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5434 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5435 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5436 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5437 | auto Update = |
| 5438 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5439 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5440 | if (Update.isInvalid()) |
| 5441 | return true; |
| 5442 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5443 | Sema::AA_Casting); |
| 5444 | if (Update.isInvalid()) |
| 5445 | return true; |
| 5446 | UpdateExpr = Update.get(); |
| 5447 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5448 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5451 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5452 | Stmt *AStmt, |
| 5453 | SourceLocation StartLoc, |
| 5454 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5455 | if (!AStmt) |
| 5456 | return StmtError(); |
| 5457 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5458 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5459 | // 1.2.2 OpenMP Language Terminology |
| 5460 | // Structured block - An executable statement with a single entry at the |
| 5461 | // top and a single exit at the bottom. |
| 5462 | // The point of exit cannot be a branch out of the structured block. |
| 5463 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5464 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5465 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5466 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5467 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5468 | C->getClauseKind() == OMPC_update || |
| 5469 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5470 | if (AtomicKind != OMPC_unknown) { |
| 5471 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5472 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5473 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5474 | << getOpenMPClauseName(AtomicKind); |
| 5475 | } else { |
| 5476 | AtomicKind = C->getClauseKind(); |
| 5477 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5478 | } |
| 5479 | } |
| 5480 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5481 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5482 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5483 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5484 | Body = EWC->getSubExpr(); |
| 5485 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5486 | Expr *X = nullptr; |
| 5487 | Expr *V = nullptr; |
| 5488 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5489 | Expr *UE = nullptr; |
| 5490 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5491 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5492 | // OpenMP [2.12.6, atomic Construct] |
| 5493 | // In the next expressions: |
| 5494 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5495 | // * During the execution of an atomic region, multiple syntactic |
| 5496 | // occurrences of x must designate the same storage location. |
| 5497 | // * Neither of v and expr (as applicable) may access the storage location |
| 5498 | // designated by x. |
| 5499 | // * Neither of x and expr (as applicable) may access the storage location |
| 5500 | // designated by v. |
| 5501 | // * expr is an expression with scalar type. |
| 5502 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5503 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5504 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5505 | // (expr). This requirement is satisfied if the operators in expr have |
| 5506 | // precedence greater than binop, or by using parentheses around expr or |
| 5507 | // subexpressions of expr. |
| 5508 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5509 | // binop x. This requirement is satisfied if the operators in expr have |
| 5510 | // precedence equal to or greater than binop, or by using parentheses around |
| 5511 | // expr or subexpressions of expr. |
| 5512 | // * For forms that allow multiple occurrences of x, the number of times |
| 5513 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5514 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5515 | enum { |
| 5516 | NotAnExpression, |
| 5517 | NotAnAssignmentOp, |
| 5518 | NotAScalarType, |
| 5519 | NotAnLValue, |
| 5520 | NoError |
| 5521 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5522 | SourceLocation ErrorLoc, NoteLoc; |
| 5523 | SourceRange ErrorRange, NoteRange; |
| 5524 | // If clause is read: |
| 5525 | // v = x; |
| 5526 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5527 | auto AtomicBinOp = |
| 5528 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5529 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5530 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5531 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5532 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5533 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5534 | if (!X->isLValue() || !V->isLValue()) { |
| 5535 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5536 | ErrorFound = NotAnLValue; |
| 5537 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5538 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5539 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5540 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5541 | } |
| 5542 | } else if (!X->isInstantiationDependent() || |
| 5543 | !V->isInstantiationDependent()) { |
| 5544 | auto NotScalarExpr = |
| 5545 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5546 | ? V |
| 5547 | : X; |
| 5548 | ErrorFound = NotAScalarType; |
| 5549 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5550 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5551 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5552 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5553 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5554 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5555 | ErrorFound = NotAnAssignmentOp; |
| 5556 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5557 | ErrorRange = AtomicBody->getSourceRange(); |
| 5558 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5559 | : AtomicBody->getExprLoc(); |
| 5560 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5561 | : AtomicBody->getSourceRange(); |
| 5562 | } |
| 5563 | } else { |
| 5564 | ErrorFound = NotAnExpression; |
| 5565 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5566 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5567 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5568 | if (ErrorFound != NoError) { |
| 5569 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5570 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5571 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5572 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5573 | return StmtError(); |
| 5574 | } else if (CurContext->isDependentContext()) |
| 5575 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5576 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5577 | enum { |
| 5578 | NotAnExpression, |
| 5579 | NotAnAssignmentOp, |
| 5580 | NotAScalarType, |
| 5581 | NotAnLValue, |
| 5582 | NoError |
| 5583 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5584 | SourceLocation ErrorLoc, NoteLoc; |
| 5585 | SourceRange ErrorRange, NoteRange; |
| 5586 | // If clause is write: |
| 5587 | // x = expr; |
| 5588 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5589 | auto AtomicBinOp = |
| 5590 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5591 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5592 | X = AtomicBinOp->getLHS(); |
| 5593 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5594 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5595 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5596 | if (!X->isLValue()) { |
| 5597 | ErrorFound = NotAnLValue; |
| 5598 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5599 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5600 | NoteLoc = X->getExprLoc(); |
| 5601 | NoteRange = X->getSourceRange(); |
| 5602 | } |
| 5603 | } else if (!X->isInstantiationDependent() || |
| 5604 | !E->isInstantiationDependent()) { |
| 5605 | auto NotScalarExpr = |
| 5606 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5607 | ? E |
| 5608 | : X; |
| 5609 | ErrorFound = NotAScalarType; |
| 5610 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5611 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5612 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5613 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5614 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5615 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5616 | ErrorFound = NotAnAssignmentOp; |
| 5617 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5618 | ErrorRange = AtomicBody->getSourceRange(); |
| 5619 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5620 | : AtomicBody->getExprLoc(); |
| 5621 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5622 | : AtomicBody->getSourceRange(); |
| 5623 | } |
| 5624 | } else { |
| 5625 | ErrorFound = NotAnExpression; |
| 5626 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5627 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5628 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5629 | if (ErrorFound != NoError) { |
| 5630 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5631 | << ErrorRange; |
| 5632 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5633 | << NoteRange; |
| 5634 | return StmtError(); |
| 5635 | } else if (CurContext->isDependentContext()) |
| 5636 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5637 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5638 | // If clause is update: |
| 5639 | // x++; |
| 5640 | // x--; |
| 5641 | // ++x; |
| 5642 | // --x; |
| 5643 | // x binop= expr; |
| 5644 | // x = x binop expr; |
| 5645 | // x = expr binop x; |
| 5646 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5647 | if (Checker.checkStatement( |
| 5648 | Body, (AtomicKind == OMPC_update) |
| 5649 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5650 | : diag::err_omp_atomic_not_expression_statement, |
| 5651 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5652 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5653 | if (!CurContext->isDependentContext()) { |
| 5654 | E = Checker.getExpr(); |
| 5655 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5656 | UE = Checker.getUpdateExpr(); |
| 5657 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5658 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5659 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5660 | enum { |
| 5661 | NotAnAssignmentOp, |
| 5662 | NotACompoundStatement, |
| 5663 | NotTwoSubstatements, |
| 5664 | NotASpecificExpression, |
| 5665 | NoError |
| 5666 | } ErrorFound = NoError; |
| 5667 | SourceLocation ErrorLoc, NoteLoc; |
| 5668 | SourceRange ErrorRange, NoteRange; |
| 5669 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5670 | // If clause is a capture: |
| 5671 | // v = x++; |
| 5672 | // v = x--; |
| 5673 | // v = ++x; |
| 5674 | // v = --x; |
| 5675 | // v = x binop= expr; |
| 5676 | // v = x = x binop expr; |
| 5677 | // v = x = expr binop x; |
| 5678 | auto *AtomicBinOp = |
| 5679 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5680 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5681 | V = AtomicBinOp->getLHS(); |
| 5682 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5683 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5684 | if (Checker.checkStatement( |
| 5685 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5686 | diag::note_omp_atomic_update)) |
| 5687 | return StmtError(); |
| 5688 | E = Checker.getExpr(); |
| 5689 | X = Checker.getX(); |
| 5690 | UE = Checker.getUpdateExpr(); |
| 5691 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5692 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5693 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5694 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5695 | ErrorRange = AtomicBody->getSourceRange(); |
| 5696 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5697 | : AtomicBody->getExprLoc(); |
| 5698 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5699 | : AtomicBody->getSourceRange(); |
| 5700 | ErrorFound = NotAnAssignmentOp; |
| 5701 | } |
| 5702 | if (ErrorFound != NoError) { |
| 5703 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5704 | << ErrorRange; |
| 5705 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5706 | return StmtError(); |
| 5707 | } else if (CurContext->isDependentContext()) { |
| 5708 | UE = V = E = X = nullptr; |
| 5709 | } |
| 5710 | } else { |
| 5711 | // If clause is a capture: |
| 5712 | // { v = x; x = expr; } |
| 5713 | // { v = x; x++; } |
| 5714 | // { v = x; x--; } |
| 5715 | // { v = x; ++x; } |
| 5716 | // { v = x; --x; } |
| 5717 | // { v = x; x binop= expr; } |
| 5718 | // { v = x; x = x binop expr; } |
| 5719 | // { v = x; x = expr binop x; } |
| 5720 | // { x++; v = x; } |
| 5721 | // { x--; v = x; } |
| 5722 | // { ++x; v = x; } |
| 5723 | // { --x; v = x; } |
| 5724 | // { x binop= expr; v = x; } |
| 5725 | // { x = x binop expr; v = x; } |
| 5726 | // { x = expr binop x; v = x; } |
| 5727 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5728 | // Check that this is { expr1; expr2; } |
| 5729 | if (CS->size() == 2) { |
| 5730 | auto *First = CS->body_front(); |
| 5731 | auto *Second = CS->body_back(); |
| 5732 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5733 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5734 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5735 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5736 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5737 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5738 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5739 | BinaryOperator *BinOp = nullptr; |
| 5740 | if (IsUpdateExprFound) { |
| 5741 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5742 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5743 | } |
| 5744 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5745 | // { v = x; x++; } |
| 5746 | // { v = x; x--; } |
| 5747 | // { v = x; ++x; } |
| 5748 | // { v = x; --x; } |
| 5749 | // { v = x; x binop= expr; } |
| 5750 | // { v = x; x = x binop expr; } |
| 5751 | // { v = x; x = expr binop x; } |
| 5752 | // Check that the first expression has form v = x. |
| 5753 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5754 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5755 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5756 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5757 | IsUpdateExprFound = XId == PossibleXId; |
| 5758 | if (IsUpdateExprFound) { |
| 5759 | V = BinOp->getLHS(); |
| 5760 | X = Checker.getX(); |
| 5761 | E = Checker.getExpr(); |
| 5762 | UE = Checker.getUpdateExpr(); |
| 5763 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5764 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5765 | } |
| 5766 | } |
| 5767 | if (!IsUpdateExprFound) { |
| 5768 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5769 | BinOp = nullptr; |
| 5770 | if (IsUpdateExprFound) { |
| 5771 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5772 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5773 | } |
| 5774 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5775 | // { x++; v = x; } |
| 5776 | // { x--; v = x; } |
| 5777 | // { ++x; v = x; } |
| 5778 | // { --x; v = x; } |
| 5779 | // { x binop= expr; v = x; } |
| 5780 | // { x = x binop expr; v = x; } |
| 5781 | // { x = expr binop x; v = x; } |
| 5782 | // Check that the second expression has form v = x. |
| 5783 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5784 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5785 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5786 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5787 | IsUpdateExprFound = XId == PossibleXId; |
| 5788 | if (IsUpdateExprFound) { |
| 5789 | V = BinOp->getLHS(); |
| 5790 | X = Checker.getX(); |
| 5791 | E = Checker.getExpr(); |
| 5792 | UE = Checker.getUpdateExpr(); |
| 5793 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5794 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5795 | } |
| 5796 | } |
| 5797 | } |
| 5798 | if (!IsUpdateExprFound) { |
| 5799 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5800 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5801 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5802 | if (!FirstExpr || !SecondExpr || |
| 5803 | !(FirstExpr->isInstantiationDependent() || |
| 5804 | SecondExpr->isInstantiationDependent())) { |
| 5805 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5806 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5807 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5808 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5809 | : First->getLocStart(); |
| 5810 | NoteRange = ErrorRange = FirstBinOp |
| 5811 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5812 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5813 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5814 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5815 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5816 | ErrorFound = NotAnAssignmentOp; |
| 5817 | NoteLoc = ErrorLoc = SecondBinOp |
| 5818 | ? SecondBinOp->getOperatorLoc() |
| 5819 | : Second->getLocStart(); |
| 5820 | NoteRange = ErrorRange = |
| 5821 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5822 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5823 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5824 | auto *PossibleXRHSInFirst = |
| 5825 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5826 | auto *PossibleXLHSInSecond = |
| 5827 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5828 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5829 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5830 | /*Canonical=*/true); |
| 5831 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5832 | /*Canonical=*/true); |
| 5833 | IsUpdateExprFound = X1Id == X2Id; |
| 5834 | if (IsUpdateExprFound) { |
| 5835 | V = FirstBinOp->getLHS(); |
| 5836 | X = SecondBinOp->getLHS(); |
| 5837 | E = SecondBinOp->getRHS(); |
| 5838 | UE = nullptr; |
| 5839 | IsXLHSInRHSPart = false; |
| 5840 | IsPostfixUpdate = true; |
| 5841 | } else { |
| 5842 | ErrorFound = NotASpecificExpression; |
| 5843 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5844 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5845 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5846 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5847 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5848 | } |
| 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | } else { |
| 5853 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5854 | NoteRange = ErrorRange = |
| 5855 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5856 | ErrorFound = NotTwoSubstatements; |
| 5857 | } |
| 5858 | } else { |
| 5859 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5860 | NoteRange = ErrorRange = |
| 5861 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5862 | ErrorFound = NotACompoundStatement; |
| 5863 | } |
| 5864 | if (ErrorFound != NoError) { |
| 5865 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5866 | << ErrorRange; |
| 5867 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5868 | return StmtError(); |
| 5869 | } else if (CurContext->isDependentContext()) { |
| 5870 | UE = V = E = X = nullptr; |
| 5871 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5872 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5873 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5874 | |
| 5875 | getCurFunction()->setHasBranchProtectedScope(); |
| 5876 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5877 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5878 | X, V, E, UE, IsXLHSInRHSPart, |
| 5879 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5882 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5883 | Stmt *AStmt, |
| 5884 | SourceLocation StartLoc, |
| 5885 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5886 | if (!AStmt) |
| 5887 | return StmtError(); |
| 5888 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5889 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5890 | // 1.2.2 OpenMP Language Terminology |
| 5891 | // Structured block - An executable statement with a single entry at the |
| 5892 | // top and a single exit at the bottom. |
| 5893 | // The point of exit cannot be a branch out of the structured block. |
| 5894 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5895 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5896 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5897 | // OpenMP [2.16, Nesting of Regions] |
| 5898 | // If specified, a teams construct must be contained within a target |
| 5899 | // construct. That target construct must contain no statements or directives |
| 5900 | // outside of the teams construct. |
| 5901 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5902 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5903 | bool OMPTeamsFound = true; |
| 5904 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5905 | auto I = CS->body_begin(); |
| 5906 | while (I != CS->body_end()) { |
| 5907 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5908 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5909 | OMPTeamsFound = false; |
| 5910 | break; |
| 5911 | } |
| 5912 | ++I; |
| 5913 | } |
| 5914 | assert(I != CS->body_end() && "Not found statement"); |
| 5915 | S = *I; |
| 5916 | } |
| 5917 | if (!OMPTeamsFound) { |
| 5918 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5919 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5920 | diag::note_omp_nested_teams_construct_here); |
| 5921 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5922 | << isa<OMPExecutableDirective>(S); |
| 5923 | return StmtError(); |
| 5924 | } |
| 5925 | } |
| 5926 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5927 | getCurFunction()->setHasBranchProtectedScope(); |
| 5928 | |
| 5929 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5930 | } |
| 5931 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5932 | StmtResult |
| 5933 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5934 | Stmt *AStmt, SourceLocation StartLoc, |
| 5935 | SourceLocation EndLoc) { |
| 5936 | if (!AStmt) |
| 5937 | return StmtError(); |
| 5938 | |
| 5939 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5940 | // 1.2.2 OpenMP Language Terminology |
| 5941 | // Structured block - An executable statement with a single entry at the |
| 5942 | // top and a single exit at the bottom. |
| 5943 | // The point of exit cannot be a branch out of the structured block. |
| 5944 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5945 | CS->getCapturedDecl()->setNothrow(); |
| 5946 | |
| 5947 | getCurFunction()->setHasBranchProtectedScope(); |
| 5948 | |
| 5949 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5950 | AStmt); |
| 5951 | } |
| 5952 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5953 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5954 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5955 | SourceLocation EndLoc, |
| 5956 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5957 | if (!AStmt) |
| 5958 | return StmtError(); |
| 5959 | |
| 5960 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5961 | // 1.2.2 OpenMP Language Terminology |
| 5962 | // Structured block - An executable statement with a single entry at the |
| 5963 | // top and a single exit at the bottom. |
| 5964 | // The point of exit cannot be a branch out of the structured block. |
| 5965 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5966 | CS->getCapturedDecl()->setNothrow(); |
| 5967 | |
| 5968 | OMPLoopDirective::HelperExprs B; |
| 5969 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5970 | // define the nested loops number. |
| 5971 | unsigned NestedLoopCount = |
| 5972 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5973 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5974 | VarsWithImplicitDSA, B); |
| 5975 | if (NestedLoopCount == 0) |
| 5976 | return StmtError(); |
| 5977 | |
| 5978 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5979 | "omp target parallel for loop exprs were not built"); |
| 5980 | |
| 5981 | if (!CurContext->isDependentContext()) { |
| 5982 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5983 | for (auto C : Clauses) { |
| 5984 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5985 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5986 | B.NumIterations, *this, CurScope)) |
| 5987 | return StmtError(); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | getCurFunction()->setHasBranchProtectedScope(); |
| 5992 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5993 | NestedLoopCount, Clauses, AStmt, |
| 5994 | B, DSAStack->isCancelRegion()); |
| 5995 | } |
| 5996 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5997 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5998 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5999 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6000 | I != E; ++I) { |
| 6001 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6002 | return true; |
| 6003 | } |
| 6004 | } |
| 6005 | |
| 6006 | return false; |
| 6007 | } |
| 6008 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6009 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6010 | Stmt *AStmt, |
| 6011 | SourceLocation StartLoc, |
| 6012 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6013 | if (!AStmt) |
| 6014 | return StmtError(); |
| 6015 | |
| 6016 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6017 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6018 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6019 | // At least one map clause must appear on the directive. |
| 6020 | if (!HasMapClause(Clauses)) { |
| 6021 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6022 | getOpenMPDirectiveName(OMPD_target_data); |
| 6023 | return StmtError(); |
| 6024 | } |
| 6025 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6026 | getCurFunction()->setHasBranchProtectedScope(); |
| 6027 | |
| 6028 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6029 | AStmt); |
| 6030 | } |
| 6031 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6032 | StmtResult |
| 6033 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6034 | SourceLocation StartLoc, |
| 6035 | SourceLocation EndLoc) { |
| 6036 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6037 | // At least one map clause must appear on the directive. |
| 6038 | if (!HasMapClause(Clauses)) { |
| 6039 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6040 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6041 | return StmtError(); |
| 6042 | } |
| 6043 | |
| 6044 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6045 | Clauses); |
| 6046 | } |
| 6047 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6048 | StmtResult |
| 6049 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6050 | SourceLocation StartLoc, |
| 6051 | SourceLocation EndLoc) { |
| 6052 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6053 | // At least one map clause must appear on the directive. |
| 6054 | if (!HasMapClause(Clauses)) { |
| 6055 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6056 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6057 | return StmtError(); |
| 6058 | } |
| 6059 | |
| 6060 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6061 | } |
| 6062 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6063 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6064 | Stmt *AStmt, SourceLocation StartLoc, |
| 6065 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6066 | if (!AStmt) |
| 6067 | return StmtError(); |
| 6068 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6069 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6070 | // 1.2.2 OpenMP Language Terminology |
| 6071 | // Structured block - An executable statement with a single entry at the |
| 6072 | // top and a single exit at the bottom. |
| 6073 | // The point of exit cannot be a branch out of the structured block. |
| 6074 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6075 | CS->getCapturedDecl()->setNothrow(); |
| 6076 | |
| 6077 | getCurFunction()->setHasBranchProtectedScope(); |
| 6078 | |
| 6079 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6080 | } |
| 6081 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6082 | StmtResult |
| 6083 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6084 | SourceLocation EndLoc, |
| 6085 | OpenMPDirectiveKind CancelRegion) { |
| 6086 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6087 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6088 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6089 | << getOpenMPDirectiveName(CancelRegion); |
| 6090 | return StmtError(); |
| 6091 | } |
| 6092 | if (DSAStack->isParentNowaitRegion()) { |
| 6093 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6094 | return StmtError(); |
| 6095 | } |
| 6096 | if (DSAStack->isParentOrderedRegion()) { |
| 6097 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6098 | return StmtError(); |
| 6099 | } |
| 6100 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6101 | CancelRegion); |
| 6102 | } |
| 6103 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6104 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6105 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6106 | SourceLocation EndLoc, |
| 6107 | OpenMPDirectiveKind CancelRegion) { |
| 6108 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6109 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6110 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6111 | << getOpenMPDirectiveName(CancelRegion); |
| 6112 | return StmtError(); |
| 6113 | } |
| 6114 | if (DSAStack->isParentNowaitRegion()) { |
| 6115 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6116 | return StmtError(); |
| 6117 | } |
| 6118 | if (DSAStack->isParentOrderedRegion()) { |
| 6119 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6120 | return StmtError(); |
| 6121 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6122 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6123 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6124 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6127 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6128 | ArrayRef<OMPClause *> Clauses) { |
| 6129 | OMPClause *PrevClause = nullptr; |
| 6130 | bool ErrorFound = false; |
| 6131 | for (auto *C : Clauses) { |
| 6132 | if (C->getClauseKind() == OMPC_grainsize || |
| 6133 | C->getClauseKind() == OMPC_num_tasks) { |
| 6134 | if (!PrevClause) |
| 6135 | PrevClause = C; |
| 6136 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6137 | S.Diag(C->getLocStart(), |
| 6138 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6139 | << getOpenMPClauseName(C->getClauseKind()) |
| 6140 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6141 | S.Diag(PrevClause->getLocStart(), |
| 6142 | diag::note_omp_previous_grainsize_num_tasks) |
| 6143 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6144 | ErrorFound = true; |
| 6145 | } |
| 6146 | } |
| 6147 | } |
| 6148 | return ErrorFound; |
| 6149 | } |
| 6150 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6151 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6152 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6153 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6154 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6155 | if (!AStmt) |
| 6156 | return StmtError(); |
| 6157 | |
| 6158 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6159 | OMPLoopDirective::HelperExprs B; |
| 6160 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6161 | // define the nested loops number. |
| 6162 | unsigned NestedLoopCount = |
| 6163 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6164 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6165 | VarsWithImplicitDSA, B); |
| 6166 | if (NestedLoopCount == 0) |
| 6167 | return StmtError(); |
| 6168 | |
| 6169 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6170 | "omp for loop exprs were not built"); |
| 6171 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6172 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6173 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6174 | // not appear on the same taskloop directive. |
| 6175 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6176 | return StmtError(); |
| 6177 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6178 | getCurFunction()->setHasBranchProtectedScope(); |
| 6179 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6180 | NestedLoopCount, Clauses, AStmt, B); |
| 6181 | } |
| 6182 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6183 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6184 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6185 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6186 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6187 | if (!AStmt) |
| 6188 | return StmtError(); |
| 6189 | |
| 6190 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6191 | OMPLoopDirective::HelperExprs B; |
| 6192 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6193 | // define the nested loops number. |
| 6194 | unsigned NestedLoopCount = |
| 6195 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6196 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6197 | VarsWithImplicitDSA, B); |
| 6198 | if (NestedLoopCount == 0) |
| 6199 | return StmtError(); |
| 6200 | |
| 6201 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6202 | "omp for loop exprs were not built"); |
| 6203 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6204 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6205 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6206 | // not appear on the same taskloop directive. |
| 6207 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6208 | return StmtError(); |
| 6209 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6210 | getCurFunction()->setHasBranchProtectedScope(); |
| 6211 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6212 | NestedLoopCount, Clauses, AStmt, B); |
| 6213 | } |
| 6214 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6215 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6216 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6217 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6218 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6219 | if (!AStmt) |
| 6220 | return StmtError(); |
| 6221 | |
| 6222 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6223 | OMPLoopDirective::HelperExprs B; |
| 6224 | // In presence of clause 'collapse' with number of loops, it will |
| 6225 | // define the nested loops number. |
| 6226 | unsigned NestedLoopCount = |
| 6227 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6228 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6229 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6230 | if (NestedLoopCount == 0) |
| 6231 | return StmtError(); |
| 6232 | |
| 6233 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6234 | "omp for loop exprs were not built"); |
| 6235 | |
| 6236 | getCurFunction()->setHasBranchProtectedScope(); |
| 6237 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6238 | NestedLoopCount, Clauses, AStmt, B); |
| 6239 | } |
| 6240 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6241 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6242 | SourceLocation StartLoc, |
| 6243 | SourceLocation LParenLoc, |
| 6244 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6245 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6246 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6247 | case OMPC_final: |
| 6248 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6249 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6250 | case OMPC_num_threads: |
| 6251 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6252 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6253 | case OMPC_safelen: |
| 6254 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6255 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6256 | case OMPC_simdlen: |
| 6257 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6258 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6259 | case OMPC_collapse: |
| 6260 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6261 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6262 | case OMPC_ordered: |
| 6263 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6264 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6265 | case OMPC_device: |
| 6266 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6267 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6268 | case OMPC_num_teams: |
| 6269 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6270 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6271 | case OMPC_thread_limit: |
| 6272 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6273 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6274 | case OMPC_priority: |
| 6275 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6276 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6277 | case OMPC_grainsize: |
| 6278 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6279 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6280 | case OMPC_num_tasks: |
| 6281 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6282 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6283 | case OMPC_hint: |
| 6284 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6285 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6286 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6287 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6288 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6289 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6290 | case OMPC_private: |
| 6291 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6292 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6293 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6294 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6295 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6296 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6297 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6298 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6299 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6300 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6301 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6302 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6303 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6304 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6305 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6306 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6307 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6308 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6309 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6310 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6311 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6312 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6313 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6314 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6315 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6316 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6317 | llvm_unreachable("Clause is not allowed."); |
| 6318 | } |
| 6319 | return Res; |
| 6320 | } |
| 6321 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6322 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6323 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6324 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6325 | SourceLocation NameModifierLoc, |
| 6326 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6327 | SourceLocation EndLoc) { |
| 6328 | Expr *ValExpr = Condition; |
| 6329 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6330 | !Condition->isInstantiationDependent() && |
| 6331 | !Condition->containsUnexpandedParameterPack()) { |
| 6332 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6333 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6334 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6335 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6336 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6337 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6340 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6341 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6342 | } |
| 6343 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6344 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6345 | SourceLocation StartLoc, |
| 6346 | SourceLocation LParenLoc, |
| 6347 | SourceLocation EndLoc) { |
| 6348 | Expr *ValExpr = Condition; |
| 6349 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6350 | !Condition->isInstantiationDependent() && |
| 6351 | !Condition->containsUnexpandedParameterPack()) { |
| 6352 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6353 | Condition->getExprLoc(), Condition); |
| 6354 | if (Val.isInvalid()) |
| 6355 | return nullptr; |
| 6356 | |
| 6357 | ValExpr = Val.get(); |
| 6358 | } |
| 6359 | |
| 6360 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6361 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6362 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6363 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6364 | if (!Op) |
| 6365 | return ExprError(); |
| 6366 | |
| 6367 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6368 | public: |
| 6369 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6370 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6371 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6372 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6373 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6374 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6375 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6376 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6377 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6378 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6379 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6380 | QualType T, |
| 6381 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6382 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6383 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6384 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6385 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6386 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6387 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6388 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6389 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6390 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6391 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6392 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6393 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6394 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6395 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6396 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6397 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6398 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6399 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6400 | llvm_unreachable("conversion functions are permitted"); |
| 6401 | } |
| 6402 | } ConvertDiagnoser; |
| 6403 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6404 | } |
| 6405 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6406 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6407 | OpenMPClauseKind CKind, |
| 6408 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6409 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6410 | !ValExpr->isInstantiationDependent()) { |
| 6411 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6412 | ExprResult Value = |
| 6413 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6414 | if (Value.isInvalid()) |
| 6415 | return false; |
| 6416 | |
| 6417 | ValExpr = Value.get(); |
| 6418 | // The expression must evaluate to a non-negative integer value. |
| 6419 | llvm::APSInt Result; |
| 6420 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6421 | Result.isSigned() && |
| 6422 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6423 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6424 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6425 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6426 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6427 | return false; |
| 6428 | } |
| 6429 | } |
| 6430 | return true; |
| 6431 | } |
| 6432 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6433 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6434 | SourceLocation StartLoc, |
| 6435 | SourceLocation LParenLoc, |
| 6436 | SourceLocation EndLoc) { |
| 6437 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6438 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6439 | // OpenMP [2.5, Restrictions] |
| 6440 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6441 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6442 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6443 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6444 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6445 | return new (Context) |
| 6446 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6447 | } |
| 6448 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6449 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6450 | OpenMPClauseKind CKind, |
| 6451 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6452 | if (!E) |
| 6453 | return ExprError(); |
| 6454 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6455 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6456 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6457 | llvm::APSInt Result; |
| 6458 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6459 | if (ICE.isInvalid()) |
| 6460 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6461 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6462 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6463 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6464 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6465 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6466 | return ExprError(); |
| 6467 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6468 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6469 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6470 | << E->getSourceRange(); |
| 6471 | return ExprError(); |
| 6472 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6473 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6474 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6475 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6476 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6477 | return ICE; |
| 6478 | } |
| 6479 | |
| 6480 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6481 | SourceLocation LParenLoc, |
| 6482 | SourceLocation EndLoc) { |
| 6483 | // OpenMP [2.8.1, simd construct, Description] |
| 6484 | // The parameter of the safelen clause must be a constant |
| 6485 | // positive integer expression. |
| 6486 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6487 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6488 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6489 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6490 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6491 | } |
| 6492 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6493 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6494 | SourceLocation LParenLoc, |
| 6495 | SourceLocation EndLoc) { |
| 6496 | // OpenMP [2.8.1, simd construct, Description] |
| 6497 | // The parameter of the simdlen clause must be a constant |
| 6498 | // positive integer expression. |
| 6499 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6500 | if (Simdlen.isInvalid()) |
| 6501 | return nullptr; |
| 6502 | return new (Context) |
| 6503 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6504 | } |
| 6505 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6506 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6507 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6508 | SourceLocation LParenLoc, |
| 6509 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6510 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6511 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6512 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6513 | // The parameter of the collapse clause must be a constant |
| 6514 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6515 | ExprResult NumForLoopsResult = |
| 6516 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6517 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6518 | return nullptr; |
| 6519 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6520 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6521 | } |
| 6522 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6523 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6524 | SourceLocation EndLoc, |
| 6525 | SourceLocation LParenLoc, |
| 6526 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6527 | // OpenMP [2.7.1, loop construct, Description] |
| 6528 | // OpenMP [2.8.1, simd construct, Description] |
| 6529 | // OpenMP [2.9.6, distribute construct, Description] |
| 6530 | // The parameter of the ordered clause must be a constant |
| 6531 | // positive integer expression if any. |
| 6532 | if (NumForLoops && LParenLoc.isValid()) { |
| 6533 | ExprResult NumForLoopsResult = |
| 6534 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6535 | if (NumForLoopsResult.isInvalid()) |
| 6536 | return nullptr; |
| 6537 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6538 | } else |
| 6539 | NumForLoops = nullptr; |
| 6540 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6541 | return new (Context) |
| 6542 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6543 | } |
| 6544 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6545 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6546 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6547 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6548 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6549 | switch (Kind) { |
| 6550 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6551 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6552 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6553 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6554 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6555 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6556 | Res = ActOnOpenMPProcBindClause( |
| 6557 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6558 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6559 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6560 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6561 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6562 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6563 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6564 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6565 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6566 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6567 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6568 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6569 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6570 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6571 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6572 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6573 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6574 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6575 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6576 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6577 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6578 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6579 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6580 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6581 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6582 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6583 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6584 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6585 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6586 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6587 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6588 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6589 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6590 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6591 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6592 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6593 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6594 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6595 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6596 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6597 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6598 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6599 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6600 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6601 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6602 | llvm_unreachable("Clause is not allowed."); |
| 6603 | } |
| 6604 | return Res; |
| 6605 | } |
| 6606 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6607 | static std::string |
| 6608 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6609 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6610 | std::string Values; |
| 6611 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6612 | unsigned Skipped = Exclude.size(); |
| 6613 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6614 | for (unsigned i = First; i < Last; ++i) { |
| 6615 | if (std::find(S, E, i) != E) { |
| 6616 | --Skipped; |
| 6617 | continue; |
| 6618 | } |
| 6619 | Values += "'"; |
| 6620 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6621 | Values += "'"; |
| 6622 | if (i == Bound - Skipped) |
| 6623 | Values += " or "; |
| 6624 | else if (i != Bound + 1 - Skipped) |
| 6625 | Values += ", "; |
| 6626 | } |
| 6627 | return Values; |
| 6628 | } |
| 6629 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6630 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6631 | SourceLocation KindKwLoc, |
| 6632 | SourceLocation StartLoc, |
| 6633 | SourceLocation LParenLoc, |
| 6634 | SourceLocation EndLoc) { |
| 6635 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6636 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6637 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6638 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6639 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6640 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6641 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6642 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6643 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6644 | switch (Kind) { |
| 6645 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6646 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6647 | break; |
| 6648 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6649 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6650 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6651 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6652 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6653 | break; |
| 6654 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6655 | return new (Context) |
| 6656 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6657 | } |
| 6658 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6659 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6660 | SourceLocation KindKwLoc, |
| 6661 | SourceLocation StartLoc, |
| 6662 | SourceLocation LParenLoc, |
| 6663 | SourceLocation EndLoc) { |
| 6664 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6665 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6666 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6667 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6668 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6669 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6670 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6671 | return new (Context) |
| 6672 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6673 | } |
| 6674 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6675 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6676 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6677 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6678 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6679 | SourceLocation EndLoc) { |
| 6680 | OMPClause *Res = nullptr; |
| 6681 | switch (Kind) { |
| 6682 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6683 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6684 | assert(Argument.size() == NumberOfElements && |
| 6685 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6686 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6687 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6688 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6689 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6690 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6691 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6692 | break; |
| 6693 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6694 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6695 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6696 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6697 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6698 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6699 | case OMPC_dist_schedule: |
| 6700 | Res = ActOnOpenMPDistScheduleClause( |
| 6701 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6702 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6703 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6704 | case OMPC_defaultmap: |
| 6705 | enum { Modifier, DefaultmapKind }; |
| 6706 | Res = ActOnOpenMPDefaultmapClause( |
| 6707 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6708 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6709 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6710 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6711 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6712 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6713 | case OMPC_num_threads: |
| 6714 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6715 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6716 | case OMPC_collapse: |
| 6717 | case OMPC_default: |
| 6718 | case OMPC_proc_bind: |
| 6719 | case OMPC_private: |
| 6720 | case OMPC_firstprivate: |
| 6721 | case OMPC_lastprivate: |
| 6722 | case OMPC_shared: |
| 6723 | case OMPC_reduction: |
| 6724 | case OMPC_linear: |
| 6725 | case OMPC_aligned: |
| 6726 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6727 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6728 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6729 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6730 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6731 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6732 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6733 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6734 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6735 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6736 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6737 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6738 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6739 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6740 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6741 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6742 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6743 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6744 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6745 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6746 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6747 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6748 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6749 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6750 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6751 | case OMPC_unknown: |
| 6752 | llvm_unreachable("Clause is not allowed."); |
| 6753 | } |
| 6754 | return Res; |
| 6755 | } |
| 6756 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6757 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6758 | OpenMPScheduleClauseModifier M2, |
| 6759 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6760 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6761 | SmallVector<unsigned, 2> Excluded; |
| 6762 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6763 | Excluded.push_back(M2); |
| 6764 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6765 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6766 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6767 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6768 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6769 | << getListOfPossibleValues(OMPC_schedule, |
| 6770 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6771 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6772 | Excluded) |
| 6773 | << getOpenMPClauseName(OMPC_schedule); |
| 6774 | return true; |
| 6775 | } |
| 6776 | return false; |
| 6777 | } |
| 6778 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6779 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6780 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6781 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6782 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6783 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6784 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6785 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6786 | return nullptr; |
| 6787 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6788 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6789 | // but not both. |
| 6790 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6791 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6792 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6793 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6794 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6795 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6796 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6797 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6798 | return nullptr; |
| 6799 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6800 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6801 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6802 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6803 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6804 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6805 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6806 | Exclude); |
| 6807 | } else { |
| 6808 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6809 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6810 | } |
| 6811 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6812 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6813 | return nullptr; |
| 6814 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6815 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6816 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6817 | // schedule(guided). |
| 6818 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6819 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6820 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6821 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6822 | diag::err_omp_schedule_nonmonotonic_static); |
| 6823 | return nullptr; |
| 6824 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6825 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6826 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6827 | if (ChunkSize) { |
| 6828 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6829 | !ChunkSize->isInstantiationDependent() && |
| 6830 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6831 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6832 | ExprResult Val = |
| 6833 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6834 | if (Val.isInvalid()) |
| 6835 | return nullptr; |
| 6836 | |
| 6837 | ValExpr = Val.get(); |
| 6838 | |
| 6839 | // OpenMP [2.7.1, Restrictions] |
| 6840 | // chunk_size must be a loop invariant integer expression with a positive |
| 6841 | // value. |
| 6842 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6843 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6844 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6845 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6846 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6847 | return nullptr; |
| 6848 | } |
| 6849 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 6850 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6851 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 6852 | HelperValStmt = |
| 6853 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 6854 | /*NumDecls=*/1), |
| 6855 | SourceLocation(), SourceLocation()); |
| 6856 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6861 | return new (Context) |
| 6862 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6863 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6864 | } |
| 6865 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6866 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6867 | SourceLocation StartLoc, |
| 6868 | SourceLocation EndLoc) { |
| 6869 | OMPClause *Res = nullptr; |
| 6870 | switch (Kind) { |
| 6871 | case OMPC_ordered: |
| 6872 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6873 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6874 | case OMPC_nowait: |
| 6875 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6876 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6877 | case OMPC_untied: |
| 6878 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6879 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6880 | case OMPC_mergeable: |
| 6881 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6882 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6883 | case OMPC_read: |
| 6884 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6885 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6886 | case OMPC_write: |
| 6887 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6888 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6889 | case OMPC_update: |
| 6890 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6891 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6892 | case OMPC_capture: |
| 6893 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6894 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6895 | case OMPC_seq_cst: |
| 6896 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6897 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6898 | case OMPC_threads: |
| 6899 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6900 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6901 | case OMPC_simd: |
| 6902 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6903 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6904 | case OMPC_nogroup: |
| 6905 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6906 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6907 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6908 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6909 | case OMPC_num_threads: |
| 6910 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6911 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6912 | case OMPC_collapse: |
| 6913 | case OMPC_schedule: |
| 6914 | case OMPC_private: |
| 6915 | case OMPC_firstprivate: |
| 6916 | case OMPC_lastprivate: |
| 6917 | case OMPC_shared: |
| 6918 | case OMPC_reduction: |
| 6919 | case OMPC_linear: |
| 6920 | case OMPC_aligned: |
| 6921 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6922 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6923 | case OMPC_default: |
| 6924 | case OMPC_proc_bind: |
| 6925 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6926 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6927 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6928 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6929 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6930 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6931 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6932 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6933 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6934 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6935 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6936 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6937 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6938 | case OMPC_unknown: |
| 6939 | llvm_unreachable("Clause is not allowed."); |
| 6940 | } |
| 6941 | return Res; |
| 6942 | } |
| 6943 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6944 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6945 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6946 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6947 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6948 | } |
| 6949 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6950 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6951 | SourceLocation EndLoc) { |
| 6952 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6953 | } |
| 6954 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6955 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6956 | SourceLocation EndLoc) { |
| 6957 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6958 | } |
| 6959 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6960 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6961 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6962 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6963 | } |
| 6964 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6965 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6966 | SourceLocation EndLoc) { |
| 6967 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6968 | } |
| 6969 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6970 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6971 | SourceLocation EndLoc) { |
| 6972 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6973 | } |
| 6974 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6975 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6976 | SourceLocation EndLoc) { |
| 6977 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6978 | } |
| 6979 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6980 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6981 | SourceLocation EndLoc) { |
| 6982 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6983 | } |
| 6984 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6985 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6986 | SourceLocation EndLoc) { |
| 6987 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6988 | } |
| 6989 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6990 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6991 | SourceLocation EndLoc) { |
| 6992 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6993 | } |
| 6994 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6995 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6996 | SourceLocation EndLoc) { |
| 6997 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6998 | } |
| 6999 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7000 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7001 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7002 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7003 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7004 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7005 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7006 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7007 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7008 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7009 | switch (Kind) { |
| 7010 | case OMPC_private: |
| 7011 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7012 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7013 | case OMPC_firstprivate: |
| 7014 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7015 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7016 | case OMPC_lastprivate: |
| 7017 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7018 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7019 | case OMPC_shared: |
| 7020 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7021 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7022 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7023 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7024 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7025 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7026 | case OMPC_linear: |
| 7027 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7028 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7029 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7030 | case OMPC_aligned: |
| 7031 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7032 | ColonLoc, EndLoc); |
| 7033 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7034 | case OMPC_copyin: |
| 7035 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7036 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7037 | case OMPC_copyprivate: |
| 7038 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7039 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7040 | case OMPC_flush: |
| 7041 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7042 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7043 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7044 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7045 | StartLoc, LParenLoc, EndLoc); |
| 7046 | break; |
| 7047 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7048 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7049 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7050 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7051 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7052 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7053 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7054 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7055 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7056 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7057 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7058 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7059 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7060 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7061 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7062 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7063 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7064 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7065 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7066 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7067 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7068 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7069 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7070 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7071 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7072 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7073 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7074 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7075 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7076 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7077 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7078 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7079 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7080 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7081 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7082 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7083 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7084 | llvm_unreachable("Clause is not allowed."); |
| 7085 | } |
| 7086 | return Res; |
| 7087 | } |
| 7088 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7089 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7090 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7091 | ExprResult Res = BuildDeclRefExpr( |
| 7092 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7093 | if (!Res.isUsable()) |
| 7094 | return ExprError(); |
| 7095 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7096 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7097 | if (!Res.isUsable()) |
| 7098 | return ExprError(); |
| 7099 | } |
| 7100 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7101 | Res = DefaultLvalueConversion(Res.get()); |
| 7102 | if (!Res.isUsable()) |
| 7103 | return ExprError(); |
| 7104 | } |
| 7105 | return Res; |
| 7106 | } |
| 7107 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7108 | static std::pair<ValueDecl *, bool> |
| 7109 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7110 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7111 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7112 | RefExpr->containsUnexpandedParameterPack()) |
| 7113 | return std::make_pair(nullptr, true); |
| 7114 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7115 | // OpenMP [3.1, C/C++] |
| 7116 | // A list item is a variable name. |
| 7117 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7118 | // A variable that is part of another variable (as an array or |
| 7119 | // structure element) cannot appear in a private clause. |
| 7120 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7121 | enum { |
| 7122 | NoArrayExpr = -1, |
| 7123 | ArraySubscript = 0, |
| 7124 | OMPArraySection = 1 |
| 7125 | } IsArrayExpr = NoArrayExpr; |
| 7126 | if (AllowArraySection) { |
| 7127 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7128 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7129 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7130 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7131 | RefExpr = Base; |
| 7132 | IsArrayExpr = ArraySubscript; |
| 7133 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7134 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7135 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7136 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7137 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7138 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7139 | RefExpr = Base; |
| 7140 | IsArrayExpr = OMPArraySection; |
| 7141 | } |
| 7142 | } |
| 7143 | ELoc = RefExpr->getExprLoc(); |
| 7144 | ERange = RefExpr->getSourceRange(); |
| 7145 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7146 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7147 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7148 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7149 | (S.getCurrentThisType().isNull() || !ME || |
| 7150 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7151 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7152 | if (IsArrayExpr != NoArrayExpr) |
| 7153 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7154 | << ERange; |
| 7155 | else { |
| 7156 | S.Diag(ELoc, |
| 7157 | AllowArraySection |
| 7158 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7159 | : diag::err_omp_expected_var_name_member_expr) |
| 7160 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7161 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7162 | return std::make_pair(nullptr, false); |
| 7163 | } |
| 7164 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7165 | } |
| 7166 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7167 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7168 | SourceLocation StartLoc, |
| 7169 | SourceLocation LParenLoc, |
| 7170 | SourceLocation EndLoc) { |
| 7171 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7172 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7173 | for (auto &RefExpr : VarList) { |
| 7174 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7175 | SourceLocation ELoc; |
| 7176 | SourceRange ERange; |
| 7177 | Expr *SimpleRefExpr = RefExpr; |
| 7178 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7179 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7180 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7181 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7182 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7183 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7184 | ValueDecl *D = Res.first; |
| 7185 | if (!D) |
| 7186 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7187 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7188 | QualType Type = D->getType(); |
| 7189 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7190 | |
| 7191 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7192 | // A variable that appears in a private clause must not have an incomplete |
| 7193 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7194 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7195 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7196 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7197 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7198 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7199 | // in a Construct] |
| 7200 | // Variables with the predetermined data-sharing attributes may not be |
| 7201 | // listed in data-sharing attributes clauses, except for the cases |
| 7202 | // listed below. For these exceptions only, listing a predetermined |
| 7203 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7204 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7205 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7206 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7207 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7208 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7209 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7210 | continue; |
| 7211 | } |
| 7212 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7213 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7214 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7215 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7216 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7217 | << getOpenMPClauseName(OMPC_private) << Type |
| 7218 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7219 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7220 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7221 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7222 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7223 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7224 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7225 | continue; |
| 7226 | } |
| 7227 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7228 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7229 | // A variable of class type (or array thereof) that appears in a private |
| 7230 | // clause requires an accessible, unambiguous default constructor for the |
| 7231 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7232 | // Generate helper private variable and initialize it with the default |
| 7233 | // value. The address of the original variable is replaced by the address of |
| 7234 | // the new private variable in CodeGen. This new variable is not added to |
| 7235 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7236 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7237 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7238 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7239 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7240 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7241 | if (VDPrivate->isInvalidDecl()) |
| 7242 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7243 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7244 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7245 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7246 | DeclRefExpr *Ref = nullptr; |
| 7247 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7248 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7249 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7250 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7251 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7252 | } |
| 7253 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7254 | if (Vars.empty()) |
| 7255 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7256 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7257 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7258 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7259 | } |
| 7260 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7261 | namespace { |
| 7262 | class DiagsUninitializedSeveretyRAII { |
| 7263 | private: |
| 7264 | DiagnosticsEngine &Diags; |
| 7265 | SourceLocation SavedLoc; |
| 7266 | bool IsIgnored; |
| 7267 | |
| 7268 | public: |
| 7269 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7270 | bool IsIgnored) |
| 7271 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7272 | if (!IsIgnored) { |
| 7273 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7274 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7275 | } |
| 7276 | } |
| 7277 | ~DiagsUninitializedSeveretyRAII() { |
| 7278 | if (!IsIgnored) |
| 7279 | Diags.popMappings(SavedLoc); |
| 7280 | } |
| 7281 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7282 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7283 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7284 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7285 | SourceLocation StartLoc, |
| 7286 | SourceLocation LParenLoc, |
| 7287 | SourceLocation EndLoc) { |
| 7288 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7289 | SmallVector<Expr *, 8> PrivateCopies; |
| 7290 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7291 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7292 | bool IsImplicitClause = |
| 7293 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7294 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7295 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7296 | for (auto &RefExpr : VarList) { |
| 7297 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7298 | SourceLocation ELoc; |
| 7299 | SourceRange ERange; |
| 7300 | Expr *SimpleRefExpr = RefExpr; |
| 7301 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7302 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7303 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7304 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7305 | PrivateCopies.push_back(nullptr); |
| 7306 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7307 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7308 | ValueDecl *D = Res.first; |
| 7309 | if (!D) |
| 7310 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7311 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7312 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7313 | QualType Type = D->getType(); |
| 7314 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7315 | |
| 7316 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7317 | // A variable that appears in a private clause must not have an incomplete |
| 7318 | // type or a reference type. |
| 7319 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7320 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7321 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7322 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7323 | |
| 7324 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7325 | // 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] | 7326 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7327 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7328 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7329 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7330 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7331 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7332 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7333 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7334 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7335 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7336 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7337 | // A list item that specifies a given variable may not appear in more |
| 7338 | // than one clause on the same directive, except that a variable may be |
| 7339 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7340 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7341 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7342 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7343 | << getOpenMPClauseName(DVar.CKind) |
| 7344 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7345 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7346 | continue; |
| 7347 | } |
| 7348 | |
| 7349 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7350 | // in a Construct] |
| 7351 | // Variables with the predetermined data-sharing attributes may not be |
| 7352 | // listed in data-sharing attributes clauses, except for the cases |
| 7353 | // listed below. For these exceptions only, listing a predetermined |
| 7354 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7355 | // the variable's predetermined data-sharing attributes. |
| 7356 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7357 | // in a Construct, C/C++, p.2] |
| 7358 | // Variables with const-qualified type having no mutable member may be |
| 7359 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7360 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7361 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7362 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7363 | << getOpenMPClauseName(DVar.CKind) |
| 7364 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7365 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7366 | continue; |
| 7367 | } |
| 7368 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7369 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7370 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7371 | // A list item that is private within a parallel region must not appear |
| 7372 | // in a firstprivate clause on a worksharing construct if any of the |
| 7373 | // worksharing regions arising from the worksharing construct ever bind |
| 7374 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7375 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7376 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7377 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7378 | if (DVar.CKind != OMPC_shared && |
| 7379 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7380 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7381 | Diag(ELoc, diag::err_omp_required_access) |
| 7382 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7383 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7384 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7385 | continue; |
| 7386 | } |
| 7387 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7388 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7389 | // A list item that appears in a reduction clause of a parallel construct |
| 7390 | // must not appear in a firstprivate clause on a worksharing or task |
| 7391 | // construct if any of the worksharing or task regions arising from the |
| 7392 | // worksharing or task construct ever bind to any of the parallel regions |
| 7393 | // arising from the parallel construct. |
| 7394 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7395 | // A list item that appears in a reduction clause in worksharing |
| 7396 | // construct must not appear in a firstprivate clause in a task construct |
| 7397 | // encountered during execution of any of the worksharing regions arising |
| 7398 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7399 | if (CurrDir == OMPD_task) { |
| 7400 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7401 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7402 | [](OpenMPDirectiveKind K) -> bool { |
| 7403 | return isOpenMPParallelDirective(K) || |
| 7404 | isOpenMPWorksharingDirective(K); |
| 7405 | }, |
| 7406 | false); |
| 7407 | if (DVar.CKind == OMPC_reduction && |
| 7408 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7409 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7410 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7411 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7412 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7413 | continue; |
| 7414 | } |
| 7415 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7416 | |
| 7417 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7418 | // A list item that is private within a teams region must not appear in a |
| 7419 | // firstprivate clause on a distribute construct if any of the distribute |
| 7420 | // regions arising from the distribute construct ever bind to any of the |
| 7421 | // teams regions arising from the teams construct. |
| 7422 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7423 | // A list item that appears in a reduction clause of a teams construct |
| 7424 | // must not appear in a firstprivate clause on a distribute construct if |
| 7425 | // any of the distribute regions arising from the distribute construct |
| 7426 | // ever bind to any of the teams regions arising from the teams construct. |
| 7427 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7428 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7429 | // both. |
| 7430 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7431 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7432 | [](OpenMPDirectiveKind K) -> bool { |
| 7433 | return isOpenMPTeamsDirective(K); |
| 7434 | }, |
| 7435 | false); |
| 7436 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7437 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7438 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7439 | continue; |
| 7440 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7441 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7442 | [](OpenMPDirectiveKind K) -> bool { |
| 7443 | return isOpenMPTeamsDirective(K); |
| 7444 | }, |
| 7445 | false); |
| 7446 | if (DVar.CKind == OMPC_reduction && |
| 7447 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7448 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7449 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7450 | continue; |
| 7451 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7452 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7453 | if (DVar.CKind == OMPC_lastprivate) { |
| 7454 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7455 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7456 | continue; |
| 7457 | } |
| 7458 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7461 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7462 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7463 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7464 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7465 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7466 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7467 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7468 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7469 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7470 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7471 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7472 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7473 | continue; |
| 7474 | } |
| 7475 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7476 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7477 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7478 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7479 | // Generate helper private variable and initialize it with the value of the |
| 7480 | // original variable. The address of the original variable is replaced by |
| 7481 | // the address of the new private variable in the CodeGen. This new variable |
| 7482 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7483 | // original variable for proper diagnostics and variable capturing. |
| 7484 | Expr *VDInitRefExpr = nullptr; |
| 7485 | // For arrays generate initializer for single element and replace it by the |
| 7486 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7487 | if (Type->isArrayType()) { |
| 7488 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7489 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7490 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7491 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7492 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7493 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7494 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7495 | InitializedEntity Entity = |
| 7496 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7497 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7498 | |
| 7499 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7500 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7501 | if (Result.isInvalid()) |
| 7502 | VDPrivate->setInvalidDecl(); |
| 7503 | else |
| 7504 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7505 | // Remove temp variable declaration. |
| 7506 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7507 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7508 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7509 | ".firstprivate.temp"); |
| 7510 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7511 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7512 | AddInitializerToDecl(VDPrivate, |
| 7513 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7514 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7515 | } |
| 7516 | if (VDPrivate->isInvalidDecl()) { |
| 7517 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7518 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7519 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7520 | } |
| 7521 | continue; |
| 7522 | } |
| 7523 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7524 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7525 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7526 | RefExpr->getExprLoc()); |
| 7527 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7528 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7529 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7530 | Ref = TopDVar.PrivateCopy; |
| 7531 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7532 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7533 | if (!IsOpenMPCapturedDecl(D)) |
| 7534 | ExprCaptures.push_back(Ref->getDecl()); |
| 7535 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7536 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7537 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7538 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7539 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7540 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7541 | } |
| 7542 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7543 | if (Vars.empty()) |
| 7544 | return nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7545 | Stmt *PreInit = nullptr; |
| 7546 | if (!ExprCaptures.empty()) { |
| 7547 | PreInit = new (Context) |
| 7548 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 7549 | ExprCaptures.size()), |
| 7550 | SourceLocation(), SourceLocation()); |
| 7551 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7552 | |
| 7553 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7554 | Vars, PrivateCopies, Inits, PreInit); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7555 | } |
| 7556 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7557 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7558 | SourceLocation StartLoc, |
| 7559 | SourceLocation LParenLoc, |
| 7560 | SourceLocation EndLoc) { |
| 7561 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7562 | SmallVector<Expr *, 8> SrcExprs; |
| 7563 | SmallVector<Expr *, 8> DstExprs; |
| 7564 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7565 | SmallVector<Decl *, 4> ExprCaptures; |
| 7566 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7567 | for (auto &RefExpr : VarList) { |
| 7568 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7569 | SourceLocation ELoc; |
| 7570 | SourceRange ERange; |
| 7571 | Expr *SimpleRefExpr = RefExpr; |
| 7572 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7573 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7574 | // It will be analyzed later. |
| 7575 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7576 | SrcExprs.push_back(nullptr); |
| 7577 | DstExprs.push_back(nullptr); |
| 7578 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7579 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7580 | ValueDecl *D = Res.first; |
| 7581 | if (!D) |
| 7582 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7583 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7584 | QualType Type = D->getType(); |
| 7585 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7586 | |
| 7587 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7588 | // A variable that appears in a lastprivate clause must not have an |
| 7589 | // incomplete type or a reference type. |
| 7590 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7591 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7592 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7593 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7594 | |
| 7595 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7596 | // in a Construct] |
| 7597 | // Variables with the predetermined data-sharing attributes may not be |
| 7598 | // listed in data-sharing attributes clauses, except for the cases |
| 7599 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7600 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7601 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7602 | DVar.CKind != OMPC_firstprivate && |
| 7603 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7604 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7605 | << getOpenMPClauseName(DVar.CKind) |
| 7606 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7607 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7608 | continue; |
| 7609 | } |
| 7610 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7611 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7612 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7613 | // A list item that is private within a parallel region, or that appears in |
| 7614 | // the reduction clause of a parallel construct, must not appear in a |
| 7615 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7616 | // worksharing regions ever binds to any of the corresponding parallel |
| 7617 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7618 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7619 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7620 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7621 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7622 | if (DVar.CKind != OMPC_shared) { |
| 7623 | Diag(ELoc, diag::err_omp_required_access) |
| 7624 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7625 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7626 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7627 | continue; |
| 7628 | } |
| 7629 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7630 | |
| 7631 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7632 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7633 | // both. |
| 7634 | if (CurrDir == OMPD_distribute) { |
| 7635 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 7636 | if (DVar.CKind == OMPC_firstprivate) { |
| 7637 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7638 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7639 | continue; |
| 7640 | } |
| 7641 | } |
| 7642 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7643 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7644 | // A variable of class type (or array thereof) that appears in a |
| 7645 | // lastprivate clause requires an accessible, unambiguous default |
| 7646 | // constructor for the class type, unless the list item is also specified |
| 7647 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7648 | // A variable of class type (or array thereof) that appears in a |
| 7649 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7650 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7651 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7652 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7653 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7654 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7655 | auto *PseudoSrcExpr = |
| 7656 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7657 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7658 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7659 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7660 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7661 | // For arrays generate assignment operation for single element and replace |
| 7662 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7663 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7664 | PseudoDstExpr, PseudoSrcExpr); |
| 7665 | if (AssignmentOp.isInvalid()) |
| 7666 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7667 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7668 | /*DiscardedValue=*/true); |
| 7669 | if (AssignmentOp.isInvalid()) |
| 7670 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7671 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7672 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7673 | if (!VD) { |
| 7674 | if (TopDVar.CKind == OMPC_firstprivate) |
| 7675 | Ref = TopDVar.PrivateCopy; |
| 7676 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7677 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7678 | if (!IsOpenMPCapturedDecl(D)) |
| 7679 | ExprCaptures.push_back(Ref->getDecl()); |
| 7680 | } |
| 7681 | if (TopDVar.CKind == OMPC_firstprivate || |
| 7682 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 7683 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7684 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 7685 | if (!RefRes.isUsable()) |
| 7686 | continue; |
| 7687 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7688 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 7689 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7690 | if (!PostUpdateRes.isUsable()) |
| 7691 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 7692 | ExprPostUpdates.push_back( |
| 7693 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7694 | } |
| 7695 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7696 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7697 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 7698 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7699 | SrcExprs.push_back(PseudoSrcExpr); |
| 7700 | DstExprs.push_back(PseudoDstExpr); |
| 7701 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7702 | } |
| 7703 | |
| 7704 | if (Vars.empty()) |
| 7705 | return nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7706 | Stmt *PreInit = nullptr; |
| 7707 | if (!ExprCaptures.empty()) { |
| 7708 | PreInit = new (Context) |
| 7709 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 7710 | ExprCaptures.size()), |
| 7711 | SourceLocation(), SourceLocation()); |
| 7712 | } |
| 7713 | Expr *PostUpdate = nullptr; |
| 7714 | if (!ExprPostUpdates.empty()) { |
| 7715 | for (auto *E : ExprPostUpdates) { |
| 7716 | ExprResult PostUpdateRes = |
| 7717 | PostUpdate |
| 7718 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 7719 | : E; |
| 7720 | PostUpdate = PostUpdateRes.get(); |
| 7721 | } |
| 7722 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7723 | |
| 7724 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7725 | Vars, SrcExprs, DstExprs, AssignmentOps, |
| 7726 | PreInit, PostUpdate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7727 | } |
| 7728 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7729 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7730 | SourceLocation StartLoc, |
| 7731 | SourceLocation LParenLoc, |
| 7732 | SourceLocation EndLoc) { |
| 7733 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7734 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7735 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7736 | SourceLocation ELoc; |
| 7737 | SourceRange ERange; |
| 7738 | Expr *SimpleRefExpr = RefExpr; |
| 7739 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7740 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7741 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7742 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7743 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7744 | ValueDecl *D = Res.first; |
| 7745 | if (!D) |
| 7746 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7747 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7748 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7749 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7750 | // in a Construct] |
| 7751 | // Variables with the predetermined data-sharing attributes may not be |
| 7752 | // listed in data-sharing attributes clauses, except for the cases |
| 7753 | // listed below. For these exceptions only, listing a predetermined |
| 7754 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7755 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7756 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7757 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7758 | DVar.RefExpr) { |
| 7759 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7760 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7761 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7762 | continue; |
| 7763 | } |
| 7764 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7765 | DeclRefExpr *Ref = nullptr; |
| 7766 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7767 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7768 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| 7769 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7770 | } |
| 7771 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7772 | if (Vars.empty()) |
| 7773 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7774 | |
| 7775 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7776 | } |
| 7777 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7778 | namespace { |
| 7779 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7780 | DSAStackTy *Stack; |
| 7781 | |
| 7782 | public: |
| 7783 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7784 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7785 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7786 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7787 | return false; |
| 7788 | if (DVar.CKind != OMPC_unknown) |
| 7789 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7790 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7791 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7792 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7793 | return true; |
| 7794 | return false; |
| 7795 | } |
| 7796 | return false; |
| 7797 | } |
| 7798 | bool VisitStmt(Stmt *S) { |
| 7799 | for (auto Child : S->children()) { |
| 7800 | if (Child && Visit(Child)) |
| 7801 | return true; |
| 7802 | } |
| 7803 | return false; |
| 7804 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7805 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7806 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7807 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7808 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7809 | namespace { |
| 7810 | // Transform MemberExpression for specified FieldDecl of current class to |
| 7811 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 7812 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 7813 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 7814 | ValueDecl *Field; |
| 7815 | DeclRefExpr *CapturedExpr; |
| 7816 | |
| 7817 | public: |
| 7818 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 7819 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 7820 | |
| 7821 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 7822 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 7823 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7824 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7825 | return CapturedExpr; |
| 7826 | } |
| 7827 | return BaseTransform::TransformMemberExpr(E); |
| 7828 | } |
| 7829 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 7830 | }; |
| 7831 | } // namespace |
| 7832 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7833 | template <typename T> |
| 7834 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 7835 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 7836 | for (auto &Set : Lookups) { |
| 7837 | for (auto *D : Set) { |
| 7838 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 7839 | return Res; |
| 7840 | } |
| 7841 | } |
| 7842 | return T(); |
| 7843 | } |
| 7844 | |
| 7845 | static ExprResult |
| 7846 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 7847 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 7848 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 7849 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 7850 | if (ReductionIdScopeSpec.isInvalid()) |
| 7851 | return ExprError(); |
| 7852 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 7853 | if (S) { |
| 7854 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 7855 | Lookup.suppressDiagnostics(); |
| 7856 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 7857 | auto *D = Lookup.getRepresentativeDecl(); |
| 7858 | do { |
| 7859 | S = S->getParent(); |
| 7860 | } while (S && !S->isDeclScope(D)); |
| 7861 | if (S) |
| 7862 | S = S->getParent(); |
| 7863 | Lookups.push_back(UnresolvedSet<8>()); |
| 7864 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 7865 | Lookup.clear(); |
| 7866 | } |
| 7867 | } else if (auto *ULE = |
| 7868 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 7869 | Lookups.push_back(UnresolvedSet<8>()); |
| 7870 | Decl *PrevD = nullptr; |
| 7871 | for(auto *D : ULE->decls()) { |
| 7872 | if (D == PrevD) |
| 7873 | Lookups.push_back(UnresolvedSet<8>()); |
| 7874 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 7875 | Lookups.back().addDecl(DRD); |
| 7876 | PrevD = D; |
| 7877 | } |
| 7878 | } |
| 7879 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 7880 | Ty->containsUnexpandedParameterPack() || |
| 7881 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 7882 | return !D->isInvalidDecl() && |
| 7883 | (D->getType()->isDependentType() || |
| 7884 | D->getType()->isInstantiationDependentType() || |
| 7885 | D->getType()->containsUnexpandedParameterPack()); |
| 7886 | })) { |
| 7887 | UnresolvedSet<8> ResSet; |
| 7888 | for (auto &Set : Lookups) { |
| 7889 | ResSet.append(Set.begin(), Set.end()); |
| 7890 | // The last item marks the end of all declarations at the specified scope. |
| 7891 | ResSet.addDecl(Set[Set.size() - 1]); |
| 7892 | } |
| 7893 | return UnresolvedLookupExpr::Create( |
| 7894 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 7895 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 7896 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 7897 | } |
| 7898 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7899 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 7900 | if (!D->isInvalidDecl() && |
| 7901 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 7902 | return D; |
| 7903 | return nullptr; |
| 7904 | })) |
| 7905 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7906 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7907 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 7908 | if (!D->isInvalidDecl() && |
| 7909 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 7910 | !Ty.isMoreQualifiedThan(D->getType())) |
| 7911 | return D; |
| 7912 | return nullptr; |
| 7913 | })) { |
| 7914 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 7915 | /*DetectVirtual=*/false); |
| 7916 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 7917 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 7918 | VD->getType().getUnqualifiedType()))) { |
| 7919 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 7920 | /*DiagID=*/0) != |
| 7921 | Sema::AR_inaccessible) { |
| 7922 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 7923 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7924 | } |
| 7925 | } |
| 7926 | } |
| 7927 | } |
| 7928 | if (ReductionIdScopeSpec.isSet()) { |
| 7929 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 7930 | return ExprError(); |
| 7931 | } |
| 7932 | return ExprEmpty(); |
| 7933 | } |
| 7934 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7935 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7936 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7937 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7938 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 7939 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7940 | auto DN = ReductionId.getName(); |
| 7941 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7942 | BinaryOperatorKind BOK = BO_Comma; |
| 7943 | |
| 7944 | // OpenMP [2.14.3.6, reduction clause] |
| 7945 | // C |
| 7946 | // reduction-identifier is either an identifier or one of the following |
| 7947 | // operators: +, -, *, &, |, ^, && and || |
| 7948 | // C++ |
| 7949 | // reduction-identifier is either an id-expression or one of the following |
| 7950 | // operators: +, -, *, &, |, ^, && and || |
| 7951 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7952 | switch (OOK) { |
| 7953 | case OO_Plus: |
| 7954 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7955 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7956 | break; |
| 7957 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7958 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7959 | break; |
| 7960 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7961 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7962 | break; |
| 7963 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7964 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7965 | break; |
| 7966 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7967 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7968 | break; |
| 7969 | case OO_AmpAmp: |
| 7970 | BOK = BO_LAnd; |
| 7971 | break; |
| 7972 | case OO_PipePipe: |
| 7973 | BOK = BO_LOr; |
| 7974 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7975 | case OO_New: |
| 7976 | case OO_Delete: |
| 7977 | case OO_Array_New: |
| 7978 | case OO_Array_Delete: |
| 7979 | case OO_Slash: |
| 7980 | case OO_Percent: |
| 7981 | case OO_Tilde: |
| 7982 | case OO_Exclaim: |
| 7983 | case OO_Equal: |
| 7984 | case OO_Less: |
| 7985 | case OO_Greater: |
| 7986 | case OO_LessEqual: |
| 7987 | case OO_GreaterEqual: |
| 7988 | case OO_PlusEqual: |
| 7989 | case OO_MinusEqual: |
| 7990 | case OO_StarEqual: |
| 7991 | case OO_SlashEqual: |
| 7992 | case OO_PercentEqual: |
| 7993 | case OO_CaretEqual: |
| 7994 | case OO_AmpEqual: |
| 7995 | case OO_PipeEqual: |
| 7996 | case OO_LessLess: |
| 7997 | case OO_GreaterGreater: |
| 7998 | case OO_LessLessEqual: |
| 7999 | case OO_GreaterGreaterEqual: |
| 8000 | case OO_EqualEqual: |
| 8001 | case OO_ExclaimEqual: |
| 8002 | case OO_PlusPlus: |
| 8003 | case OO_MinusMinus: |
| 8004 | case OO_Comma: |
| 8005 | case OO_ArrowStar: |
| 8006 | case OO_Arrow: |
| 8007 | case OO_Call: |
| 8008 | case OO_Subscript: |
| 8009 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8010 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8011 | case NUM_OVERLOADED_OPERATORS: |
| 8012 | llvm_unreachable("Unexpected reduction identifier"); |
| 8013 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8014 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8015 | if (II->isStr("max")) |
| 8016 | BOK = BO_GT; |
| 8017 | else if (II->isStr("min")) |
| 8018 | BOK = BO_LT; |
| 8019 | } |
| 8020 | break; |
| 8021 | } |
| 8022 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8023 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8024 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8025 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8026 | |
| 8027 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8028 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8029 | SmallVector<Expr *, 8> LHSs; |
| 8030 | SmallVector<Expr *, 8> RHSs; |
| 8031 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8032 | SmallVector<Decl *, 4> ExprCaptures; |
| 8033 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8034 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8035 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8036 | for (auto RefExpr : VarList) { |
| 8037 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8038 | // OpenMP [2.1, C/C++] |
| 8039 | // A list item is a variable or array section, subject to the restrictions |
| 8040 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8041 | // describing clauses and directives for which a list appears. |
| 8042 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8043 | // A variable that is part of another variable (as an array or |
| 8044 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8045 | if (!FirstIter && IR != ER) |
| 8046 | ++IR; |
| 8047 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8048 | SourceLocation ELoc; |
| 8049 | SourceRange ERange; |
| 8050 | Expr *SimpleRefExpr = RefExpr; |
| 8051 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8052 | /*AllowArraySection=*/true); |
| 8053 | if (Res.second) { |
| 8054 | // It will be analyzed later. |
| 8055 | Vars.push_back(RefExpr); |
| 8056 | Privates.push_back(nullptr); |
| 8057 | LHSs.push_back(nullptr); |
| 8058 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8059 | // Try to find 'declare reduction' corresponding construct before using |
| 8060 | // builtin/overloaded operators. |
| 8061 | QualType Type = Context.DependentTy; |
| 8062 | CXXCastPath BasePath; |
| 8063 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8064 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8065 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8066 | if (CurContext->isDependentContext() && |
| 8067 | (DeclareReductionRef.isUnset() || |
| 8068 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8069 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8070 | else |
| 8071 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8072 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8073 | ValueDecl *D = Res.first; |
| 8074 | if (!D) |
| 8075 | continue; |
| 8076 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8077 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8078 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8079 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8080 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8081 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8082 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8083 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8084 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8085 | Type = ATy->getElementType(); |
| 8086 | else |
| 8087 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8088 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8089 | } else |
| 8090 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8091 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8092 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8093 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8094 | // A variable that appears in a private clause must not have an incomplete |
| 8095 | // type or a reference type. |
| 8096 | if (RequireCompleteType(ELoc, Type, |
| 8097 | diag::err_omp_reduction_incomplete_type)) |
| 8098 | continue; |
| 8099 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8100 | // A list item that appears in a reduction clause must not be |
| 8101 | // const-qualified. |
| 8102 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8103 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8104 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8105 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8106 | bool IsDecl = !VD || |
| 8107 | VD->isThisDeclarationADefinition(Context) == |
| 8108 | VarDecl::DeclarationOnly; |
| 8109 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8110 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8111 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8112 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8113 | continue; |
| 8114 | } |
| 8115 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8116 | // If a list-item is a reference type then it must bind to the same object |
| 8117 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8118 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8119 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8120 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8121 | DSARefChecker Check(DSAStack); |
| 8122 | if (Check.Visit(VDDef->getInit())) { |
| 8123 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8124 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8125 | continue; |
| 8126 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8127 | } |
| 8128 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8129 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8130 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8131 | // in a Construct] |
| 8132 | // Variables with the predetermined data-sharing attributes may not be |
| 8133 | // listed in data-sharing attributes clauses, except for the cases |
| 8134 | // listed below. For these exceptions only, listing a predetermined |
| 8135 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8136 | // the variable's predetermined data-sharing attributes. |
| 8137 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8138 | // Any number of reduction clauses can be specified on the directive, |
| 8139 | // but a list item can appear only once in the reduction clauses for that |
| 8140 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8141 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8142 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8143 | if (DVar.CKind == OMPC_reduction) { |
| 8144 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8145 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8146 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8147 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8148 | } else if (DVar.CKind != OMPC_unknown) { |
| 8149 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8150 | << getOpenMPClauseName(DVar.CKind) |
| 8151 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8152 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8153 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8154 | } |
| 8155 | |
| 8156 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8157 | // A list item that appears in a reduction clause of a worksharing |
| 8158 | // construct must be shared in the parallel regions to which any of the |
| 8159 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8160 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8161 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8162 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8163 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8164 | if (DVar.CKind != OMPC_shared) { |
| 8165 | Diag(ELoc, diag::err_omp_required_access) |
| 8166 | << getOpenMPClauseName(OMPC_reduction) |
| 8167 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8168 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8169 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8170 | } |
| 8171 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8172 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8173 | // Try to find 'declare reduction' corresponding construct before using |
| 8174 | // builtin/overloaded operators. |
| 8175 | CXXCastPath BasePath; |
| 8176 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8177 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8178 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8179 | if (DeclareReductionRef.isInvalid()) |
| 8180 | continue; |
| 8181 | if (CurContext->isDependentContext() && |
| 8182 | (DeclareReductionRef.isUnset() || |
| 8183 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8184 | Vars.push_back(RefExpr); |
| 8185 | Privates.push_back(nullptr); |
| 8186 | LHSs.push_back(nullptr); |
| 8187 | RHSs.push_back(nullptr); |
| 8188 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8189 | continue; |
| 8190 | } |
| 8191 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8192 | // Not allowed reduction identifier is found. |
| 8193 | Diag(ReductionId.getLocStart(), |
| 8194 | diag::err_omp_unknown_reduction_identifier) |
| 8195 | << Type << ReductionIdRange; |
| 8196 | continue; |
| 8197 | } |
| 8198 | |
| 8199 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8200 | // The type of a list item that appears in a reduction clause must be valid |
| 8201 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8202 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8203 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8204 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8205 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8206 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8207 | if (DeclareReductionRef.isUnset()) { |
| 8208 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8209 | !(Type->isScalarType() || |
| 8210 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8211 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8212 | << getLangOpts().CPlusPlus; |
| 8213 | if (!ASE && !OASE) { |
| 8214 | bool IsDecl = !VD || |
| 8215 | VD->isThisDeclarationADefinition(Context) == |
| 8216 | VarDecl::DeclarationOnly; |
| 8217 | Diag(D->getLocation(), |
| 8218 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8219 | << D; |
| 8220 | } |
| 8221 | continue; |
| 8222 | } |
| 8223 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8224 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8225 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8226 | if (!ASE && !OASE) { |
| 8227 | bool IsDecl = !VD || |
| 8228 | VD->isThisDeclarationADefinition(Context) == |
| 8229 | VarDecl::DeclarationOnly; |
| 8230 | Diag(D->getLocation(), |
| 8231 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8232 | << D; |
| 8233 | } |
| 8234 | continue; |
| 8235 | } |
| 8236 | } |
| 8237 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8238 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8239 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8240 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8241 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8242 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8243 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8244 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8245 | (!ASE && |
| 8246 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8247 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8248 | // Create pseudo array type for private copy. The size for this array will |
| 8249 | // be generated during codegen. |
| 8250 | // For array subscripts or single variables Private Ty is the same as Type |
| 8251 | // (type of the variable or single array element). |
| 8252 | PrivateTy = Context.getVariableArrayType( |
| 8253 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8254 | Context.getSizeType(), VK_RValue), |
| 8255 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8256 | } else if (!ASE && !OASE && |
| 8257 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8258 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8259 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8260 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8261 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8262 | // Add initializer for private variable. |
| 8263 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8264 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8265 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8266 | if (DeclareReductionRef.isUsable()) { |
| 8267 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8268 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8269 | if (DRD->getInitializer()) { |
| 8270 | Init = DRDRef; |
| 8271 | RHSVD->setInit(DRDRef); |
| 8272 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8273 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8274 | } else { |
| 8275 | switch (BOK) { |
| 8276 | case BO_Add: |
| 8277 | case BO_Xor: |
| 8278 | case BO_Or: |
| 8279 | case BO_LOr: |
| 8280 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8281 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8282 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8283 | break; |
| 8284 | case BO_Mul: |
| 8285 | case BO_LAnd: |
| 8286 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8287 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8288 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8289 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8290 | break; |
| 8291 | case BO_And: { |
| 8292 | // '&' reduction op - initializer is '~0'. |
| 8293 | QualType OrigType = Type; |
| 8294 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8295 | Type = ComplexTy->getElementType(); |
| 8296 | if (Type->isRealFloatingType()) { |
| 8297 | llvm::APFloat InitValue = |
| 8298 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8299 | /*isIEEE=*/true); |
| 8300 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8301 | Type, ELoc); |
| 8302 | } else if (Type->isScalarType()) { |
| 8303 | auto Size = Context.getTypeSize(Type); |
| 8304 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8305 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8306 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8307 | } |
| 8308 | if (Init && OrigType->isAnyComplexType()) { |
| 8309 | // Init = 0xFFFF + 0xFFFFi; |
| 8310 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8311 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8312 | } |
| 8313 | Type = OrigType; |
| 8314 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8315 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8316 | case BO_LT: |
| 8317 | case BO_GT: { |
| 8318 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8319 | // the reduction list item type'. |
| 8320 | // 'max' reduction op - initializer is 'Least representable number in |
| 8321 | // the reduction list item type'. |
| 8322 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8323 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8324 | auto Size = Context.getTypeSize(Type); |
| 8325 | QualType IntTy = |
| 8326 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8327 | llvm::APInt InitValue = |
| 8328 | (BOK != BO_LT) |
| 8329 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8330 | : llvm::APInt::getMinValue(Size) |
| 8331 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8332 | : llvm::APInt::getMaxValue(Size); |
| 8333 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8334 | if (Type->isPointerType()) { |
| 8335 | // Cast to pointer type. |
| 8336 | auto CastExpr = BuildCStyleCastExpr( |
| 8337 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8338 | SourceLocation(), Init); |
| 8339 | if (CastExpr.isInvalid()) |
| 8340 | continue; |
| 8341 | Init = CastExpr.get(); |
| 8342 | } |
| 8343 | } else if (Type->isRealFloatingType()) { |
| 8344 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8345 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8346 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8347 | Type, ELoc); |
| 8348 | } |
| 8349 | break; |
| 8350 | } |
| 8351 | case BO_PtrMemD: |
| 8352 | case BO_PtrMemI: |
| 8353 | case BO_MulAssign: |
| 8354 | case BO_Div: |
| 8355 | case BO_Rem: |
| 8356 | case BO_Sub: |
| 8357 | case BO_Shl: |
| 8358 | case BO_Shr: |
| 8359 | case BO_LE: |
| 8360 | case BO_GE: |
| 8361 | case BO_EQ: |
| 8362 | case BO_NE: |
| 8363 | case BO_AndAssign: |
| 8364 | case BO_XorAssign: |
| 8365 | case BO_OrAssign: |
| 8366 | case BO_Assign: |
| 8367 | case BO_AddAssign: |
| 8368 | case BO_SubAssign: |
| 8369 | case BO_DivAssign: |
| 8370 | case BO_RemAssign: |
| 8371 | case BO_ShlAssign: |
| 8372 | case BO_ShrAssign: |
| 8373 | case BO_Comma: |
| 8374 | llvm_unreachable("Unexpected reduction operation"); |
| 8375 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8376 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8377 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8378 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8379 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8380 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8381 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8382 | if (RHSVD->isInvalidDecl()) |
| 8383 | continue; |
| 8384 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8385 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8386 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8387 | bool IsDecl = |
| 8388 | !VD || |
| 8389 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8390 | Diag(D->getLocation(), |
| 8391 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8392 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8393 | continue; |
| 8394 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8395 | // Store initializer for single element in private copy. Will be used during |
| 8396 | // codegen. |
| 8397 | PrivateVD->setInit(RHSVD->getInit()); |
| 8398 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8399 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8400 | ExprResult ReductionOp; |
| 8401 | if (DeclareReductionRef.isUsable()) { |
| 8402 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8403 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8404 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8405 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8406 | if (!BasePath.empty()) { |
| 8407 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8408 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8409 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8410 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8411 | &BasePath, LHS.get()->getValueKind()); |
| 8412 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8413 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8414 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8415 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8416 | FunctionProtoType::ExtProtoInfo EPI; |
| 8417 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8418 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8419 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8420 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8421 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8422 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8423 | ReductionOp = new (Context) |
| 8424 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8425 | } else { |
| 8426 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8427 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8428 | if (ReductionOp.isUsable()) { |
| 8429 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8430 | ReductionOp = |
| 8431 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8432 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8433 | } else { |
| 8434 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8435 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8436 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8437 | ReductionOp = |
| 8438 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8439 | BO_Assign, LHSDRE, ConditionalOp); |
| 8440 | } |
| 8441 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8442 | } |
| 8443 | if (ReductionOp.isInvalid()) |
| 8444 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8445 | } |
| 8446 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8447 | DeclRefExpr *Ref = nullptr; |
| 8448 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 8449 | if (!VD) { |
| 8450 | if (ASE || OASE) { |
| 8451 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8452 | VarsExpr = |
| 8453 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8454 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8455 | } else { |
| 8456 | VarsExpr = Ref = |
| 8457 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8458 | if (!IsOpenMPCapturedDecl(D)) { |
| 8459 | ExprCaptures.push_back(Ref->getDecl()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8460 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8461 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8462 | if (!RefRes.isUsable()) |
| 8463 | continue; |
| 8464 | ExprResult PostUpdateRes = |
| 8465 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8466 | SimpleRefExpr, RefRes.get()); |
| 8467 | if (!PostUpdateRes.isUsable()) |
| 8468 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8469 | ExprPostUpdates.push_back( |
| 8470 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8471 | } |
| 8472 | } |
| 8473 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8474 | } |
| 8475 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8476 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8477 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8478 | LHSs.push_back(LHSDRE); |
| 8479 | RHSs.push_back(RHSDRE); |
| 8480 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | if (Vars.empty()) |
| 8484 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8485 | Stmt *PreInit = nullptr; |
| 8486 | if (!ExprCaptures.empty()) { |
| 8487 | PreInit = new (Context) |
| 8488 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 8489 | ExprCaptures.size()), |
| 8490 | SourceLocation(), SourceLocation()); |
| 8491 | } |
| 8492 | Expr *PostUpdate = nullptr; |
| 8493 | if (!ExprPostUpdates.empty()) { |
| 8494 | for (auto *E : ExprPostUpdates) { |
| 8495 | ExprResult PostUpdateRes = |
| 8496 | PostUpdate |
| 8497 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 8498 | : E; |
| 8499 | PostUpdate = PostUpdateRes.get(); |
| 8500 | } |
| 8501 | } |
| 8502 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8503 | return OMPReductionClause::Create( |
| 8504 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8505 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8506 | LHSs, RHSs, ReductionOps, PreInit, PostUpdate); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8507 | } |
| 8508 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8509 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8510 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8511 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8512 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8513 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8514 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8515 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8516 | SmallVector<Decl *, 4> ExprCaptures; |
| 8517 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8518 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8519 | LinKind == OMPC_LINEAR_unknown) { |
| 8520 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8521 | LinKind = OMPC_LINEAR_val; |
| 8522 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8523 | for (auto &RefExpr : VarList) { |
| 8524 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8525 | SourceLocation ELoc; |
| 8526 | SourceRange ERange; |
| 8527 | Expr *SimpleRefExpr = RefExpr; |
| 8528 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8529 | /*AllowArraySection=*/false); |
| 8530 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8531 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8532 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8533 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8534 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8535 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8536 | ValueDecl *D = Res.first; |
| 8537 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8538 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8539 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8540 | QualType Type = D->getType(); |
| 8541 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8542 | |
| 8543 | // OpenMP [2.14.3.7, linear clause] |
| 8544 | // A list-item cannot appear in more than one linear clause. |
| 8545 | // A list-item that appears in a linear clause cannot appear in any |
| 8546 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8547 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8548 | if (DVar.RefExpr) { |
| 8549 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8550 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8551 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8552 | continue; |
| 8553 | } |
| 8554 | |
| 8555 | // A variable must not have an incomplete type or a reference type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8556 | if (RequireCompleteType(ELoc, Type, |
| 8557 | diag::err_omp_linear_incomplete_type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8558 | continue; |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8559 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8560 | !Type->isReferenceType()) { |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8561 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8562 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8563 | continue; |
| 8564 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8565 | Type = Type.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8566 | |
| 8567 | // A list item must not be const-qualified. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8568 | if (Type.isConstant(Context)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8569 | Diag(ELoc, diag::err_omp_const_variable) |
| 8570 | << getOpenMPClauseName(OMPC_linear); |
| 8571 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8572 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8573 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8574 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8575 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8576 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8577 | continue; |
| 8578 | } |
| 8579 | |
| 8580 | // A list item must be of integral or pointer type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8581 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8582 | const auto *Ty = Type.getTypePtrOrNull(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8583 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8584 | !Ty->isPointerType())) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8585 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8586 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8587 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8588 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8589 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8590 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8591 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8592 | continue; |
| 8593 | } |
| 8594 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8595 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8596 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8597 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8598 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8599 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8600 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8601 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8602 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8603 | if (!VD) { |
| 8604 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8605 | if (!IsOpenMPCapturedDecl(D)) { |
| 8606 | ExprCaptures.push_back(Ref->getDecl()); |
| 8607 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8608 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8609 | if (!RefRes.isUsable()) |
| 8610 | continue; |
| 8611 | ExprResult PostUpdateRes = |
| 8612 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8613 | SimpleRefExpr, RefRes.get()); |
| 8614 | if (!PostUpdateRes.isUsable()) |
| 8615 | continue; |
| 8616 | ExprPostUpdates.push_back( |
| 8617 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8618 | } |
| 8619 | } |
| 8620 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8621 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8622 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8623 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8624 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8625 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8626 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 8627 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8628 | |
| 8629 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 8630 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8631 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8632 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8633 | } |
| 8634 | |
| 8635 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8636 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8637 | |
| 8638 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8639 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8640 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8641 | !Step->isInstantiationDependent() && |
| 8642 | !Step->containsUnexpandedParameterPack()) { |
| 8643 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8644 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8645 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8646 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8647 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8648 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8649 | // Build var to save the step value. |
| 8650 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8651 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8652 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8653 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8654 | ExprResult CalcStep = |
| 8655 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8656 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8657 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8658 | // Warn about zero linear step (it would be probably better specified as |
| 8659 | // making corresponding variables 'const'). |
| 8660 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8661 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8662 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8663 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8664 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8665 | if (!IsConstant && CalcStep.isUsable()) { |
| 8666 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8667 | // (This is not used if the number of iterations may be kfold-ed). |
| 8668 | CalcStepExpr = CalcStep.get(); |
| 8669 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8670 | } |
| 8671 | |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8672 | Stmt *PreInit = nullptr; |
| 8673 | if (!ExprCaptures.empty()) { |
| 8674 | PreInit = new (Context) |
| 8675 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 8676 | ExprCaptures.size()), |
| 8677 | SourceLocation(), SourceLocation()); |
| 8678 | } |
| 8679 | Expr *PostUpdate = nullptr; |
| 8680 | if (!ExprPostUpdates.empty()) { |
| 8681 | for (auto *E : ExprPostUpdates) { |
| 8682 | ExprResult PostUpdateRes = |
| 8683 | PostUpdate |
| 8684 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 8685 | : E; |
| 8686 | PostUpdate = PostUpdateRes.get(); |
| 8687 | } |
| 8688 | } |
| 8689 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8690 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8691 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8692 | StepExpr, CalcStepExpr, PreInit, PostUpdate); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8696 | Expr *NumIterations, Sema &SemaRef, |
| 8697 | Scope *S) { |
| 8698 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8699 | SmallVector<Expr *, 8> Updates; |
| 8700 | SmallVector<Expr *, 8> Finals; |
| 8701 | Expr *Step = Clause.getStep(); |
| 8702 | Expr *CalcStep = Clause.getCalcStep(); |
| 8703 | // OpenMP [2.14.3.7, linear clause] |
| 8704 | // If linear-step is not specified it is assumed to be 1. |
| 8705 | if (Step == nullptr) |
| 8706 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 8707 | else if (CalcStep) |
| 8708 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 8709 | bool HasErrors = false; |
| 8710 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8711 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8712 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8713 | for (auto &RefExpr : Clause.varlists()) { |
| 8714 | Expr *InitExpr = *CurInit; |
| 8715 | |
| 8716 | // Build privatized reference to the current linear var. |
| 8717 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8718 | Expr *CapturedRef; |
| 8719 | if (LinKind == OMPC_LINEAR_uval) |
| 8720 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8721 | else |
| 8722 | CapturedRef = |
| 8723 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8724 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8725 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8726 | |
| 8727 | // Build update: Var = InitExpr + IV * Step |
| 8728 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8729 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8730 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8731 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8732 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8733 | |
| 8734 | // Build final: Var = InitExpr + NumIterations * Step |
| 8735 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8736 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8737 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8738 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8739 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8740 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8741 | Updates.push_back(nullptr); |
| 8742 | Finals.push_back(nullptr); |
| 8743 | HasErrors = true; |
| 8744 | } else { |
| 8745 | Updates.push_back(Update.get()); |
| 8746 | Finals.push_back(Final.get()); |
| 8747 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 8748 | ++CurInit; |
| 8749 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8750 | } |
| 8751 | Clause.setUpdates(Updates); |
| 8752 | Clause.setFinals(Finals); |
| 8753 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8754 | } |
| 8755 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8756 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8757 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8758 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8759 | |
| 8760 | SmallVector<Expr *, 8> Vars; |
| 8761 | for (auto &RefExpr : VarList) { |
| 8762 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8763 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8764 | // It will be analyzed later. |
| 8765 | Vars.push_back(RefExpr); |
| 8766 | continue; |
| 8767 | } |
| 8768 | |
| 8769 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8770 | // OpenMP [2.1, C/C++] |
| 8771 | // A list item is a variable name. |
| 8772 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8773 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8774 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8775 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8776 | continue; |
| 8777 | } |
| 8778 | |
| 8779 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8780 | |
| 8781 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8782 | // The type of list items appearing in the aligned clause must be |
| 8783 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8784 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8785 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8786 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8787 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8788 | !Ty->isPointerType())) { |
| 8789 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8790 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8791 | bool IsDecl = |
| 8792 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8793 | Diag(VD->getLocation(), |
| 8794 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8795 | << VD; |
| 8796 | continue; |
| 8797 | } |
| 8798 | |
| 8799 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8800 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8801 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8802 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8803 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8804 | << getOpenMPClauseName(OMPC_aligned); |
| 8805 | continue; |
| 8806 | } |
| 8807 | |
| 8808 | Vars.push_back(DE); |
| 8809 | } |
| 8810 | |
| 8811 | // OpenMP [2.8.1, simd construct, Description] |
| 8812 | // The parameter of the aligned clause, alignment, must be a constant |
| 8813 | // positive integer expression. |
| 8814 | // If no optional parameter is specified, implementation-defined default |
| 8815 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8816 | if (Alignment != nullptr) { |
| 8817 | ExprResult AlignResult = |
| 8818 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8819 | if (AlignResult.isInvalid()) |
| 8820 | return nullptr; |
| 8821 | Alignment = AlignResult.get(); |
| 8822 | } |
| 8823 | if (Vars.empty()) |
| 8824 | return nullptr; |
| 8825 | |
| 8826 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8827 | EndLoc, Vars, Alignment); |
| 8828 | } |
| 8829 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8830 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8831 | SourceLocation StartLoc, |
| 8832 | SourceLocation LParenLoc, |
| 8833 | SourceLocation EndLoc) { |
| 8834 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8835 | SmallVector<Expr *, 8> SrcExprs; |
| 8836 | SmallVector<Expr *, 8> DstExprs; |
| 8837 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8838 | for (auto &RefExpr : VarList) { |
| 8839 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8840 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8841 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8842 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8843 | SrcExprs.push_back(nullptr); |
| 8844 | DstExprs.push_back(nullptr); |
| 8845 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8846 | continue; |
| 8847 | } |
| 8848 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8849 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8850 | // OpenMP [2.1, C/C++] |
| 8851 | // A list item is a variable name. |
| 8852 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8853 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8854 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8855 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8856 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8857 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8858 | continue; |
| 8859 | } |
| 8860 | |
| 8861 | Decl *D = DE->getDecl(); |
| 8862 | VarDecl *VD = cast<VarDecl>(D); |
| 8863 | |
| 8864 | QualType Type = VD->getType(); |
| 8865 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8866 | // It will be analyzed later. |
| 8867 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8868 | SrcExprs.push_back(nullptr); |
| 8869 | DstExprs.push_back(nullptr); |
| 8870 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8871 | continue; |
| 8872 | } |
| 8873 | |
| 8874 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8875 | // A list item that appears in a copyin clause must be threadprivate. |
| 8876 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8877 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8878 | << getOpenMPClauseName(OMPC_copyin) |
| 8879 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8880 | continue; |
| 8881 | } |
| 8882 | |
| 8883 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8884 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8885 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8886 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8887 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8888 | auto *SrcVD = |
| 8889 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8890 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8891 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8892 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8893 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8894 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8895 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8896 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8897 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8898 | // For arrays generate assignment operation for single element and replace |
| 8899 | // it by the original array element in CodeGen. |
| 8900 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8901 | PseudoDstExpr, PseudoSrcExpr); |
| 8902 | if (AssignmentOp.isInvalid()) |
| 8903 | continue; |
| 8904 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8905 | /*DiscardedValue=*/true); |
| 8906 | if (AssignmentOp.isInvalid()) |
| 8907 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8908 | |
| 8909 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8910 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8911 | SrcExprs.push_back(PseudoSrcExpr); |
| 8912 | DstExprs.push_back(PseudoDstExpr); |
| 8913 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8914 | } |
| 8915 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8916 | if (Vars.empty()) |
| 8917 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8918 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8919 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8920 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8921 | } |
| 8922 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8923 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8924 | SourceLocation StartLoc, |
| 8925 | SourceLocation LParenLoc, |
| 8926 | SourceLocation EndLoc) { |
| 8927 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8928 | SmallVector<Expr *, 8> SrcExprs; |
| 8929 | SmallVector<Expr *, 8> DstExprs; |
| 8930 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8931 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8932 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8933 | SourceLocation ELoc; |
| 8934 | SourceRange ERange; |
| 8935 | Expr *SimpleRefExpr = RefExpr; |
| 8936 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8937 | /*AllowArraySection=*/false); |
| 8938 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8939 | // It will be analyzed later. |
| 8940 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8941 | SrcExprs.push_back(nullptr); |
| 8942 | DstExprs.push_back(nullptr); |
| 8943 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8944 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8945 | ValueDecl *D = Res.first; |
| 8946 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8947 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8948 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8949 | QualType Type = D->getType(); |
| 8950 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8951 | |
| 8952 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8953 | // A list item that appears in a copyprivate clause may not appear in a |
| 8954 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8955 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 8956 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8957 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8958 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8959 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8960 | << getOpenMPClauseName(DVar.CKind) |
| 8961 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8962 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8963 | continue; |
| 8964 | } |
| 8965 | |
| 8966 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8967 | // All list items that appear in a copyprivate clause must be either |
| 8968 | // threadprivate or private in the enclosing context. |
| 8969 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8970 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8971 | if (DVar.CKind == OMPC_shared) { |
| 8972 | Diag(ELoc, diag::err_omp_required_access) |
| 8973 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8974 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8975 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8976 | continue; |
| 8977 | } |
| 8978 | } |
| 8979 | } |
| 8980 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8981 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8982 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8983 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8984 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8985 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8986 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8987 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8988 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8989 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8990 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8991 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8992 | continue; |
| 8993 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8994 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8995 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8996 | // A variable of class type (or array thereof) that appears in a |
| 8997 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8998 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8999 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9000 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9001 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9002 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9003 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9004 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9005 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9006 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9007 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9008 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9009 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 9010 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9011 | PseudoDstExpr, PseudoSrcExpr); |
| 9012 | if (AssignmentOp.isInvalid()) |
| 9013 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9014 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9015 | /*DiscardedValue=*/true); |
| 9016 | if (AssignmentOp.isInvalid()) |
| 9017 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9018 | |
| 9019 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9020 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9021 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9022 | Vars.push_back( |
| 9023 | VD ? RefExpr->IgnoreParens() |
| 9024 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9025 | SrcExprs.push_back(PseudoSrcExpr); |
| 9026 | DstExprs.push_back(PseudoDstExpr); |
| 9027 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9028 | } |
| 9029 | |
| 9030 | if (Vars.empty()) |
| 9031 | return nullptr; |
| 9032 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9033 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9034 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9035 | } |
| 9036 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9037 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9038 | SourceLocation StartLoc, |
| 9039 | SourceLocation LParenLoc, |
| 9040 | SourceLocation EndLoc) { |
| 9041 | if (VarList.empty()) |
| 9042 | return nullptr; |
| 9043 | |
| 9044 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9045 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9046 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9047 | OMPClause * |
| 9048 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9049 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9050 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9051 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9052 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9053 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9054 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9055 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9056 | return nullptr; |
| 9057 | } |
| 9058 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9059 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9060 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9061 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9062 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9063 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9064 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9065 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9066 | return nullptr; |
| 9067 | } |
| 9068 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9069 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9070 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9071 | if (DepKind == OMPC_DEPEND_sink) { |
| 9072 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9073 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9074 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9075 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9076 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9077 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9078 | DSAStack->getParentOrderedRegionParam()) { |
| 9079 | for (auto &RefExpr : VarList) { |
| 9080 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 9081 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 9082 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 9083 | // It will be analyzed later. |
| 9084 | Vars.push_back(RefExpr); |
| 9085 | continue; |
| 9086 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9087 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9088 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9089 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9090 | if (DepKind == OMPC_DEPEND_sink) { |
| 9091 | if (DepCounter >= TotalDepCount) { |
| 9092 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9093 | continue; |
| 9094 | } |
| 9095 | ++DepCounter; |
| 9096 | // OpenMP [2.13.9, Summary] |
| 9097 | // depend(dependence-type : vec), where dependence-type is: |
| 9098 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9099 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9100 | // where n is the value specified by the ordered clause in the loop |
| 9101 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9102 | // loop associated with the loop directive, and di is a constant |
| 9103 | // non-negative integer. |
| 9104 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9105 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9106 | if (!DE) { |
| 9107 | OverloadedOperatorKind OOK = OO_None; |
| 9108 | SourceLocation OOLoc; |
| 9109 | Expr *LHS, *RHS; |
| 9110 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9111 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9112 | OOLoc = BO->getOperatorLoc(); |
| 9113 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9114 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9115 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9116 | OOK = OCE->getOperator(); |
| 9117 | OOLoc = OCE->getOperatorLoc(); |
| 9118 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9119 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9120 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9121 | OOK = MCE->getMethodDecl() |
| 9122 | ->getNameInfo() |
| 9123 | .getName() |
| 9124 | .getCXXOverloadedOperator(); |
| 9125 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9126 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9127 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9128 | } else { |
| 9129 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 9130 | continue; |
| 9131 | } |
| 9132 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 9133 | if (!DE) { |
| 9134 | Diag(LHS->getExprLoc(), |
| 9135 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9136 | << DSAStack->getParentLoopControlVariable( |
| 9137 | DepCounter.getZExtValue()); |
| 9138 | continue; |
| 9139 | } |
| 9140 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 9141 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9142 | continue; |
| 9143 | } |
| 9144 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 9145 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9146 | if (Res.isInvalid()) |
| 9147 | continue; |
| 9148 | } |
| 9149 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 9150 | if (!CurContext->isDependentContext() && |
| 9151 | DSAStack->getParentOrderedRegionParam() && |
| 9152 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 9153 | Diag(DE->getExprLoc(), |
| 9154 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9155 | << DSAStack->getParentLoopControlVariable( |
| 9156 | DepCounter.getZExtValue()); |
| 9157 | continue; |
| 9158 | } |
| 9159 | } else { |
| 9160 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9161 | // A variable that is part of another variable (such as a field of a |
| 9162 | // structure) but is not an array element or an array section cannot |
| 9163 | // appear in a depend clause. |
| 9164 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9165 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9166 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9167 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9168 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9169 | (ASE && |
| 9170 | !ASE->getBase() |
| 9171 | ->getType() |
| 9172 | .getNonReferenceType() |
| 9173 | ->isPointerType() && |
| 9174 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9175 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9176 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9177 | continue; |
| 9178 | } |
| 9179 | } |
| 9180 | |
| 9181 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9182 | } |
| 9183 | |
| 9184 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9185 | TotalDepCount > VarList.size() && |
| 9186 | DSAStack->getParentOrderedRegionParam()) { |
| 9187 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9188 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9189 | } |
| 9190 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9191 | Vars.empty()) |
| 9192 | return nullptr; |
| 9193 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9194 | |
| 9195 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 9196 | DepLoc, ColonLoc, Vars); |
| 9197 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9198 | |
| 9199 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9200 | SourceLocation LParenLoc, |
| 9201 | SourceLocation EndLoc) { |
| 9202 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9203 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9204 | // OpenMP [2.9.1, Restrictions] |
| 9205 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9206 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9207 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9208 | return nullptr; |
| 9209 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9210 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9211 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9212 | |
| 9213 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9214 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9215 | if (!RD || RD->isInvalidDecl()) |
| 9216 | return true; |
| 9217 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 9218 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 9219 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 9220 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9221 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9222 | if (RD->isDynamicClass()) { |
| 9223 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9224 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9225 | return false; |
| 9226 | } |
| 9227 | auto *DC = RD; |
| 9228 | bool IsCorrect = true; |
| 9229 | for (auto *I : DC->decls()) { |
| 9230 | if (I) { |
| 9231 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9232 | if (MD->isStatic()) { |
| 9233 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9234 | SemaRef.Diag(MD->getLocation(), |
| 9235 | diag::note_omp_static_member_in_target); |
| 9236 | IsCorrect = false; |
| 9237 | } |
| 9238 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9239 | if (VD->isStaticDataMember()) { |
| 9240 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9241 | SemaRef.Diag(VD->getLocation(), |
| 9242 | diag::note_omp_static_member_in_target); |
| 9243 | IsCorrect = false; |
| 9244 | } |
| 9245 | } |
| 9246 | } |
| 9247 | } |
| 9248 | |
| 9249 | for (auto &I : RD->bases()) { |
| 9250 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9251 | I.getType()->getAsCXXRecordDecl())) |
| 9252 | IsCorrect = false; |
| 9253 | } |
| 9254 | return IsCorrect; |
| 9255 | } |
| 9256 | |
| 9257 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9258 | DSAStackTy *Stack, QualType QTy) { |
| 9259 | NamedDecl *ND; |
| 9260 | if (QTy->isIncompleteType(&ND)) { |
| 9261 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9262 | return false; |
| 9263 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 9264 | if (!RD->isInvalidDecl() && |
| 9265 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 9266 | return false; |
| 9267 | } |
| 9268 | return true; |
| 9269 | } |
| 9270 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9271 | /// \brief Return true if it can be proven that the provided array expression |
| 9272 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9273 | /// array whose base type is \a BaseQTy. |
| 9274 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9275 | const Expr *E, |
| 9276 | QualType BaseQTy) { |
| 9277 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9278 | |
| 9279 | // If this is an array subscript, it refers to the whole size if the size of |
| 9280 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9281 | // format of an array subscript if no colon is used. |
| 9282 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9283 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9284 | return ATy->getSize().getSExtValue() != 1; |
| 9285 | // Size can't be evaluated statically. |
| 9286 | return false; |
| 9287 | } |
| 9288 | |
| 9289 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9290 | auto *LowerBound = OASE->getLowerBound(); |
| 9291 | auto *Length = OASE->getLength(); |
| 9292 | |
| 9293 | // If there is a lower bound that does not evaluates to zero, we are not |
| 9294 | // convering the whole dimension. |
| 9295 | if (LowerBound) { |
| 9296 | llvm::APSInt ConstLowerBound; |
| 9297 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9298 | return false; // Can't get the integer value as a constant. |
| 9299 | if (ConstLowerBound.getSExtValue()) |
| 9300 | return true; |
| 9301 | } |
| 9302 | |
| 9303 | // If we don't have a length we covering the whole dimension. |
| 9304 | if (!Length) |
| 9305 | return false; |
| 9306 | |
| 9307 | // If the base is a pointer, we don't have a way to get the size of the |
| 9308 | // pointee. |
| 9309 | if (BaseQTy->isPointerType()) |
| 9310 | return false; |
| 9311 | |
| 9312 | // We can only check if the length is the same as the size of the dimension |
| 9313 | // if we have a constant array. |
| 9314 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9315 | if (!CATy) |
| 9316 | return false; |
| 9317 | |
| 9318 | llvm::APSInt ConstLength; |
| 9319 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9320 | return false; // Can't get the integer value as a constant. |
| 9321 | |
| 9322 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9323 | } |
| 9324 | |
| 9325 | // Return true if it can be proven that the provided array expression (array |
| 9326 | // section or array subscript) does NOT specify a single element of the array |
| 9327 | // whose base type is \a BaseQTy. |
| 9328 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 9329 | const Expr *E, |
| 9330 | QualType BaseQTy) { |
| 9331 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9332 | |
| 9333 | // An array subscript always refer to a single element. Also, an array section |
| 9334 | // assumes the format of an array subscript if no colon is used. |
| 9335 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9336 | return false; |
| 9337 | |
| 9338 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9339 | auto *Length = OASE->getLength(); |
| 9340 | |
| 9341 | // If we don't have a length we have to check if the array has unitary size |
| 9342 | // for this dimension. Also, we should always expect a length if the base type |
| 9343 | // is pointer. |
| 9344 | if (!Length) { |
| 9345 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9346 | return ATy->getSize().getSExtValue() != 1; |
| 9347 | // We cannot assume anything. |
| 9348 | return false; |
| 9349 | } |
| 9350 | |
| 9351 | // Check if the length evaluates to 1. |
| 9352 | llvm::APSInt ConstLength; |
| 9353 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9354 | return false; // Can't get the integer value as a constant. |
| 9355 | |
| 9356 | return ConstLength.getSExtValue() != 1; |
| 9357 | } |
| 9358 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9359 | // Return the expression of the base of the map clause or null if it cannot |
| 9360 | // be determined and do all the necessary checks to see if the expression is |
| 9361 | // valid as a standalone map clause expression. |
| 9362 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 9363 | SourceLocation ELoc = E->getExprLoc(); |
| 9364 | SourceRange ERange = E->getSourceRange(); |
| 9365 | |
| 9366 | // The base of elements of list in a map clause have to be either: |
| 9367 | // - a reference to variable or field. |
| 9368 | // - a member expression. |
| 9369 | // - an array expression. |
| 9370 | // |
| 9371 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9372 | // reference to 'r'. |
| 9373 | // |
| 9374 | // If we have: |
| 9375 | // |
| 9376 | // struct SS { |
| 9377 | // Bla S; |
| 9378 | // foo() { |
| 9379 | // #pragma omp target map (S.Arr[:12]); |
| 9380 | // } |
| 9381 | // } |
| 9382 | // |
| 9383 | // We want to retrieve the member expression 'this->S'; |
| 9384 | |
| 9385 | Expr *RelevantExpr = nullptr; |
| 9386 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9387 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9388 | // If a list item is an array section, it must specify contiguous storage. |
| 9389 | // |
| 9390 | // For this restriction it is sufficient that we make sure only references |
| 9391 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9392 | // exist except in the rightmost expression (unless they cover the whole |
| 9393 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9394 | // |
| 9395 | // r.ArrS[3:5].Arr[6:7] |
| 9396 | // |
| 9397 | // r.ArrS[3:5].x |
| 9398 | // |
| 9399 | // but these would be valid: |
| 9400 | // r.ArrS[3].Arr[6:7] |
| 9401 | // |
| 9402 | // r.ArrS[3].x |
| 9403 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9404 | bool AllowUnitySizeArraySection = true; |
| 9405 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9406 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9407 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9408 | E = E->IgnoreParenImpCasts(); |
| 9409 | |
| 9410 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9411 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9412 | break; |
| 9413 | |
| 9414 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9415 | |
| 9416 | // If we got a reference to a declaration, we should not expect any array |
| 9417 | // section before that. |
| 9418 | AllowUnitySizeArraySection = false; |
| 9419 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9420 | continue; |
| 9421 | } |
| 9422 | |
| 9423 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9424 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9425 | |
| 9426 | if (isa<CXXThisExpr>(BaseE)) |
| 9427 | // We found a base expression: this->Val. |
| 9428 | RelevantExpr = CurE; |
| 9429 | else |
| 9430 | E = BaseE; |
| 9431 | |
| 9432 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9433 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9434 | << CurE->getSourceRange(); |
| 9435 | break; |
| 9436 | } |
| 9437 | |
| 9438 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9439 | |
| 9440 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9441 | // A bit-field cannot appear in a map clause. |
| 9442 | // |
| 9443 | if (FD->isBitField()) { |
| 9444 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9445 | << CurE->getSourceRange(); |
| 9446 | break; |
| 9447 | } |
| 9448 | |
| 9449 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9450 | // If the type of a list item is a reference to a type T then the type |
| 9451 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9452 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9453 | |
| 9454 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9455 | // A list item cannot be a variable that is a member of a structure with |
| 9456 | // a union type. |
| 9457 | // |
| 9458 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9459 | if (RT->isUnionType()) { |
| 9460 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9461 | << CurE->getSourceRange(); |
| 9462 | break; |
| 9463 | } |
| 9464 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9465 | // If we got a member expression, we should not expect any array section |
| 9466 | // before that: |
| 9467 | // |
| 9468 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9469 | // If a list item is an element of a structure, only the rightmost symbol |
| 9470 | // of the variable reference can be an array section. |
| 9471 | // |
| 9472 | AllowUnitySizeArraySection = false; |
| 9473 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9474 | continue; |
| 9475 | } |
| 9476 | |
| 9477 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9478 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9479 | |
| 9480 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9481 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9482 | << 0 << CurE->getSourceRange(); |
| 9483 | break; |
| 9484 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9485 | |
| 9486 | // If we got an array subscript that express the whole dimension we |
| 9487 | // can have any array expressions before. If it only expressing part of |
| 9488 | // the dimension, we can only have unitary-size array expressions. |
| 9489 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9490 | E->getType())) |
| 9491 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9492 | continue; |
| 9493 | } |
| 9494 | |
| 9495 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9496 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9497 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9498 | auto CurType = |
| 9499 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9500 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9501 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9502 | // If the type of a list item is a reference to a type T then the type |
| 9503 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9504 | if (CurType->isReferenceType()) |
| 9505 | CurType = CurType->getPointeeType(); |
| 9506 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9507 | bool IsPointer = CurType->isAnyPointerType(); |
| 9508 | |
| 9509 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9510 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9511 | << 0 << CurE->getSourceRange(); |
| 9512 | break; |
| 9513 | } |
| 9514 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9515 | bool NotWhole = |
| 9516 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9517 | bool NotUnity = |
| 9518 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9519 | |
| 9520 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 9521 | // Any array section is currently allowed. |
| 9522 | // |
| 9523 | // If this array section refers to the whole dimension we can still |
| 9524 | // accept other array sections before this one, except if the base is a |
| 9525 | // pointer. Otherwise, only unitary sections are accepted. |
| 9526 | if (NotWhole || IsPointer) |
| 9527 | AllowWholeSizeArraySection = false; |
| 9528 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 9529 | (AllowWholeSizeArraySection && NotWhole)) { |
| 9530 | // A unity or whole array section is not allowed and that is not |
| 9531 | // compatible with the properties of the current array section. |
| 9532 | SemaRef.Diag( |
| 9533 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9534 | << CurE->getSourceRange(); |
| 9535 | break; |
| 9536 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9537 | continue; |
| 9538 | } |
| 9539 | |
| 9540 | // If nothing else worked, this is not a valid map clause expression. |
| 9541 | SemaRef.Diag(ELoc, |
| 9542 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9543 | << ERange; |
| 9544 | break; |
| 9545 | } |
| 9546 | |
| 9547 | return RelevantExpr; |
| 9548 | } |
| 9549 | |
| 9550 | // Return true if expression E associated with value VD has conflicts with other |
| 9551 | // map information. |
| 9552 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9553 | Expr *E, bool CurrentRegionOnly) { |
| 9554 | assert(VD && E); |
| 9555 | |
| 9556 | // Types used to organize the components of a valid map clause. |
| 9557 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9558 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9559 | |
| 9560 | // Helper to extract the components in the map clause expression E and store |
| 9561 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9562 | // it has already passed the single clause checks. |
| 9563 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9564 | MapExpressionComponents &MEC) { |
| 9565 | while (true) { |
| 9566 | TE = TE->IgnoreParenImpCasts(); |
| 9567 | |
| 9568 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9569 | MEC.push_back( |
| 9570 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9571 | break; |
| 9572 | } |
| 9573 | |
| 9574 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9575 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9576 | |
| 9577 | MEC.push_back(MapExpressionComponent( |
| 9578 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9579 | if (isa<CXXThisExpr>(BaseE)) |
| 9580 | break; |
| 9581 | |
| 9582 | TE = BaseE; |
| 9583 | continue; |
| 9584 | } |
| 9585 | |
| 9586 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9587 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9588 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9589 | continue; |
| 9590 | } |
| 9591 | |
| 9592 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9593 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9594 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9595 | continue; |
| 9596 | } |
| 9597 | |
| 9598 | llvm_unreachable( |
| 9599 | "Expecting only valid map clause expressions at this point!"); |
| 9600 | } |
| 9601 | }; |
| 9602 | |
| 9603 | SourceLocation ELoc = E->getExprLoc(); |
| 9604 | SourceRange ERange = E->getSourceRange(); |
| 9605 | |
| 9606 | // In order to easily check the conflicts we need to match each component of |
| 9607 | // the expression under test with the components of the expressions that are |
| 9608 | // already in the stack. |
| 9609 | |
| 9610 | MapExpressionComponents CurComponents; |
| 9611 | ExtractMapExpressionComponents(E, CurComponents); |
| 9612 | |
| 9613 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9614 | assert(CurComponents.back().second == VD && |
| 9615 | "Map clause expression with unexpected base!"); |
| 9616 | |
| 9617 | // Variables to help detecting enclosing problems in data environment nests. |
| 9618 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9619 | Expr *EnclosingExpr = nullptr; |
| 9620 | |
| 9621 | bool FoundError = |
| 9622 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9623 | MapExpressionComponents StackComponents; |
| 9624 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9625 | assert(!StackComponents.empty() && |
| 9626 | "Map clause expression with no components!"); |
| 9627 | assert(StackComponents.back().second == VD && |
| 9628 | "Map clause expression with unexpected base!"); |
| 9629 | |
| 9630 | // Expressions must start from the same base. Here we detect at which |
| 9631 | // point both expressions diverge from each other and see if we can |
| 9632 | // detect if the memory referred to both expressions is contiguous and |
| 9633 | // do not overlap. |
| 9634 | auto CI = CurComponents.rbegin(); |
| 9635 | auto CE = CurComponents.rend(); |
| 9636 | auto SI = StackComponents.rbegin(); |
| 9637 | auto SE = StackComponents.rend(); |
| 9638 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9639 | |
| 9640 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9641 | // At most one list item can be an array item derived from a given |
| 9642 | // variable in map clauses of the same construct. |
| 9643 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9644 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9645 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9646 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9647 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9648 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9649 | << CI->first->getSourceRange(); |
| 9650 | ; |
| 9651 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9652 | << SI->first->getSourceRange(); |
| 9653 | return true; |
| 9654 | } |
| 9655 | |
| 9656 | // Do both expressions have the same kind? |
| 9657 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9658 | break; |
| 9659 | |
| 9660 | // Are we dealing with different variables/fields? |
| 9661 | if (CI->second != SI->second) |
| 9662 | break; |
| 9663 | } |
| 9664 | |
| 9665 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9666 | // List items of map clauses in the same construct must not share |
| 9667 | // original storage. |
| 9668 | // |
| 9669 | // If the expressions are exactly the same or one is a subset of the |
| 9670 | // other, it means they are sharing storage. |
| 9671 | if (CI == CE && SI == SE) { |
| 9672 | if (CurrentRegionOnly) { |
| 9673 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9674 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9675 | << RE->getSourceRange(); |
| 9676 | return true; |
| 9677 | } else { |
| 9678 | // If we find the same expression in the enclosing data environment, |
| 9679 | // that is legal. |
| 9680 | IsEnclosedByDataEnvironmentExpr = true; |
| 9681 | return false; |
| 9682 | } |
| 9683 | } |
| 9684 | |
| 9685 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9686 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9687 | |
| 9688 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9689 | // If the type of a list item is a reference to a type T then the type |
| 9690 | // will be considered to be T for all purposes of this clause. |
| 9691 | if (DerivedType->isReferenceType()) |
| 9692 | DerivedType = DerivedType->getPointeeType(); |
| 9693 | |
| 9694 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9695 | // A variable for which the type is pointer and an array section |
| 9696 | // derived from that variable must not appear as list items of map |
| 9697 | // clauses of the same construct. |
| 9698 | // |
| 9699 | // Also, cover one of the cases in: |
| 9700 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9701 | // If any part of the original storage of a list item has corresponding |
| 9702 | // storage in the device data environment, all of the original storage |
| 9703 | // must have corresponding storage in the device data environment. |
| 9704 | // |
| 9705 | if (DerivedType->isAnyPointerType()) { |
| 9706 | if (CI == CE || SI == SE) { |
| 9707 | SemaRef.Diag( |
| 9708 | DerivedLoc, |
| 9709 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9710 | << DerivedLoc; |
| 9711 | } else { |
| 9712 | assert(CI != CE && SI != SE); |
| 9713 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9714 | << DerivedLoc; |
| 9715 | } |
| 9716 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9717 | << RE->getSourceRange(); |
| 9718 | return true; |
| 9719 | } |
| 9720 | |
| 9721 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9722 | // List items of map clauses in the same construct must not share |
| 9723 | // original storage. |
| 9724 | // |
| 9725 | // An expression is a subset of the other. |
| 9726 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9727 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9728 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9729 | << RE->getSourceRange(); |
| 9730 | return true; |
| 9731 | } |
| 9732 | |
| 9733 | // The current expression uses the same base as other expression in the |
| 9734 | // data environment but does not contain it completelly. |
| 9735 | if (!CurrentRegionOnly && SI != SE) |
| 9736 | EnclosingExpr = RE; |
| 9737 | |
| 9738 | // The current expression is a subset of the expression in the data |
| 9739 | // environment. |
| 9740 | IsEnclosedByDataEnvironmentExpr |= |
| 9741 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9742 | |
| 9743 | return false; |
| 9744 | }); |
| 9745 | |
| 9746 | if (CurrentRegionOnly) |
| 9747 | return FoundError; |
| 9748 | |
| 9749 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9750 | // If any part of the original storage of a list item has corresponding |
| 9751 | // storage in the device data environment, all of the original storage must |
| 9752 | // have corresponding storage in the device data environment. |
| 9753 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9754 | // If a list item is an element of a structure, and a different element of |
| 9755 | // the structure has a corresponding list item in the device data environment |
| 9756 | // prior to a task encountering the construct associated with the map clause, |
| 9757 | // then the list item must also have a correspnding list item in the device |
| 9758 | // data environment prior to the task encountering the construct. |
| 9759 | // |
| 9760 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9761 | SemaRef.Diag(ELoc, |
| 9762 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9763 | << ERange; |
| 9764 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9765 | << EnclosingExpr->getSourceRange(); |
| 9766 | return true; |
| 9767 | } |
| 9768 | |
| 9769 | return FoundError; |
| 9770 | } |
| 9771 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9772 | OMPClause * |
| 9773 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9774 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9775 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9776 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9777 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9778 | SmallVector<Expr *, 4> Vars; |
| 9779 | |
| 9780 | for (auto &RE : VarList) { |
| 9781 | assert(RE && "Null expr in omp map"); |
| 9782 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9783 | // It will be analyzed later. |
| 9784 | Vars.push_back(RE); |
| 9785 | continue; |
| 9786 | } |
| 9787 | SourceLocation ELoc = RE->getExprLoc(); |
| 9788 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9789 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9790 | |
| 9791 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9792 | VE->isInstantiationDependent() || |
| 9793 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9794 | // We can only analyze this information once the missing information is |
| 9795 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9796 | Vars.push_back(RE); |
| 9797 | continue; |
| 9798 | } |
| 9799 | |
| 9800 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9801 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9802 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9803 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9804 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9805 | continue; |
| 9806 | } |
| 9807 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9808 | // Obtain the array or member expression bases if required. |
| 9809 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9810 | if (!BE) |
| 9811 | continue; |
| 9812 | |
| 9813 | // If the base is a reference to a variable, we rely on that variable for |
| 9814 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9815 | ValueDecl *D = nullptr; |
| 9816 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9817 | D = DRE->getDecl(); |
| 9818 | } else { |
| 9819 | auto *ME = cast<MemberExpr>(BE); |
| 9820 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9821 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9822 | } |
| 9823 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9824 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9825 | auto *VD = dyn_cast<VarDecl>(D); |
| 9826 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9827 | |
| 9828 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9829 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9830 | |
| 9831 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9832 | // threadprivate variables cannot appear in a map clause. |
| 9833 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9834 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9835 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9836 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9837 | continue; |
| 9838 | } |
| 9839 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9840 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9841 | // A list item cannot appear in both a map clause and a data-sharing |
| 9842 | // attribute clause on the same construct. |
| 9843 | // |
| 9844 | // TODO: Implement this check - it cannot currently be tested because of |
| 9845 | // missing implementation of the other data sharing clauses in target |
| 9846 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9847 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9848 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9849 | // with the current construct separately from the enclosing data |
| 9850 | // environment, because the restrictions are different. |
| 9851 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9852 | /*CurrentRegionOnly=*/true)) |
| 9853 | break; |
| 9854 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9855 | /*CurrentRegionOnly=*/false)) |
| 9856 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9857 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9858 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9859 | // If the type of a list item is a reference to a type T then the type will |
| 9860 | // be considered to be T for all purposes of this clause. |
| 9861 | QualType Type = D->getType(); |
| 9862 | if (Type->isReferenceType()) |
| 9863 | Type = Type->getPointeeType(); |
| 9864 | |
| 9865 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9866 | // A list item must have a mappable type. |
| 9867 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9868 | DSAStack, Type)) |
| 9869 | continue; |
| 9870 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9871 | // target enter data |
| 9872 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9873 | // A map-type must be specified in all map clauses and must be either |
| 9874 | // to or alloc. |
| 9875 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9876 | if (DKind == OMPD_target_enter_data && |
| 9877 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9878 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9879 | << (IsMapTypeImplicit ? 1 : 0) |
| 9880 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9881 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9882 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9883 | } |
| 9884 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9885 | // target exit_data |
| 9886 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9887 | // A map-type must be specified in all map clauses and must be either |
| 9888 | // from, release, or delete. |
| 9889 | DKind = DSAStack->getCurrentDirective(); |
| 9890 | if (DKind == OMPD_target_exit_data && |
| 9891 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9892 | MapType == OMPC_MAP_delete)) { |
| 9893 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9894 | << (IsMapTypeImplicit ? 1 : 0) |
| 9895 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9896 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9897 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9898 | } |
| 9899 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9900 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9901 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9902 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9903 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9904 | // We need to produce a map clause even if we don't have variables so that |
| 9905 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9906 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9907 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9908 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9909 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9910 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9911 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 9912 | TypeResult ParsedType) { |
| 9913 | assert(ParsedType.isUsable()); |
| 9914 | |
| 9915 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 9916 | if (ReductionType.isNull()) |
| 9917 | return QualType(); |
| 9918 | |
| 9919 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 9920 | // A type name in a declare reduction directive cannot be a function type, an |
| 9921 | // array type, a reference type, or a type qualified with const, volatile or |
| 9922 | // restrict. |
| 9923 | if (ReductionType.hasQualifiers()) { |
| 9924 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 9925 | return QualType(); |
| 9926 | } |
| 9927 | |
| 9928 | if (ReductionType->isFunctionType()) { |
| 9929 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 9930 | return QualType(); |
| 9931 | } |
| 9932 | if (ReductionType->isReferenceType()) { |
| 9933 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 9934 | return QualType(); |
| 9935 | } |
| 9936 | if (ReductionType->isArrayType()) { |
| 9937 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 9938 | return QualType(); |
| 9939 | } |
| 9940 | return ReductionType; |
| 9941 | } |
| 9942 | |
| 9943 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 9944 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 9945 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 9946 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 9947 | SmallVector<Decl *, 8> Decls; |
| 9948 | Decls.reserve(ReductionTypes.size()); |
| 9949 | |
| 9950 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 9951 | ForRedeclaration); |
| 9952 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 9953 | // A reduction-identifier may not be re-declared in the current scope for the |
| 9954 | // same type or for a type that is compatible according to the base language |
| 9955 | // rules. |
| 9956 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 9957 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 9958 | bool InCompoundScope = true; |
| 9959 | if (S != nullptr) { |
| 9960 | // Find previous declaration with the same name not referenced in other |
| 9961 | // declarations. |
| 9962 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 9963 | InCompoundScope = |
| 9964 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 9965 | LookupName(Lookup, S); |
| 9966 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 9967 | /*AllowInlineNamespace=*/false); |
| 9968 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 9969 | auto Filter = Lookup.makeFilter(); |
| 9970 | while (Filter.hasNext()) { |
| 9971 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 9972 | if (InCompoundScope) { |
| 9973 | auto I = UsedAsPrevious.find(PrevDecl); |
| 9974 | if (I == UsedAsPrevious.end()) |
| 9975 | UsedAsPrevious[PrevDecl] = false; |
| 9976 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 9977 | UsedAsPrevious[D] = true; |
| 9978 | } |
| 9979 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 9980 | PrevDecl->getLocation(); |
| 9981 | } |
| 9982 | Filter.done(); |
| 9983 | if (InCompoundScope) { |
| 9984 | for (auto &PrevData : UsedAsPrevious) { |
| 9985 | if (!PrevData.second) { |
| 9986 | PrevDRD = PrevData.first; |
| 9987 | break; |
| 9988 | } |
| 9989 | } |
| 9990 | } |
| 9991 | } else if (PrevDeclInScope != nullptr) { |
| 9992 | auto *PrevDRDInScope = PrevDRD = |
| 9993 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 9994 | do { |
| 9995 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 9996 | PrevDRDInScope->getLocation(); |
| 9997 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 9998 | } while (PrevDRDInScope != nullptr); |
| 9999 | } |
| 10000 | for (auto &TyData : ReductionTypes) { |
| 10001 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10002 | bool Invalid = false; |
| 10003 | if (I != PreviousRedeclTypes.end()) { |
| 10004 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10005 | << TyData.first; |
| 10006 | Diag(I->second, diag::note_previous_definition); |
| 10007 | Invalid = true; |
| 10008 | } |
| 10009 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10010 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10011 | Name, TyData.first, PrevDRD); |
| 10012 | DC->addDecl(DRD); |
| 10013 | DRD->setAccess(AS); |
| 10014 | Decls.push_back(DRD); |
| 10015 | if (Invalid) |
| 10016 | DRD->setInvalidDecl(); |
| 10017 | else |
| 10018 | PrevDRD = DRD; |
| 10019 | } |
| 10020 | |
| 10021 | return DeclGroupPtrTy::make( |
| 10022 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10023 | } |
| 10024 | |
| 10025 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10026 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10027 | |
| 10028 | // Enter new function scope. |
| 10029 | PushFunctionScope(); |
| 10030 | getCurFunction()->setHasBranchProtectedScope(); |
| 10031 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10032 | |
| 10033 | if (S != nullptr) |
| 10034 | PushDeclContext(S, DRD); |
| 10035 | else |
| 10036 | CurContext = DRD; |
| 10037 | |
| 10038 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10039 | |
| 10040 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10041 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10042 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10043 | // uses semantics of argument handles by value, but it should be passed by |
| 10044 | // reference. C lang does not support references, so pass all parameters as |
| 10045 | // pointers. |
| 10046 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10047 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10048 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10049 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10050 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10051 | // uses semantics of argument handles by value, but it should be passed by |
| 10052 | // reference. C lang does not support references, so pass all parameters as |
| 10053 | // pointers. |
| 10054 | // Create 'T omp_out;' variable. |
| 10055 | auto *OmpOutParm = |
| 10056 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10057 | if (S != nullptr) { |
| 10058 | PushOnScopeChains(OmpInParm, S); |
| 10059 | PushOnScopeChains(OmpOutParm, S); |
| 10060 | } else { |
| 10061 | DRD->addDecl(OmpInParm); |
| 10062 | DRD->addDecl(OmpOutParm); |
| 10063 | } |
| 10064 | } |
| 10065 | |
| 10066 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10067 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10068 | DiscardCleanupsInEvaluationContext(); |
| 10069 | PopExpressionEvaluationContext(); |
| 10070 | |
| 10071 | PopDeclContext(); |
| 10072 | PopFunctionScopeInfo(); |
| 10073 | |
| 10074 | if (Combiner != nullptr) |
| 10075 | DRD->setCombiner(Combiner); |
| 10076 | else |
| 10077 | DRD->setInvalidDecl(); |
| 10078 | } |
| 10079 | |
| 10080 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10081 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10082 | |
| 10083 | // Enter new function scope. |
| 10084 | PushFunctionScope(); |
| 10085 | getCurFunction()->setHasBranchProtectedScope(); |
| 10086 | |
| 10087 | if (S != nullptr) |
| 10088 | PushDeclContext(S, DRD); |
| 10089 | else |
| 10090 | CurContext = DRD; |
| 10091 | |
| 10092 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10093 | |
| 10094 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10095 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10096 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10097 | // uses semantics of argument handles by value, but it should be passed by |
| 10098 | // reference. C lang does not support references, so pass all parameters as |
| 10099 | // pointers. |
| 10100 | // Create 'T omp_priv;' variable. |
| 10101 | auto *OmpPrivParm = |
| 10102 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10103 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10104 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10105 | // uses semantics of argument handles by value, but it should be passed by |
| 10106 | // reference. C lang does not support references, so pass all parameters as |
| 10107 | // pointers. |
| 10108 | // Create 'T omp_orig;' variable. |
| 10109 | auto *OmpOrigParm = |
| 10110 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10111 | if (S != nullptr) { |
| 10112 | PushOnScopeChains(OmpPrivParm, S); |
| 10113 | PushOnScopeChains(OmpOrigParm, S); |
| 10114 | } else { |
| 10115 | DRD->addDecl(OmpPrivParm); |
| 10116 | DRD->addDecl(OmpOrigParm); |
| 10117 | } |
| 10118 | } |
| 10119 | |
| 10120 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10121 | Expr *Initializer) { |
| 10122 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10123 | DiscardCleanupsInEvaluationContext(); |
| 10124 | PopExpressionEvaluationContext(); |
| 10125 | |
| 10126 | PopDeclContext(); |
| 10127 | PopFunctionScopeInfo(); |
| 10128 | |
| 10129 | if (Initializer != nullptr) |
| 10130 | DRD->setInitializer(Initializer); |
| 10131 | else |
| 10132 | DRD->setInvalidDecl(); |
| 10133 | } |
| 10134 | |
| 10135 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10136 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10137 | for (auto *D : DeclReductions.get()) { |
| 10138 | if (IsValid) { |
| 10139 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10140 | if (S != nullptr) |
| 10141 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10142 | } else |
| 10143 | D->setInvalidDecl(); |
| 10144 | } |
| 10145 | return DeclReductions; |
| 10146 | } |
| 10147 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10148 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 10149 | SourceLocation StartLoc, |
| 10150 | SourceLocation LParenLoc, |
| 10151 | SourceLocation EndLoc) { |
| 10152 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10153 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10154 | // OpenMP [teams Constrcut, Restrictions] |
| 10155 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10156 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10157 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10158 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10159 | |
| 10160 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10161 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10162 | |
| 10163 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10164 | SourceLocation StartLoc, |
| 10165 | SourceLocation LParenLoc, |
| 10166 | SourceLocation EndLoc) { |
| 10167 | Expr *ValExpr = ThreadLimit; |
| 10168 | |
| 10169 | // OpenMP [teams Constrcut, Restrictions] |
| 10170 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10171 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10172 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10173 | return nullptr; |
| 10174 | |
| 10175 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 10176 | EndLoc); |
| 10177 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10178 | |
| 10179 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10180 | SourceLocation StartLoc, |
| 10181 | SourceLocation LParenLoc, |
| 10182 | SourceLocation EndLoc) { |
| 10183 | Expr *ValExpr = Priority; |
| 10184 | |
| 10185 | // OpenMP [2.9.1, task Constrcut] |
| 10186 | // The priority-value is a non-negative numerical scalar expression. |
| 10187 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10188 | /*StrictlyPositive=*/false)) |
| 10189 | return nullptr; |
| 10190 | |
| 10191 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10192 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10193 | |
| 10194 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10195 | SourceLocation StartLoc, |
| 10196 | SourceLocation LParenLoc, |
| 10197 | SourceLocation EndLoc) { |
| 10198 | Expr *ValExpr = Grainsize; |
| 10199 | |
| 10200 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10201 | // The parameter of the grainsize clause must be a positive integer |
| 10202 | // expression. |
| 10203 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10204 | /*StrictlyPositive=*/true)) |
| 10205 | return nullptr; |
| 10206 | |
| 10207 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10208 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10209 | |
| 10210 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10211 | SourceLocation StartLoc, |
| 10212 | SourceLocation LParenLoc, |
| 10213 | SourceLocation EndLoc) { |
| 10214 | Expr *ValExpr = NumTasks; |
| 10215 | |
| 10216 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10217 | // The parameter of the num_tasks clause must be a positive integer |
| 10218 | // expression. |
| 10219 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10220 | /*StrictlyPositive=*/true)) |
| 10221 | return nullptr; |
| 10222 | |
| 10223 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10224 | } |
| 10225 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10226 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10227 | SourceLocation LParenLoc, |
| 10228 | SourceLocation EndLoc) { |
| 10229 | // OpenMP [2.13.2, critical construct, Description] |
| 10230 | // ... where hint-expression is an integer constant expression that evaluates |
| 10231 | // to a valid lock hint. |
| 10232 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10233 | if (HintExpr.isInvalid()) |
| 10234 | return nullptr; |
| 10235 | return new (Context) |
| 10236 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10237 | } |
| 10238 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10239 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10240 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10241 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10242 | SourceLocation EndLoc) { |
| 10243 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10244 | std::string Values; |
| 10245 | Values += "'"; |
| 10246 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10247 | Values += "'"; |
| 10248 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10249 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10250 | return nullptr; |
| 10251 | } |
| 10252 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10253 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10254 | if (ChunkSize) { |
| 10255 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10256 | !ChunkSize->isInstantiationDependent() && |
| 10257 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10258 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10259 | ExprResult Val = |
| 10260 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10261 | if (Val.isInvalid()) |
| 10262 | return nullptr; |
| 10263 | |
| 10264 | ValExpr = Val.get(); |
| 10265 | |
| 10266 | // OpenMP [2.7.1, Restrictions] |
| 10267 | // chunk_size must be a loop invariant integer expression with a positive |
| 10268 | // value. |
| 10269 | llvm::APSInt Result; |
| 10270 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10271 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10272 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10273 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10274 | return nullptr; |
| 10275 | } |
| 10276 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10277 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10278 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 10279 | HelperValStmt = |
| 10280 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 10281 | /*NumDecls=*/1), |
| 10282 | SourceLocation(), SourceLocation()); |
| 10283 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10284 | } |
| 10285 | } |
| 10286 | } |
| 10287 | |
| 10288 | return new (Context) |
| 10289 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10290 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10291 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10292 | |
| 10293 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10294 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10295 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10296 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10297 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 10298 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 10299 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 10300 | std::string Value; |
| 10301 | SourceLocation Loc; |
| 10302 | Value += "'"; |
| 10303 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10304 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10305 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 10306 | Loc = MLoc; |
| 10307 | } else { |
| 10308 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10309 | OMPC_DEFAULTMAP_scalar); |
| 10310 | Loc = KindLoc; |
| 10311 | } |
| 10312 | Value += "'"; |
| 10313 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10314 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10315 | return nullptr; |
| 10316 | } |
| 10317 | |
| 10318 | return new (Context) |
| 10319 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10320 | } |