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 | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 73 | Expr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 74 | SourceLocation ImplicitDSALoc; |
| 75 | DSAVarData() |
| 76 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 77 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 79 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 80 | public: |
| 81 | struct MapInfo { |
| 82 | Expr *RefExpr; |
| 83 | }; |
| 84 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 85 | private: |
| 86 | struct DSAInfo { |
| 87 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 88 | Expr *RefExpr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 89 | }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 90 | typedef llvm::SmallDenseMap<ValueDecl *, DSAInfo, 64> DeclSAMapTy; |
| 91 | typedef llvm::SmallDenseMap<ValueDecl *, Expr *, 64> AlignedMapTy; |
| 92 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
| 93 | typedef llvm::SmallDenseMap<ValueDecl *, MapInfo, 64> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 94 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 95 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | |
| 97 | struct SharingMapTy { |
| 98 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 99 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 100 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 101 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 102 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 103 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 104 | OpenMPDirectiveKind Directive; |
| 105 | DeclarationNameInfo DirectiveName; |
| 106 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 108 | /// \brief first argument (Expr *) contains optional argument of the |
| 109 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 110 | /// clause, false otherwise. |
| 111 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 112 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 113 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 114 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 115 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 116 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 117 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 118 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 119 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 120 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 121 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 123 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 124 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 125 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 126 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 130 | |
| 131 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 132 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 134 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 135 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 136 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 137 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 138 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 139 | |
| 140 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 141 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 142 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 143 | |
| 144 | /// \brief Checks if the variable is a local for OpenMP region. |
| 145 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 146 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 147 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 148 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 149 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 150 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 151 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 152 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 153 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 154 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 155 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 156 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 157 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 158 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 159 | Scope *CurScope, SourceLocation Loc) { |
| 160 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 161 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void pop() { |
| 165 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 166 | Stack.pop_back(); |
| 167 | } |
| 168 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 169 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 170 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 171 | } |
| 172 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 173 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 174 | auto I = Criticals.find(Name.getAsString()); |
| 175 | if (I != Criticals.end()) |
| 176 | return I->second; |
| 177 | return std::make_pair(nullptr, llvm::APSInt()); |
| 178 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 179 | /// \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] | 180 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 181 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 182 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 183 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 184 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 185 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 186 | /// \brief Check if the specified variable is a loop control variable for |
| 187 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 188 | /// \return The index of the loop control variable in the list of associated |
| 189 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 190 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 191 | /// \brief Check if the specified variable is a loop control variable for |
| 192 | /// parent region. |
| 193 | /// \return The index of the loop control variable in the list of associated |
| 194 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 195 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 196 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 197 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 198 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 199 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 201 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 202 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | /// \brief Returns data sharing attributes from top of the stack for the |
| 204 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 205 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 207 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 208 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 209 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 210 | /// predicate. |
| 211 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 212 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 213 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 214 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 215 | /// match specified \a CPred predicate in any innermost directive which |
| 216 | /// matches \a DPred predicate. |
| 217 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 218 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 219 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 220 | /// \brief Checks if the specified variables has explicit data-sharing |
| 221 | /// attributes which match specified \a CPred predicate at the specified |
| 222 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 223 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 224 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 225 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 226 | |
| 227 | /// \brief Returns true if the directive at level \Level matches in the |
| 228 | /// specified \a DPred predicate. |
| 229 | bool hasExplicitDirective( |
| 230 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 231 | unsigned Level); |
| 232 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 233 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 234 | template <class NamedDirectivesPredicate> |
| 235 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 236 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 237 | /// \brief Returns currently analyzed directive. |
| 238 | OpenMPDirectiveKind getCurrentDirective() const { |
| 239 | return Stack.back().Directive; |
| 240 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 241 | /// \brief Returns parent directive. |
| 242 | OpenMPDirectiveKind getParentDirective() const { |
| 243 | if (Stack.size() > 2) |
| 244 | return Stack[Stack.size() - 2].Directive; |
| 245 | return OMPD_unknown; |
| 246 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 247 | /// \brief Return the directive associated with the provided scope. |
| 248 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 249 | |
| 250 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 251 | void setDefaultDSANone(SourceLocation Loc) { |
| 252 | Stack.back().DefaultAttr = DSA_none; |
| 253 | Stack.back().DefaultAttrLoc = Loc; |
| 254 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 255 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 256 | void setDefaultDSAShared(SourceLocation Loc) { |
| 257 | Stack.back().DefaultAttr = DSA_shared; |
| 258 | Stack.back().DefaultAttrLoc = Loc; |
| 259 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 260 | |
| 261 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 262 | return Stack.back().DefaultAttr; |
| 263 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 264 | SourceLocation getDefaultDSALocation() const { |
| 265 | return Stack.back().DefaultAttrLoc; |
| 266 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 268 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 269 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 270 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 271 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 274 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 275 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 276 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 277 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 278 | } |
| 279 | /// \brief Returns true, if parent region is ordered (has associated |
| 280 | /// 'ordered' clause), false - otherwise. |
| 281 | bool isParentOrderedRegion() const { |
| 282 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 283 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 284 | return false; |
| 285 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 286 | /// \brief Returns optional parameter for the ordered region. |
| 287 | Expr *getParentOrderedRegionParam() const { |
| 288 | if (Stack.size() > 2) |
| 289 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 290 | return nullptr; |
| 291 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 292 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 293 | void setNowaitRegion(bool IsNowait = true) { |
| 294 | Stack.back().NowaitRegion = IsNowait; |
| 295 | } |
| 296 | /// \brief Returns true, if parent region is nowait (has associated |
| 297 | /// 'nowait' clause), false - otherwise. |
| 298 | bool isParentNowaitRegion() const { |
| 299 | if (Stack.size() > 2) |
| 300 | return Stack[Stack.size() - 2].NowaitRegion; |
| 301 | return false; |
| 302 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 303 | /// \brief Marks parent region as cancel region. |
| 304 | void setParentCancelRegion(bool Cancel = true) { |
| 305 | if (Stack.size() > 2) |
| 306 | Stack[Stack.size() - 2].CancelRegion = |
| 307 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 308 | } |
| 309 | /// \brief Return true if current region has inner cancel construct. |
| 310 | bool isCancelRegion() const { |
| 311 | return Stack.back().CancelRegion; |
| 312 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 313 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 314 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 315 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 316 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 317 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 318 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 319 | /// \brief Marks current target region as one with closely nested teams |
| 320 | /// region. |
| 321 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 322 | if (Stack.size() > 2) |
| 323 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 324 | } |
| 325 | /// \brief Returns true, if current region has closely nested teams region. |
| 326 | bool hasInnerTeamsRegion() const { |
| 327 | return getInnerTeamsRegionLoc().isValid(); |
| 328 | } |
| 329 | /// \brief Returns location of the nested teams region (if any). |
| 330 | SourceLocation getInnerTeamsRegionLoc() const { |
| 331 | if (Stack.size() > 1) |
| 332 | return Stack.back().InnerTeamsRegionLoc; |
| 333 | return SourceLocation(); |
| 334 | } |
| 335 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 336 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 338 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 339 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 340 | MapInfo getMapInfoForVar(ValueDecl *VD) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 341 | MapInfo VarMI = {0}; |
| 342 | for (auto Cnt = Stack.size() - 1; Cnt > 0; --Cnt) { |
| 343 | if (Stack[Cnt].MappedDecls.count(VD)) { |
| 344 | VarMI = Stack[Cnt].MappedDecls[VD]; |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | return VarMI; |
| 349 | } |
| 350 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 351 | void addMapInfoForVar(ValueDecl *VD, MapInfo MI) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 352 | if (Stack.size() > 1) { |
| 353 | Stack.back().MappedDecls[VD] = MI; |
| 354 | } |
| 355 | } |
| 356 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 357 | MapInfo IsMappedInCurrentRegion(ValueDecl *VD) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 358 | assert(Stack.size() > 1 && "Target level is 0"); |
| 359 | MapInfo VarMI = {0}; |
| 360 | if (Stack.size() > 1 && Stack.back().MappedDecls.count(VD)) { |
| 361 | VarMI = Stack.back().MappedDecls[VD]; |
| 362 | } |
| 363 | return VarMI; |
| 364 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 365 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 366 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 367 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 368 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 369 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 370 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 371 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 372 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 373 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 374 | auto *VD = dyn_cast<VarDecl>(D); |
| 375 | auto *FD = dyn_cast<FieldDecl>(D); |
| 376 | if (VD != nullptr) { |
| 377 | VD = VD->getCanonicalDecl(); |
| 378 | D = VD; |
| 379 | } else { |
| 380 | assert(FD); |
| 381 | FD = FD->getCanonicalDecl(); |
| 382 | D = FD; |
| 383 | } |
| 384 | return D; |
| 385 | } |
| 386 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 387 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 388 | ValueDecl *D) { |
| 389 | D = getCanonicalDecl(D); |
| 390 | auto *VD = dyn_cast<VarDecl>(D); |
| 391 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 393 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 394 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 395 | // in a region but not in construct] |
| 396 | // File-scope or namespace-scope variables referenced in called routines |
| 397 | // in the region are shared unless they appear in a threadprivate |
| 398 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 399 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 400 | DVar.CKind = OMPC_shared; |
| 401 | |
| 402 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 403 | // in a region but not in construct] |
| 404 | // Variables with static storage duration that are declared in called |
| 405 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 406 | if (VD && VD->hasGlobalStorage()) |
| 407 | DVar.CKind = OMPC_shared; |
| 408 | |
| 409 | // Non-static data members are shared by default. |
| 410 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 411 | DVar.CKind = OMPC_shared; |
| 412 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 413 | return DVar; |
| 414 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 415 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 416 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 417 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 418 | // in a Construct, C/C++, predetermined, p.1] |
| 419 | // Variables with automatic storage duration that are declared in a scope |
| 420 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 421 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 422 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 423 | DVar.CKind = OMPC_private; |
| 424 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | // Explicitly specified attributes and local variables with predetermined |
| 428 | // attributes. |
| 429 | if (Iter->SharingMap.count(D)) { |
| 430 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 431 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 432 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 433 | return DVar; |
| 434 | } |
| 435 | |
| 436 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 437 | // in a Construct, C/C++, implicitly determined, p.1] |
| 438 | // In a parallel or task construct, the data-sharing attributes of these |
| 439 | // variables are determined by the default clause, if present. |
| 440 | switch (Iter->DefaultAttr) { |
| 441 | case DSA_shared: |
| 442 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 443 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | return DVar; |
| 445 | case DSA_none: |
| 446 | return DVar; |
| 447 | case DSA_unspecified: |
| 448 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 449 | // in a Construct, implicitly determined, p.2] |
| 450 | // In a parallel construct, if no default clause is present, these |
| 451 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 452 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 453 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 454 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 455 | DVar.CKind = OMPC_shared; |
| 456 | return DVar; |
| 457 | } |
| 458 | |
| 459 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 460 | // in a Construct, implicitly determined, p.4] |
| 461 | // In a task construct, if no default clause is present, a variable that in |
| 462 | // the enclosing context is determined to be shared by all implicit tasks |
| 463 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 464 | if (DVar.DKind == OMPD_task) { |
| 465 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 466 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 467 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 468 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 469 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 470 | // in a Construct, implicitly determined, p.6] |
| 471 | // In a task construct, if no default clause is present, a variable |
| 472 | // whose data-sharing attribute is not determined by the rules above is |
| 473 | // firstprivate. |
| 474 | DVarTemp = getDSA(I, D); |
| 475 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 476 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 478 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 479 | return DVar; |
| 480 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 481 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 482 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 483 | } |
| 484 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 486 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | return DVar; |
| 488 | } |
| 489 | } |
| 490 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 491 | // in a Construct, implicitly determined, p.3] |
| 492 | // For constructs other than task, if no default clause is present, these |
| 493 | // variables inherit their data-sharing attributes from the enclosing |
| 494 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 495 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 498 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 499 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 500 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 501 | auto It = Stack.back().AlignedMap.find(D); |
| 502 | if (It == Stack.back().AlignedMap.end()) { |
| 503 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 504 | Stack.back().AlignedMap[D] = NewDE; |
| 505 | return nullptr; |
| 506 | } else { |
| 507 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 508 | return It->second; |
| 509 | } |
| 510 | return nullptr; |
| 511 | } |
| 512 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 513 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 514 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 515 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 516 | 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] | 517 | } |
| 518 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 519 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 520 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 521 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 522 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 523 | } |
| 524 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 526 | assert(Stack.size() > 2 && "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 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 529 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 530 | : 0; |
| 531 | } |
| 532 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 534 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 535 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 536 | return nullptr; |
| 537 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 538 | if (Pair.second == I) |
| 539 | return Pair.first; |
| 540 | } |
| 541 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 544 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A) { |
| 545 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 546 | if (A == OMPC_threadprivate) { |
| 547 | Stack[0].SharingMap[D].Attributes = A; |
| 548 | Stack[0].SharingMap[D].RefExpr = E; |
| 549 | } else { |
| 550 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 551 | Stack.back().SharingMap[D].Attributes = A; |
| 552 | Stack.back().SharingMap[D].RefExpr = E; |
| 553 | } |
| 554 | } |
| 555 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 556 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 557 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 558 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 559 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 560 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 561 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 562 | ++I; |
| 563 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 564 | if (I == E) |
| 565 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 566 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 567 | Scope *CurScope = getCurScope(); |
| 568 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 569 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 570 | } |
| 571 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 572 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 573 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 576 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 577 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 578 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 579 | DeclContext *DC = SemaRef.CurContext; |
| 580 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 581 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 582 | VarDecl *Decl = |
| 583 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 584 | if (Attrs) { |
| 585 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 586 | I != E; ++I) |
| 587 | Decl->addAttr(*I); |
| 588 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 589 | Decl->setImplicit(); |
| 590 | return Decl; |
| 591 | } |
| 592 | |
| 593 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 594 | SourceLocation Loc, |
| 595 | bool RefersToCapture = false) { |
| 596 | D->setReferenced(); |
| 597 | D->markUsed(S.Context); |
| 598 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 599 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 600 | VK_LValue); |
| 601 | } |
| 602 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 603 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 604 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 605 | DSAVarData DVar; |
| 606 | |
| 607 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 608 | // in a Construct, C/C++, predetermined, p.1] |
| 609 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 610 | auto *VD = dyn_cast<VarDecl>(D); |
| 611 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 612 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 613 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 614 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 615 | (VD && VD->getStorageClass() == SC_Register && |
| 616 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 617 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 618 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 619 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 620 | } |
| 621 | if (Stack[0].SharingMap.count(D)) { |
| 622 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 623 | DVar.CKind = OMPC_threadprivate; |
| 624 | return DVar; |
| 625 | } |
| 626 | |
| 627 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 628 | // in a Construct, C/C++, predetermined, p.4] |
| 629 | // Static data members are shared. |
| 630 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 631 | // in a Construct, C/C++, predetermined, p.7] |
| 632 | // Variables with static storage duration that are declared in a scope |
| 633 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 634 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 635 | DSAVarData DVarTemp = |
| 636 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 637 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 638 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 639 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 640 | DVar.CKind = OMPC_shared; |
| 641 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 645 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 646 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 647 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 648 | // in a Construct, C/C++, predetermined, p.6] |
| 649 | // Variables with const qualified type having no mutable member are |
| 650 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 651 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 652 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 653 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 654 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 655 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 656 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 657 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 658 | // Variables with const-qualified type having no mutable member may be |
| 659 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 660 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 661 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 662 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 663 | return DVar; |
| 664 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 665 | DVar.CKind = OMPC_shared; |
| 666 | return DVar; |
| 667 | } |
| 668 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 669 | // Explicitly specified attributes and local variables with predetermined |
| 670 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 671 | auto StartI = std::next(Stack.rbegin()); |
| 672 | auto EndI = std::prev(Stack.rend()); |
| 673 | if (FromParent && StartI != EndI) { |
| 674 | StartI = std::next(StartI); |
| 675 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 676 | auto I = std::prev(StartI); |
| 677 | if (I->SharingMap.count(D)) { |
| 678 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 679 | DVar.CKind = I->SharingMap[D].Attributes; |
| 680 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | return DVar; |
| 684 | } |
| 685 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 686 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 687 | bool FromParent) { |
| 688 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 689 | auto StartI = Stack.rbegin(); |
| 690 | auto EndI = std::prev(Stack.rend()); |
| 691 | if (FromParent && StartI != EndI) { |
| 692 | StartI = std::next(StartI); |
| 693 | } |
| 694 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 697 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 698 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 699 | DirectivesPredicate DPred, |
| 700 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 701 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 702 | auto StartI = std::next(Stack.rbegin()); |
| 703 | auto EndI = std::prev(Stack.rend()); |
| 704 | if (FromParent && StartI != EndI) { |
| 705 | StartI = std::next(StartI); |
| 706 | } |
| 707 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 708 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 709 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 710 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 711 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 712 | return DVar; |
| 713 | } |
| 714 | return DSAVarData(); |
| 715 | } |
| 716 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 717 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 718 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 719 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 720 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 721 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 722 | auto StartI = std::next(Stack.rbegin()); |
| 723 | auto EndI = std::prev(Stack.rend()); |
| 724 | if (FromParent && StartI != EndI) { |
| 725 | StartI = std::next(StartI); |
| 726 | } |
| 727 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 728 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 729 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 730 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 731 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 732 | return DVar; |
| 733 | return DSAVarData(); |
| 734 | } |
| 735 | return DSAVarData(); |
| 736 | } |
| 737 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 738 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 739 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 740 | unsigned Level) { |
| 741 | if (CPred(ClauseKindMode)) |
| 742 | return true; |
| 743 | if (isClauseParsingMode()) |
| 744 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 745 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 746 | auto StartI = Stack.rbegin(); |
| 747 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 748 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 749 | return false; |
| 750 | std::advance(StartI, Level); |
| 751 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 752 | CPred(StartI->SharingMap[D].Attributes); |
| 753 | } |
| 754 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 755 | bool DSAStackTy::hasExplicitDirective( |
| 756 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 757 | unsigned Level) { |
| 758 | if (isClauseParsingMode()) |
| 759 | ++Level; |
| 760 | auto StartI = Stack.rbegin(); |
| 761 | auto EndI = std::prev(Stack.rend()); |
| 762 | if (std::distance(StartI, EndI) <= (int)Level) |
| 763 | return false; |
| 764 | std::advance(StartI, Level); |
| 765 | return DPred(StartI->Directive); |
| 766 | } |
| 767 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 768 | template <class NamedDirectivesPredicate> |
| 769 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 770 | auto StartI = std::next(Stack.rbegin()); |
| 771 | auto EndI = std::prev(Stack.rend()); |
| 772 | if (FromParent && StartI != EndI) { |
| 773 | StartI = std::next(StartI); |
| 774 | } |
| 775 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 776 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 777 | return true; |
| 778 | } |
| 779 | return false; |
| 780 | } |
| 781 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 782 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 783 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 784 | if (I->CurScope == S) |
| 785 | return I->Directive; |
| 786 | return OMPD_unknown; |
| 787 | } |
| 788 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 789 | void Sema::InitDataSharingAttributesStack() { |
| 790 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 791 | } |
| 792 | |
| 793 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 794 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 795 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 796 | const CapturedRegionScopeInfo *RSI) { |
| 797 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 798 | |
| 799 | auto &Ctx = getASTContext(); |
| 800 | bool IsByRef = true; |
| 801 | |
| 802 | // Find the directive that is associated with the provided scope. |
| 803 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 804 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 805 | |
| 806 | if (isOpenMPTargetDirective(DKind)) { |
| 807 | // This table summarizes how a given variable should be passed to the device |
| 808 | // given its type and the clauses where it appears. This table is based on |
| 809 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 810 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 811 | // |
| 812 | // ========================================================================= |
| 813 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 814 | // | |(tofrom:scalar)| | pvt | | | | |
| 815 | // ========================================================================= |
| 816 | // | scl | | | | - | | bycopy| |
| 817 | // | scl | | - | x | - | - | bycopy| |
| 818 | // | scl | | x | - | - | - | null | |
| 819 | // | scl | x | | | - | | byref | |
| 820 | // | scl | x | - | x | - | - | bycopy| |
| 821 | // | scl | x | x | - | - | - | null | |
| 822 | // | scl | | - | - | - | x | byref | |
| 823 | // | scl | x | - | - | - | x | byref | |
| 824 | // |
| 825 | // | agg | n.a. | | | - | | byref | |
| 826 | // | agg | n.a. | - | x | - | - | byref | |
| 827 | // | agg | n.a. | x | - | - | - | null | |
| 828 | // | agg | n.a. | - | - | - | x | byref | |
| 829 | // | agg | n.a. | - | - | - | x[] | byref | |
| 830 | // |
| 831 | // | ptr | n.a. | | | - | | bycopy| |
| 832 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 833 | // | ptr | n.a. | x | - | - | - | null | |
| 834 | // | ptr | n.a. | - | - | - | x | byref | |
| 835 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 836 | // | ptr | n.a. | - | - | x | | bycopy| |
| 837 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 838 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 839 | // ========================================================================= |
| 840 | // Legend: |
| 841 | // scl - scalar |
| 842 | // ptr - pointer |
| 843 | // agg - aggregate |
| 844 | // x - applies |
| 845 | // - - invalid in this combination |
| 846 | // [] - mapped with an array section |
| 847 | // byref - should be mapped by reference |
| 848 | // byval - should be mapped by value |
| 849 | // null - initialize a local variable to null on the device |
| 850 | // |
| 851 | // Observations: |
| 852 | // - All scalar declarations that show up in a map clause have to be passed |
| 853 | // by reference, because they may have been mapped in the enclosing data |
| 854 | // environment. |
| 855 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 856 | // passed by reference, regardless the result in the table above. |
| 857 | // - For pointers mapped by value that have either an implicit map or an |
| 858 | // array section, the runtime library may pass the NULL value to the |
| 859 | // device instead of the value passed to it by the compiler. |
| 860 | |
| 861 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 862 | // values requires having the map, private, and firstprivate clauses SEMA |
| 863 | // and parsing in place, which we don't yet. |
| 864 | |
| 865 | if (Ty->isReferenceType()) |
| 866 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 867 | IsByRef = !Ty->isScalarType(); |
| 868 | } |
| 869 | |
| 870 | // When passing data by value, we need to make sure it fits the uintptr size |
| 871 | // and alignment, because the runtime library only deals with uintptr types. |
| 872 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 873 | // instead. |
| 874 | if (!IsByRef && |
| 875 | (Ctx.getTypeSizeInChars(Ty) > |
| 876 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 877 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 878 | IsByRef = true; |
| 879 | |
| 880 | return IsByRef; |
| 881 | } |
| 882 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 883 | bool Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 884 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 885 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 886 | |
| 887 | // If we are attempting to capture a global variable in a directive with |
| 888 | // 'target' we return true so that this global is also mapped to the device. |
| 889 | // |
| 890 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 891 | // then it should not be captured. Therefore, an extra check has to be |
| 892 | // inserted here once support for 'declare target' is added. |
| 893 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 894 | auto *VD = dyn_cast<VarDecl>(D); |
| 895 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 896 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 897 | !DSAStack->isClauseParsingMode()) { |
| 898 | return true; |
| 899 | } |
| 900 | if (DSAStack->getCurScope() && |
| 901 | DSAStack->hasDirective( |
| 902 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 903 | SourceLocation Loc) -> bool { |
| 904 | return isOpenMPTargetDirective(K); |
| 905 | }, |
| 906 | false)) { |
| 907 | return true; |
| 908 | } |
| 909 | } |
| 910 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 911 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 912 | (!DSAStack->isClauseParsingMode() || |
| 913 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 914 | if (DSAStack->isLoopControlVariable(D) || |
| 915 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 916 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 917 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 918 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 919 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 920 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 921 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 922 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 923 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 924 | return DVarPrivate.CKind != OMPC_unknown; |
| 925 | } |
| 926 | return false; |
| 927 | } |
| 928 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 929 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 930 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 931 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 932 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 935 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 936 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 937 | // Return true if the current level is no longer enclosed in a target region. |
| 938 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 939 | auto *VD = dyn_cast<VarDecl>(D); |
| 940 | return VD && !VD->hasLocalStorage() && |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 941 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 942 | } |
| 943 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 944 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 945 | |
| 946 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 947 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 948 | Scope *CurScope, SourceLocation Loc) { |
| 949 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 950 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 951 | } |
| 952 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 953 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 954 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 957 | void Sema::EndOpenMPClause() { |
| 958 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 961 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 962 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 963 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 964 | // clause requires an accessible, unambiguous default constructor for the |
| 965 | // class type, unless the list item is also specified in a firstprivate |
| 966 | // clause. |
| 967 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 968 | for (auto *C : D->clauses()) { |
| 969 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 970 | SmallVector<Expr *, 8> PrivateCopies; |
| 971 | for (auto *DE : Clause->varlists()) { |
| 972 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 973 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 974 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 975 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 976 | DE = DE->IgnoreParens(); |
| 977 | VarDecl *VD = nullptr; |
| 978 | FieldDecl *FD = nullptr; |
| 979 | ValueDecl *D; |
| 980 | if (auto *DRE = dyn_cast<DeclRefExpr>(DE)) { |
| 981 | VD = cast<VarDecl>(DRE->getDecl()); |
| 982 | D = VD; |
| 983 | } else { |
| 984 | assert(isa<MemberExpr>(DE)); |
| 985 | FD = cast<FieldDecl>(cast<MemberExpr>(DE)->getMemberDecl()); |
| 986 | D = FD; |
| 987 | } |
| 988 | QualType Type = D->getType().getNonReferenceType(); |
| 989 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 990 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 991 | // Generate helper private variable and initialize it with the |
| 992 | // default value. The address of the original variable is replaced |
| 993 | // by the address of the new private variable in CodeGen. This new |
| 994 | // variable is not added to IdResolver, so the code in the OpenMP |
| 995 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 996 | auto *VDPrivate = buildVarDecl( |
| 997 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 998 | D->getName(), D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 999 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1000 | if (VDPrivate->isInvalidDecl()) |
| 1001 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1002 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1003 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1004 | } else { |
| 1005 | // The variable is also a firstprivate, so initialization sequence |
| 1006 | // for private copy is generated already. |
| 1007 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1008 | } |
| 1009 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1010 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1011 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1012 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1017 | DSAStack->pop(); |
| 1018 | DiscardCleanupsInEvaluationContext(); |
| 1019 | PopExpressionEvaluationContext(); |
| 1020 | } |
| 1021 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1022 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1023 | Expr *NumIterations, Sema &SemaRef, |
| 1024 | Scope *S); |
| 1025 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1026 | namespace { |
| 1027 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1028 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1029 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1030 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1031 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1032 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1033 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1034 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1035 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1036 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1037 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1038 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1039 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1040 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1041 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1042 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1043 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1044 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1045 | |
| 1046 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1047 | CXXScopeSpec &ScopeSpec, |
| 1048 | const DeclarationNameInfo &Id) { |
| 1049 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1050 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1051 | |
| 1052 | if (Lookup.isAmbiguous()) |
| 1053 | return ExprError(); |
| 1054 | |
| 1055 | VarDecl *VD; |
| 1056 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1057 | if (TypoCorrection Corrected = CorrectTypo( |
| 1058 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1059 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1060 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1061 | PDiag(Lookup.empty() |
| 1062 | ? diag::err_undeclared_var_use_suggest |
| 1063 | : diag::err_omp_expected_var_arg_suggest) |
| 1064 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1065 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1066 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1067 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1068 | : diag::err_omp_expected_var_arg) |
| 1069 | << Id.getName(); |
| 1070 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1071 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1072 | } else { |
| 1073 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1074 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1075 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1076 | return ExprError(); |
| 1077 | } |
| 1078 | } |
| 1079 | Lookup.suppressDiagnostics(); |
| 1080 | |
| 1081 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1082 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1083 | if (!VD->hasGlobalStorage()) { |
| 1084 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1085 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1086 | bool IsDecl = |
| 1087 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1088 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1089 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1090 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1091 | return ExprError(); |
| 1092 | } |
| 1093 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1094 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1095 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1096 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1097 | // A threadprivate directive for file-scope variables must appear outside |
| 1098 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1099 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1100 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1101 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1102 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1103 | bool IsDecl = |
| 1104 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1105 | Diag(VD->getLocation(), |
| 1106 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1107 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1108 | return ExprError(); |
| 1109 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1110 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1111 | // A threadprivate directive for static class member variables must appear |
| 1112 | // in the class definition, in the same scope in which the member |
| 1113 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1114 | if (CanonicalVD->isStaticDataMember() && |
| 1115 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1116 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1117 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1118 | bool IsDecl = |
| 1119 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1120 | Diag(VD->getLocation(), |
| 1121 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1122 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1123 | return ExprError(); |
| 1124 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1125 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1126 | // A threadprivate directive for namespace-scope variables must appear |
| 1127 | // outside any definition or declaration other than the namespace |
| 1128 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1129 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1130 | (!getCurLexicalContext()->isFileContext() || |
| 1131 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1132 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1133 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1134 | bool IsDecl = |
| 1135 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1136 | Diag(VD->getLocation(), |
| 1137 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1138 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1139 | return ExprError(); |
| 1140 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1141 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1142 | // A threadprivate directive for static block-scope variables must appear |
| 1143 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1144 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1145 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1146 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1147 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1148 | bool IsDecl = |
| 1149 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1150 | Diag(VD->getLocation(), |
| 1151 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1152 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1153 | return ExprError(); |
| 1154 | } |
| 1155 | |
| 1156 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1157 | // A threadprivate directive must lexically precede all references to any |
| 1158 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1159 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1160 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1161 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1162 | return ExprError(); |
| 1163 | } |
| 1164 | |
| 1165 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1166 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1167 | return DE; |
| 1168 | } |
| 1169 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1170 | Sema::DeclGroupPtrTy |
| 1171 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1172 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1173 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1174 | CurContext->addDecl(D); |
| 1175 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1176 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1177 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1180 | namespace { |
| 1181 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1182 | Sema &SemaRef; |
| 1183 | |
| 1184 | public: |
| 1185 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1186 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1187 | if (VD->hasLocalStorage()) { |
| 1188 | SemaRef.Diag(E->getLocStart(), |
| 1189 | diag::err_omp_local_var_in_threadprivate_init) |
| 1190 | << E->getSourceRange(); |
| 1191 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1192 | << VD << VD->getSourceRange(); |
| 1193 | return true; |
| 1194 | } |
| 1195 | } |
| 1196 | return false; |
| 1197 | } |
| 1198 | bool VisitStmt(const Stmt *S) { |
| 1199 | for (auto Child : S->children()) { |
| 1200 | if (Child && Visit(Child)) |
| 1201 | return true; |
| 1202 | } |
| 1203 | return false; |
| 1204 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1205 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1206 | }; |
| 1207 | } // namespace |
| 1208 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1209 | OMPThreadPrivateDecl * |
| 1210 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1211 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1212 | for (auto &RefExpr : VarList) { |
| 1213 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1214 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1215 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1216 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1217 | QualType QType = VD->getType(); |
| 1218 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1219 | // It will be analyzed later. |
| 1220 | Vars.push_back(DE); |
| 1221 | continue; |
| 1222 | } |
| 1223 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1224 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1225 | // A threadprivate variable must not have an incomplete type. |
| 1226 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1227 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1228 | continue; |
| 1229 | } |
| 1230 | |
| 1231 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1232 | // A threadprivate variable must not have a reference type. |
| 1233 | if (VD->getType()->isReferenceType()) { |
| 1234 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1235 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1236 | bool IsDecl = |
| 1237 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1238 | Diag(VD->getLocation(), |
| 1239 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1240 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1241 | continue; |
| 1242 | } |
| 1243 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1244 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1245 | // the corresponding diagnostic. |
| 1246 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1247 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1248 | getLangOpts().OpenMPUseTLS && |
| 1249 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1250 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1251 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1252 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1253 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1254 | bool IsDecl = |
| 1255 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1256 | Diag(VD->getLocation(), |
| 1257 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1258 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1259 | continue; |
| 1260 | } |
| 1261 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1262 | // Check if initial value of threadprivate variable reference variable with |
| 1263 | // local storage (it is not supported by runtime). |
| 1264 | if (auto Init = VD->getAnyInitializer()) { |
| 1265 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1266 | if (Checker.Visit(Init)) |
| 1267 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1270 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1271 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1272 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1273 | Context, SourceRange(Loc, Loc))); |
| 1274 | if (auto *ML = Context.getASTMutationListener()) |
| 1275 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1276 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1277 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1278 | if (!Vars.empty()) { |
| 1279 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1280 | Vars); |
| 1281 | D->setAccess(AS_public); |
| 1282 | } |
| 1283 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1284 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1285 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1286 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1287 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1288 | bool IsLoopIterVar = false) { |
| 1289 | if (DVar.RefExpr) { |
| 1290 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1291 | << getOpenMPClauseName(DVar.CKind); |
| 1292 | return; |
| 1293 | } |
| 1294 | enum { |
| 1295 | PDSA_StaticMemberShared, |
| 1296 | PDSA_StaticLocalVarShared, |
| 1297 | PDSA_LoopIterVarPrivate, |
| 1298 | PDSA_LoopIterVarLinear, |
| 1299 | PDSA_LoopIterVarLastprivate, |
| 1300 | PDSA_ConstVarShared, |
| 1301 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1302 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1303 | PDSA_LocalVarPrivate, |
| 1304 | PDSA_Implicit |
| 1305 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1306 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1307 | auto ReportLoc = D->getLocation(); |
| 1308 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1309 | if (IsLoopIterVar) { |
| 1310 | if (DVar.CKind == OMPC_private) |
| 1311 | Reason = PDSA_LoopIterVarPrivate; |
| 1312 | else if (DVar.CKind == OMPC_lastprivate) |
| 1313 | Reason = PDSA_LoopIterVarLastprivate; |
| 1314 | else |
| 1315 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1316 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1317 | Reason = PDSA_TaskVarFirstprivate; |
| 1318 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1319 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1320 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1321 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1322 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1323 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1324 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1325 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1326 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1327 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1328 | ReportHint = true; |
| 1329 | Reason = PDSA_LocalVarPrivate; |
| 1330 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1331 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1332 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1333 | << Reason << ReportHint |
| 1334 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1335 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1336 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1337 | << getOpenMPClauseName(DVar.CKind); |
| 1338 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1341 | namespace { |
| 1342 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1343 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1344 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1345 | bool ErrorFound; |
| 1346 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1347 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1348 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1349 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1350 | public: |
| 1351 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1352 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1353 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1354 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1355 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1356 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1357 | auto DVar = Stack->getTopDSA(VD, false); |
| 1358 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1359 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1361 | auto ELoc = E->getExprLoc(); |
| 1362 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1363 | // The default(none) clause requires that each variable that is referenced |
| 1364 | // in the construct, and does not have a predetermined data-sharing |
| 1365 | // attribute, must have its data-sharing attribute explicitly determined |
| 1366 | // by being listed in a data-sharing attribute clause. |
| 1367 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1368 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1369 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1370 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1371 | return; |
| 1372 | } |
| 1373 | |
| 1374 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1375 | // A list item that appears in a reduction clause of the innermost |
| 1376 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1377 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1378 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1379 | [](OpenMPDirectiveKind K) -> bool { |
| 1380 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1381 | isOpenMPWorksharingDirective(K) || |
| 1382 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1383 | }, |
| 1384 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1385 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1386 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1387 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1388 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1389 | return; |
| 1390 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1391 | |
| 1392 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1393 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1394 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1395 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1398 | void VisitMemberExpr(MemberExpr *E) { |
| 1399 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1400 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1401 | auto DVar = Stack->getTopDSA(FD, false); |
| 1402 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1403 | // so. |
| 1404 | if (DVar.RefExpr) |
| 1405 | return; |
| 1406 | |
| 1407 | auto ELoc = E->getExprLoc(); |
| 1408 | auto DKind = Stack->getCurrentDirective(); |
| 1409 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1410 | // A list item that appears in a reduction clause of the innermost |
| 1411 | // enclosing worksharing or parallel construct may not be accessed in |
| 1412 | // an |
| 1413 | // explicit task. |
| 1414 | DVar = |
| 1415 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1416 | [](OpenMPDirectiveKind K) -> bool { |
| 1417 | return isOpenMPParallelDirective(K) || |
| 1418 | isOpenMPWorksharingDirective(K) || |
| 1419 | isOpenMPTeamsDirective(K); |
| 1420 | }, |
| 1421 | false); |
| 1422 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1423 | ErrorFound = true; |
| 1424 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1425 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1426 | return; |
| 1427 | } |
| 1428 | |
| 1429 | // Define implicit data-sharing attributes for task. |
| 1430 | DVar = Stack->getImplicitDSA(FD, false); |
| 1431 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1432 | ImplicitFirstprivate.push_back(E); |
| 1433 | } |
| 1434 | } |
| 1435 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1436 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1437 | for (auto *C : S->clauses()) { |
| 1438 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1439 | // for task directives. |
| 1440 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1441 | for (auto *CC : C->children()) { |
| 1442 | if (CC) |
| 1443 | Visit(CC); |
| 1444 | } |
| 1445 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1446 | } |
| 1447 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1448 | for (auto *C : S->children()) { |
| 1449 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1450 | Visit(C); |
| 1451 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1452 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1453 | |
| 1454 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1455 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1456 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1457 | return VarsWithInheritedDSA; |
| 1458 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1460 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1461 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1463 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1464 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1465 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1466 | switch (DKind) { |
| 1467 | case OMPD_parallel: { |
| 1468 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1469 | QualType KmpInt32PtrTy = |
| 1470 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1471 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1472 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1473 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1474 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1475 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1476 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1477 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1478 | break; |
| 1479 | } |
| 1480 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1481 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1482 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1483 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1484 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1485 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1486 | break; |
| 1487 | } |
| 1488 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1489 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1490 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1491 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1492 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1493 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1494 | break; |
| 1495 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1496 | case OMPD_for_simd: { |
| 1497 | Sema::CapturedParamNameType Params[] = { |
| 1498 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1499 | }; |
| 1500 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1501 | Params); |
| 1502 | break; |
| 1503 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1504 | case OMPD_sections: { |
| 1505 | Sema::CapturedParamNameType Params[] = { |
| 1506 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1507 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1508 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1509 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1510 | break; |
| 1511 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1512 | case OMPD_section: { |
| 1513 | Sema::CapturedParamNameType Params[] = { |
| 1514 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1515 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1516 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1517 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1518 | break; |
| 1519 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1520 | case OMPD_single: { |
| 1521 | Sema::CapturedParamNameType Params[] = { |
| 1522 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1523 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1524 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1525 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1528 | case OMPD_master: { |
| 1529 | Sema::CapturedParamNameType Params[] = { |
| 1530 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1531 | }; |
| 1532 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1533 | Params); |
| 1534 | break; |
| 1535 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1536 | case OMPD_critical: { |
| 1537 | Sema::CapturedParamNameType Params[] = { |
| 1538 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1539 | }; |
| 1540 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1541 | Params); |
| 1542 | break; |
| 1543 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1544 | case OMPD_parallel_for: { |
| 1545 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1546 | QualType KmpInt32PtrTy = |
| 1547 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1548 | Sema::CapturedParamNameType Params[] = { |
| 1549 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1550 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1551 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1552 | }; |
| 1553 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1554 | Params); |
| 1555 | break; |
| 1556 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1557 | case OMPD_parallel_for_simd: { |
| 1558 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1559 | QualType KmpInt32PtrTy = |
| 1560 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1561 | Sema::CapturedParamNameType Params[] = { |
| 1562 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1563 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1564 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1565 | }; |
| 1566 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1567 | Params); |
| 1568 | break; |
| 1569 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1570 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1571 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1572 | QualType KmpInt32PtrTy = |
| 1573 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1574 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1575 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1576 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1577 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1578 | }; |
| 1579 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1580 | Params); |
| 1581 | break; |
| 1582 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1583 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1584 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1585 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1586 | FunctionProtoType::ExtProtoInfo EPI; |
| 1587 | EPI.Variadic = true; |
| 1588 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1589 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1590 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1591 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1592 | std::make_pair(".privates.", |
| 1593 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1594 | std::make_pair( |
| 1595 | ".copy_fn.", |
| 1596 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1597 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1598 | }; |
| 1599 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1600 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1601 | // Mark this captured region as inlined, because we don't use outlined |
| 1602 | // function directly. |
| 1603 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1604 | AlwaysInlineAttr::CreateImplicit( |
| 1605 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1606 | break; |
| 1607 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1608 | case OMPD_ordered: { |
| 1609 | Sema::CapturedParamNameType Params[] = { |
| 1610 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1611 | }; |
| 1612 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1613 | Params); |
| 1614 | break; |
| 1615 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1616 | case OMPD_atomic: { |
| 1617 | Sema::CapturedParamNameType Params[] = { |
| 1618 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1619 | }; |
| 1620 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1621 | Params); |
| 1622 | break; |
| 1623 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1624 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1625 | case OMPD_target: { |
| 1626 | Sema::CapturedParamNameType Params[] = { |
| 1627 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1628 | }; |
| 1629 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1630 | Params); |
| 1631 | break; |
| 1632 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1633 | case OMPD_teams: { |
| 1634 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1635 | QualType KmpInt32PtrTy = |
| 1636 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1637 | Sema::CapturedParamNameType Params[] = { |
| 1638 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1639 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1640 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1641 | }; |
| 1642 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1643 | Params); |
| 1644 | break; |
| 1645 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1646 | case OMPD_taskgroup: { |
| 1647 | Sema::CapturedParamNameType Params[] = { |
| 1648 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1649 | }; |
| 1650 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1651 | Params); |
| 1652 | break; |
| 1653 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1654 | case OMPD_taskloop: { |
| 1655 | Sema::CapturedParamNameType Params[] = { |
| 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 | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1662 | case OMPD_taskloop_simd: { |
| 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 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1670 | case OMPD_distribute: { |
| 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 | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1678 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1679 | case OMPD_taskyield: |
| 1680 | case OMPD_barrier: |
| 1681 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1682 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1683 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1684 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1685 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1686 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1687 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1688 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1689 | llvm_unreachable("Unknown OpenMP directive"); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1693 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1694 | ArrayRef<OMPClause *> Clauses) { |
| 1695 | if (!S.isUsable()) { |
| 1696 | ActOnCapturedRegionError(); |
| 1697 | return StmtError(); |
| 1698 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1699 | |
| 1700 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1701 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1702 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1703 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1704 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1705 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1706 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1707 | (getLangOpts().OpenMPUseTLS && |
| 1708 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1709 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1710 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1711 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1712 | for (auto *VarRef : Clause->children()) { |
| 1713 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1714 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1715 | } |
| 1716 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1717 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1718 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1719 | Clause->getClauseKind() == OMPC_schedule) { |
| 1720 | // Mark all variables in private list clauses as used in inner region. |
| 1721 | // Required for proper codegen of combined directives. |
| 1722 | // TODO: add processing for other clauses. |
| 1723 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1724 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1725 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1726 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1727 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1728 | SC = cast<OMPScheduleClause>(Clause); |
| 1729 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1730 | OC = cast<OMPOrderedClause>(Clause); |
| 1731 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1732 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1733 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1734 | bool ErrorFound = false; |
| 1735 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1736 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1737 | // specified. |
| 1738 | if (SC && |
| 1739 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1740 | SC->getSecondScheduleModifier() == |
| 1741 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1742 | OC) { |
| 1743 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1744 | ? SC->getFirstScheduleModifierLoc() |
| 1745 | : SC->getSecondScheduleModifierLoc(), |
| 1746 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1747 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1748 | ErrorFound = true; |
| 1749 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1750 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1751 | for (auto *C : LCs) { |
| 1752 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1753 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1754 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1755 | ErrorFound = true; |
| 1756 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1757 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1758 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1759 | OC->getNumForLoops()) { |
| 1760 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1761 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1762 | ErrorFound = true; |
| 1763 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1764 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1765 | ActOnCapturedRegionError(); |
| 1766 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1767 | } |
| 1768 | return ActOnCapturedRegionEnd(S.get()); |
| 1769 | } |
| 1770 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1771 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1772 | OpenMPDirectiveKind CurrentRegion, |
| 1773 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1774 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1775 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1776 | // Allowed nesting of constructs |
| 1777 | // +------------------+-----------------+------------------------------------+ |
| 1778 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1779 | // +------------------+-----------------+------------------------------------+ |
| 1780 | // | parallel | parallel | * | |
| 1781 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1782 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1783 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1784 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1785 | // | parallel | simd | * | |
| 1786 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1787 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1788 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1789 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1790 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1791 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1792 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1793 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1794 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1795 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1796 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1797 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1798 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1799 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1800 | // | parallel | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1801 | // | parallel | target enter | * | |
| 1802 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1803 | // | parallel | target exit | * | |
| 1804 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1805 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1806 | // | parallel | cancellation | | |
| 1807 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1808 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1809 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1810 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1811 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1812 | // +------------------+-----------------+------------------------------------+ |
| 1813 | // | for | parallel | * | |
| 1814 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1815 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1816 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1817 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1818 | // | for | simd | * | |
| 1819 | // | for | sections | + | |
| 1820 | // | for | section | + | |
| 1821 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1822 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1823 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1824 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1825 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1826 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1827 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1828 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1829 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1830 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1831 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1832 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1833 | // | for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1834 | // | for | target enter | * | |
| 1835 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1836 | // | for | target exit | * | |
| 1837 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1838 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1839 | // | for | cancellation | | |
| 1840 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1841 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1842 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1843 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1844 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1845 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1846 | // | master | parallel | * | |
| 1847 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1848 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1849 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1850 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1851 | // | master | simd | * | |
| 1852 | // | master | sections | + | |
| 1853 | // | master | section | + | |
| 1854 | // | master | single | + | |
| 1855 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1856 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1857 | // | master |parallel sections| * | |
| 1858 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1859 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1860 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1861 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1862 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1863 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1864 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1865 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1866 | // | master | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1867 | // | master | target enter | * | |
| 1868 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1869 | // | master | target exit | * | |
| 1870 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1871 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1872 | // | master | cancellation | | |
| 1873 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1874 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1875 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1876 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1877 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1878 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1879 | // | critical | parallel | * | |
| 1880 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1881 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1882 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1883 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1884 | // | critical | simd | * | |
| 1885 | // | critical | sections | + | |
| 1886 | // | critical | section | + | |
| 1887 | // | critical | single | + | |
| 1888 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1889 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1890 | // | critical |parallel sections| * | |
| 1891 | // | critical | task | * | |
| 1892 | // | critical | taskyield | * | |
| 1893 | // | critical | barrier | + | |
| 1894 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1895 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1896 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1897 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1898 | // | critical | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1899 | // | critical | target enter | * | |
| 1900 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1901 | // | critical | target exit | * | |
| 1902 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1903 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1904 | // | critical | cancellation | | |
| 1905 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1906 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1907 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1908 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1909 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1910 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1911 | // | simd | parallel | | |
| 1912 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1913 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1914 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1915 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1916 | // | simd | simd | | |
| 1917 | // | simd | sections | | |
| 1918 | // | simd | section | | |
| 1919 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1920 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1921 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1922 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1923 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1924 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1925 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1926 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1927 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1928 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1929 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1930 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1931 | // | simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1932 | // | simd | target enter | | |
| 1933 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1934 | // | simd | target exit | | |
| 1935 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1936 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1937 | // | simd | cancellation | | |
| 1938 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1939 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1940 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1941 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1942 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1943 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1944 | // | for simd | parallel | | |
| 1945 | // | for simd | for | | |
| 1946 | // | for simd | for simd | | |
| 1947 | // | for simd | master | | |
| 1948 | // | for simd | critical | | |
| 1949 | // | for simd | simd | | |
| 1950 | // | for simd | sections | | |
| 1951 | // | for simd | section | | |
| 1952 | // | for simd | single | | |
| 1953 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1954 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1955 | // | for simd |parallel sections| | |
| 1956 | // | for simd | task | | |
| 1957 | // | for simd | taskyield | | |
| 1958 | // | for simd | barrier | | |
| 1959 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1960 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1961 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1962 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1963 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1964 | // | for simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1965 | // | for simd | target enter | | |
| 1966 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1967 | // | for simd | target exit | | |
| 1968 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1969 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1970 | // | for simd | cancellation | | |
| 1971 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1972 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1973 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1974 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1975 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1976 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1977 | // | parallel for simd| parallel | | |
| 1978 | // | parallel for simd| for | | |
| 1979 | // | parallel for simd| for simd | | |
| 1980 | // | parallel for simd| master | | |
| 1981 | // | parallel for simd| critical | | |
| 1982 | // | parallel for simd| simd | | |
| 1983 | // | parallel for simd| sections | | |
| 1984 | // | parallel for simd| section | | |
| 1985 | // | parallel for simd| single | | |
| 1986 | // | parallel for simd| parallel for | | |
| 1987 | // | parallel for simd|parallel for simd| | |
| 1988 | // | parallel for simd|parallel sections| | |
| 1989 | // | parallel for simd| task | | |
| 1990 | // | parallel for simd| taskyield | | |
| 1991 | // | parallel for simd| barrier | | |
| 1992 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1993 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1994 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1995 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1996 | // | parallel for simd| atomic | | |
| 1997 | // | parallel for simd| target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1998 | // | parallel for simd| target enter | | |
| 1999 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2000 | // | parallel for simd| target exit | | |
| 2001 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2002 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2003 | // | parallel for simd| cancellation | | |
| 2004 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2005 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2006 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2007 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2008 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2009 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2010 | // | sections | parallel | * | |
| 2011 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2012 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2013 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2014 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2015 | // | sections | simd | * | |
| 2016 | // | sections | sections | + | |
| 2017 | // | sections | section | * | |
| 2018 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2019 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2020 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2021 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2022 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2023 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2024 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2025 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2026 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2027 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2028 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2029 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2030 | // | sections | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2031 | // | sections | target enter | * | |
| 2032 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2033 | // | sections | target exit | * | |
| 2034 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2035 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2036 | // | sections | cancellation | | |
| 2037 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2038 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2039 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2040 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2041 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2042 | // +------------------+-----------------+------------------------------------+ |
| 2043 | // | section | parallel | * | |
| 2044 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2045 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2046 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2047 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2048 | // | section | simd | * | |
| 2049 | // | section | sections | + | |
| 2050 | // | section | section | + | |
| 2051 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2052 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2053 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2054 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2055 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2056 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2057 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2058 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2059 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2060 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2061 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2062 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2063 | // | section | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2064 | // | section | target enter | * | |
| 2065 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2066 | // | section | target exit | * | |
| 2067 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2068 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2069 | // | section | cancellation | | |
| 2070 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2071 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2072 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2073 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2074 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2075 | // +------------------+-----------------+------------------------------------+ |
| 2076 | // | single | parallel | * | |
| 2077 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2078 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2079 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2080 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2081 | // | single | simd | * | |
| 2082 | // | single | sections | + | |
| 2083 | // | single | section | + | |
| 2084 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2085 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2086 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2087 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2088 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2089 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2090 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2091 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2092 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2093 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2094 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2095 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2096 | // | single | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2097 | // | single | target enter | * | |
| 2098 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2099 | // | single | target exit | * | |
| 2100 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2101 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2102 | // | single | cancellation | | |
| 2103 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2104 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2105 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2106 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2107 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2108 | // +------------------+-----------------+------------------------------------+ |
| 2109 | // | parallel for | parallel | * | |
| 2110 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2111 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2112 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2113 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2114 | // | parallel for | simd | * | |
| 2115 | // | parallel for | sections | + | |
| 2116 | // | parallel for | section | + | |
| 2117 | // | parallel for | single | + | |
| 2118 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2119 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2120 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2121 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2122 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2123 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2124 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2125 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2126 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2127 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2128 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2129 | // | parallel for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2130 | // | parallel for | target enter | * | |
| 2131 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2132 | // | parallel for | target exit | * | |
| 2133 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2134 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2135 | // | parallel for | cancellation | | |
| 2136 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2137 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2138 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2139 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2140 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2141 | // +------------------+-----------------+------------------------------------+ |
| 2142 | // | parallel sections| parallel | * | |
| 2143 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2144 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2145 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2146 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2147 | // | parallel sections| simd | * | |
| 2148 | // | parallel sections| sections | + | |
| 2149 | // | parallel sections| section | * | |
| 2150 | // | parallel sections| single | + | |
| 2151 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2152 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2153 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2154 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2155 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2156 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2157 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2158 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2159 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2160 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2161 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2162 | // | parallel sections| target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2163 | // | parallel sections| target enter | * | |
| 2164 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2165 | // | parallel sections| target exit | * | |
| 2166 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2167 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2168 | // | parallel sections| cancellation | | |
| 2169 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2170 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2171 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2172 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2173 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2174 | // +------------------+-----------------+------------------------------------+ |
| 2175 | // | task | parallel | * | |
| 2176 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2177 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2178 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2179 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2180 | // | task | simd | * | |
| 2181 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2182 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2183 | // | task | single | + | |
| 2184 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2185 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2186 | // | task |parallel sections| * | |
| 2187 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2188 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2189 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2190 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2191 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2192 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2193 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2194 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2195 | // | task | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2196 | // | task | target enter | * | |
| 2197 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2198 | // | task | target exit | * | |
| 2199 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2200 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2201 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2202 | // | | point | ! | |
| 2203 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2204 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2205 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2206 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2207 | // +------------------+-----------------+------------------------------------+ |
| 2208 | // | ordered | parallel | * | |
| 2209 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2210 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2211 | // | ordered | master | * | |
| 2212 | // | ordered | critical | * | |
| 2213 | // | ordered | simd | * | |
| 2214 | // | ordered | sections | + | |
| 2215 | // | ordered | section | + | |
| 2216 | // | ordered | single | + | |
| 2217 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2218 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2219 | // | ordered |parallel sections| * | |
| 2220 | // | ordered | task | * | |
| 2221 | // | ordered | taskyield | * | |
| 2222 | // | ordered | barrier | + | |
| 2223 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2224 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2225 | // | ordered | flush | * | |
| 2226 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2227 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2228 | // | ordered | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2229 | // | ordered | target enter | * | |
| 2230 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2231 | // | ordered | target exit | * | |
| 2232 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2233 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2234 | // | ordered | cancellation | | |
| 2235 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2236 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2237 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2238 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2239 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2240 | // +------------------+-----------------+------------------------------------+ |
| 2241 | // | atomic | parallel | | |
| 2242 | // | atomic | for | | |
| 2243 | // | atomic | for simd | | |
| 2244 | // | atomic | master | | |
| 2245 | // | atomic | critical | | |
| 2246 | // | atomic | simd | | |
| 2247 | // | atomic | sections | | |
| 2248 | // | atomic | section | | |
| 2249 | // | atomic | single | | |
| 2250 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2251 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2252 | // | atomic |parallel sections| | |
| 2253 | // | atomic | task | | |
| 2254 | // | atomic | taskyield | | |
| 2255 | // | atomic | barrier | | |
| 2256 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2257 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2258 | // | atomic | flush | | |
| 2259 | // | atomic | ordered | | |
| 2260 | // | atomic | atomic | | |
| 2261 | // | atomic | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2262 | // | atomic | target enter | | |
| 2263 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2264 | // | atomic | target exit | | |
| 2265 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2266 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2267 | // | atomic | cancellation | | |
| 2268 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2269 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2270 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2271 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2272 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2273 | // +------------------+-----------------+------------------------------------+ |
| 2274 | // | target | parallel | * | |
| 2275 | // | target | for | * | |
| 2276 | // | target | for simd | * | |
| 2277 | // | target | master | * | |
| 2278 | // | target | critical | * | |
| 2279 | // | target | simd | * | |
| 2280 | // | target | sections | * | |
| 2281 | // | target | section | * | |
| 2282 | // | target | single | * | |
| 2283 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2284 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2285 | // | target |parallel sections| * | |
| 2286 | // | target | task | * | |
| 2287 | // | target | taskyield | * | |
| 2288 | // | target | barrier | * | |
| 2289 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2290 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2291 | // | target | flush | * | |
| 2292 | // | target | ordered | * | |
| 2293 | // | target | atomic | * | |
| 2294 | // | target | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2295 | // | target | target enter | * | |
| 2296 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2297 | // | target | target exit | * | |
| 2298 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2299 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2300 | // | target | cancellation | | |
| 2301 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2302 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2303 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2304 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2305 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2306 | // +------------------+-----------------+------------------------------------+ |
| 2307 | // | teams | parallel | * | |
| 2308 | // | teams | for | + | |
| 2309 | // | teams | for simd | + | |
| 2310 | // | teams | master | + | |
| 2311 | // | teams | critical | + | |
| 2312 | // | teams | simd | + | |
| 2313 | // | teams | sections | + | |
| 2314 | // | teams | section | + | |
| 2315 | // | teams | single | + | |
| 2316 | // | teams | parallel for | * | |
| 2317 | // | teams |parallel for simd| * | |
| 2318 | // | teams |parallel sections| * | |
| 2319 | // | teams | task | + | |
| 2320 | // | teams | taskyield | + | |
| 2321 | // | teams | barrier | + | |
| 2322 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2323 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2324 | // | teams | flush | + | |
| 2325 | // | teams | ordered | + | |
| 2326 | // | teams | atomic | + | |
| 2327 | // | teams | target | + | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2328 | // | teams | target enter | + | |
| 2329 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2330 | // | teams | target exit | + | |
| 2331 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2332 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2333 | // | teams | cancellation | | |
| 2334 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2335 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2336 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2337 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2338 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2339 | // +------------------+-----------------+------------------------------------+ |
| 2340 | // | taskloop | parallel | * | |
| 2341 | // | taskloop | for | + | |
| 2342 | // | taskloop | for simd | + | |
| 2343 | // | taskloop | master | + | |
| 2344 | // | taskloop | critical | * | |
| 2345 | // | taskloop | simd | * | |
| 2346 | // | taskloop | sections | + | |
| 2347 | // | taskloop | section | + | |
| 2348 | // | taskloop | single | + | |
| 2349 | // | taskloop | parallel for | * | |
| 2350 | // | taskloop |parallel for simd| * | |
| 2351 | // | taskloop |parallel sections| * | |
| 2352 | // | taskloop | task | * | |
| 2353 | // | taskloop | taskyield | * | |
| 2354 | // | taskloop | barrier | + | |
| 2355 | // | taskloop | taskwait | * | |
| 2356 | // | taskloop | taskgroup | * | |
| 2357 | // | taskloop | flush | * | |
| 2358 | // | taskloop | ordered | + | |
| 2359 | // | taskloop | atomic | * | |
| 2360 | // | taskloop | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2361 | // | taskloop | target enter | * | |
| 2362 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2363 | // | taskloop | target exit | * | |
| 2364 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2365 | // | taskloop | teams | + | |
| 2366 | // | taskloop | cancellation | | |
| 2367 | // | | point | | |
| 2368 | // | taskloop | cancel | | |
| 2369 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2370 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2371 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2372 | // | taskloop simd | parallel | | |
| 2373 | // | taskloop simd | for | | |
| 2374 | // | taskloop simd | for simd | | |
| 2375 | // | taskloop simd | master | | |
| 2376 | // | taskloop simd | critical | | |
| 2377 | // | taskloop simd | simd | | |
| 2378 | // | taskloop simd | sections | | |
| 2379 | // | taskloop simd | section | | |
| 2380 | // | taskloop simd | single | | |
| 2381 | // | taskloop simd | parallel for | | |
| 2382 | // | taskloop simd |parallel for simd| | |
| 2383 | // | taskloop simd |parallel sections| | |
| 2384 | // | taskloop simd | task | | |
| 2385 | // | taskloop simd | taskyield | | |
| 2386 | // | taskloop simd | barrier | | |
| 2387 | // | taskloop simd | taskwait | | |
| 2388 | // | taskloop simd | taskgroup | | |
| 2389 | // | taskloop simd | flush | | |
| 2390 | // | taskloop simd | ordered | + (with simd clause) | |
| 2391 | // | taskloop simd | atomic | | |
| 2392 | // | taskloop simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2393 | // | taskloop simd | target enter | | |
| 2394 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2395 | // | taskloop simd | target exit | | |
| 2396 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2397 | // | taskloop simd | teams | | |
| 2398 | // | taskloop simd | cancellation | | |
| 2399 | // | | point | | |
| 2400 | // | taskloop simd | cancel | | |
| 2401 | // | taskloop simd | taskloop | | |
| 2402 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2403 | // | taskloop simd | distribute | | |
| 2404 | // +------------------+-----------------+------------------------------------+ |
| 2405 | // | distribute | parallel | * | |
| 2406 | // | distribute | for | * | |
| 2407 | // | distribute | for simd | * | |
| 2408 | // | distribute | master | * | |
| 2409 | // | distribute | critical | * | |
| 2410 | // | distribute | simd | * | |
| 2411 | // | distribute | sections | * | |
| 2412 | // | distribute | section | * | |
| 2413 | // | distribute | single | * | |
| 2414 | // | distribute | parallel for | * | |
| 2415 | // | distribute |parallel for simd| * | |
| 2416 | // | distribute |parallel sections| * | |
| 2417 | // | distribute | task | * | |
| 2418 | // | distribute | taskyield | * | |
| 2419 | // | distribute | barrier | * | |
| 2420 | // | distribute | taskwait | * | |
| 2421 | // | distribute | taskgroup | * | |
| 2422 | // | distribute | flush | * | |
| 2423 | // | distribute | ordered | + | |
| 2424 | // | distribute | atomic | * | |
| 2425 | // | distribute | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2426 | // | distribute | target enter | | |
| 2427 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2428 | // | distribute | target exit | | |
| 2429 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2430 | // | distribute | teams | | |
| 2431 | // | distribute | cancellation | + | |
| 2432 | // | | point | | |
| 2433 | // | distribute | cancel | + | |
| 2434 | // | distribute | taskloop | * | |
| 2435 | // | distribute | taskloop simd | * | |
| 2436 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2437 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2438 | if (Stack->getCurScope()) { |
| 2439 | auto ParentRegion = Stack->getParentDirective(); |
| 2440 | bool NestingProhibited = false; |
| 2441 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2442 | enum { |
| 2443 | NoRecommend, |
| 2444 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2445 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2446 | ShouldBeInTargetRegion, |
| 2447 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2448 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2449 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2450 | // OpenMP [2.16, Nesting of Regions] |
| 2451 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2452 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2453 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2454 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2455 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2456 | return true; |
| 2457 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2458 | if (ParentRegion == OMPD_atomic) { |
| 2459 | // OpenMP [2.16, Nesting of Regions] |
| 2460 | // OpenMP constructs may not be nested inside an atomic region. |
| 2461 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2462 | return true; |
| 2463 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2464 | if (CurrentRegion == OMPD_section) { |
| 2465 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2466 | // Orphaned section directives are prohibited. That is, the section |
| 2467 | // directives must appear within the sections construct and must not be |
| 2468 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2469 | if (ParentRegion != OMPD_sections && |
| 2470 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2471 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2472 | << (ParentRegion != OMPD_unknown) |
| 2473 | << getOpenMPDirectiveName(ParentRegion); |
| 2474 | return true; |
| 2475 | } |
| 2476 | return false; |
| 2477 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2478 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2479 | // called from OpenMP regions with the required preconditions). |
| 2480 | if (ParentRegion == OMPD_unknown) |
| 2481 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2482 | if (CurrentRegion == OMPD_cancellation_point || |
| 2483 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2484 | // OpenMP [2.16, Nesting of Regions] |
| 2485 | // A cancellation point construct for which construct-type-clause is |
| 2486 | // taskgroup must be nested inside a task construct. A cancellation |
| 2487 | // point construct for which construct-type-clause is not taskgroup must |
| 2488 | // be closely nested inside an OpenMP construct that matches the type |
| 2489 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2490 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2491 | // nested inside a task construct. A cancel construct for which |
| 2492 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2493 | // OpenMP construct that matches the type specified in |
| 2494 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2495 | NestingProhibited = |
| 2496 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2497 | (CancelRegion == OMPD_for && |
| 2498 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2499 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2500 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2501 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2502 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2503 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2504 | // OpenMP [2.16, Nesting of Regions] |
| 2505 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2506 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2507 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2508 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2509 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2510 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2511 | // OpenMP [2.16, Nesting of Regions] |
| 2512 | // A critical region may not be nested (closely or otherwise) inside a |
| 2513 | // critical region with the same name. Note that this restriction is not |
| 2514 | // sufficient to prevent deadlock. |
| 2515 | SourceLocation PreviousCriticalLoc; |
| 2516 | bool DeadLock = |
| 2517 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2518 | OpenMPDirectiveKind K, |
| 2519 | const DeclarationNameInfo &DNI, |
| 2520 | SourceLocation Loc) |
| 2521 | ->bool { |
| 2522 | if (K == OMPD_critical && |
| 2523 | DNI.getName() == CurrentName.getName()) { |
| 2524 | PreviousCriticalLoc = Loc; |
| 2525 | return true; |
| 2526 | } else |
| 2527 | return false; |
| 2528 | }, |
| 2529 | false /* skip top directive */); |
| 2530 | if (DeadLock) { |
| 2531 | SemaRef.Diag(StartLoc, |
| 2532 | diag::err_omp_prohibited_region_critical_same_name) |
| 2533 | << CurrentName.getName(); |
| 2534 | if (PreviousCriticalLoc.isValid()) |
| 2535 | SemaRef.Diag(PreviousCriticalLoc, |
| 2536 | diag::note_omp_previous_critical_region); |
| 2537 | return true; |
| 2538 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2539 | } else if (CurrentRegion == OMPD_barrier) { |
| 2540 | // OpenMP [2.16, Nesting of Regions] |
| 2541 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2542 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2543 | NestingProhibited = |
| 2544 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2545 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2546 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2547 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2548 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2549 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2550 | // OpenMP [2.16, Nesting of Regions] |
| 2551 | // A worksharing region may not be closely nested inside a worksharing, |
| 2552 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2553 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2554 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2555 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2556 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2557 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2558 | Recommend = ShouldBeInParallelRegion; |
| 2559 | } else if (CurrentRegion == OMPD_ordered) { |
| 2560 | // OpenMP [2.16, Nesting of Regions] |
| 2561 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2562 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2563 | // An ordered region must be closely nested inside a loop region (or |
| 2564 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2565 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2566 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2567 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2568 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2569 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2570 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2571 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2572 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2573 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2574 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2575 | // OpenMP [2.16, Nesting of Regions] |
| 2576 | // If specified, a teams construct must be contained within a target |
| 2577 | // construct. |
| 2578 | NestingProhibited = ParentRegion != OMPD_target; |
| 2579 | Recommend = ShouldBeInTargetRegion; |
| 2580 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2581 | } |
| 2582 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2583 | // OpenMP [2.16, Nesting of Regions] |
| 2584 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2585 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2586 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2587 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2588 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2589 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2590 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2591 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2592 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2593 | // The region associated with the distribute construct must be strictly |
| 2594 | // nested inside a teams region |
| 2595 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2596 | Recommend = ShouldBeInTeamsRegion; |
| 2597 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2598 | if (NestingProhibited) { |
| 2599 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2600 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2601 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2602 | return true; |
| 2603 | } |
| 2604 | } |
| 2605 | return false; |
| 2606 | } |
| 2607 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2608 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2609 | ArrayRef<OMPClause *> Clauses, |
| 2610 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2611 | bool ErrorFound = false; |
| 2612 | unsigned NamedModifiersNumber = 0; |
| 2613 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2614 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2615 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2616 | for (const auto *C : Clauses) { |
| 2617 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2618 | // At most one if clause without a directive-name-modifier can appear on |
| 2619 | // the directive. |
| 2620 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2621 | if (FoundNameModifiers[CurNM]) { |
| 2622 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2623 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2624 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2625 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2626 | } else if (CurNM != OMPD_unknown) { |
| 2627 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2628 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2629 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2630 | FoundNameModifiers[CurNM] = IC; |
| 2631 | if (CurNM == OMPD_unknown) |
| 2632 | continue; |
| 2633 | // Check if the specified name modifier is allowed for the current |
| 2634 | // directive. |
| 2635 | // At most one if clause with the particular directive-name-modifier can |
| 2636 | // appear on the directive. |
| 2637 | bool MatchFound = false; |
| 2638 | for (auto NM : AllowedNameModifiers) { |
| 2639 | if (CurNM == NM) { |
| 2640 | MatchFound = true; |
| 2641 | break; |
| 2642 | } |
| 2643 | } |
| 2644 | if (!MatchFound) { |
| 2645 | S.Diag(IC->getNameModifierLoc(), |
| 2646 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2647 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2648 | ErrorFound = true; |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | // If any if clause on the directive includes a directive-name-modifier then |
| 2653 | // all if clauses on the directive must include a directive-name-modifier. |
| 2654 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2655 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2656 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2657 | diag::err_omp_no_more_if_clause); |
| 2658 | } else { |
| 2659 | std::string Values; |
| 2660 | std::string Sep(", "); |
| 2661 | unsigned AllowedCnt = 0; |
| 2662 | unsigned TotalAllowedNum = |
| 2663 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2664 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2665 | ++Cnt) { |
| 2666 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2667 | if (!FoundNameModifiers[NM]) { |
| 2668 | Values += "'"; |
| 2669 | Values += getOpenMPDirectiveName(NM); |
| 2670 | Values += "'"; |
| 2671 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2672 | Values += " or "; |
| 2673 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2674 | Values += Sep; |
| 2675 | ++AllowedCnt; |
| 2676 | } |
| 2677 | } |
| 2678 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2679 | diag::err_omp_unnamed_if_clause) |
| 2680 | << (TotalAllowedNum > 1) << Values; |
| 2681 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2682 | for (auto Loc : NameModifierLoc) { |
| 2683 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2684 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2685 | ErrorFound = true; |
| 2686 | } |
| 2687 | return ErrorFound; |
| 2688 | } |
| 2689 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2690 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2691 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2692 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2693 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2694 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2695 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2696 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2697 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2698 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2699 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2700 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2701 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2702 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2703 | if (AStmt) { |
| 2704 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2705 | |
| 2706 | // Check default data sharing attributes for referenced variables. |
| 2707 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2708 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2709 | if (DSAChecker.isErrorFound()) |
| 2710 | return StmtError(); |
| 2711 | // Generate list of implicitly defined firstprivate variables. |
| 2712 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2713 | |
| 2714 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2715 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2716 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2717 | SourceLocation(), SourceLocation())) { |
| 2718 | ClausesWithImplicit.push_back(Implicit); |
| 2719 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2720 | DSAChecker.getImplicitFirstprivate().size(); |
| 2721 | } else |
| 2722 | ErrorFound = true; |
| 2723 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2724 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2725 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2726 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2727 | switch (Kind) { |
| 2728 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2729 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2730 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2731 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2732 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2733 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2734 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2735 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2736 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2737 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2738 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2739 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2740 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2741 | case OMPD_for_simd: |
| 2742 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2743 | EndLoc, VarsWithInheritedDSA); |
| 2744 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2745 | case OMPD_sections: |
| 2746 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2747 | EndLoc); |
| 2748 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2749 | case OMPD_section: |
| 2750 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2751 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2752 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2753 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2754 | case OMPD_single: |
| 2755 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2756 | EndLoc); |
| 2757 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2758 | case OMPD_master: |
| 2759 | assert(ClausesWithImplicit.empty() && |
| 2760 | "No clauses are allowed for 'omp master' directive"); |
| 2761 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2762 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2763 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2764 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2765 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2766 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2767 | case OMPD_parallel_for: |
| 2768 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2769 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2770 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2771 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2772 | case OMPD_parallel_for_simd: |
| 2773 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2774 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2775 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2776 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2777 | case OMPD_parallel_sections: |
| 2778 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2779 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2780 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2781 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2782 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2783 | Res = |
| 2784 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2785 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2786 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2787 | case OMPD_taskyield: |
| 2788 | assert(ClausesWithImplicit.empty() && |
| 2789 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2790 | assert(AStmt == nullptr && |
| 2791 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2792 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2793 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2794 | case OMPD_barrier: |
| 2795 | assert(ClausesWithImplicit.empty() && |
| 2796 | "No clauses are allowed for 'omp barrier' directive"); |
| 2797 | assert(AStmt == nullptr && |
| 2798 | "No associated statement allowed for 'omp barrier' directive"); |
| 2799 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2800 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2801 | case OMPD_taskwait: |
| 2802 | assert(ClausesWithImplicit.empty() && |
| 2803 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2804 | assert(AStmt == nullptr && |
| 2805 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2806 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2807 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2808 | case OMPD_taskgroup: |
| 2809 | assert(ClausesWithImplicit.empty() && |
| 2810 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2811 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2812 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2813 | case OMPD_flush: |
| 2814 | assert(AStmt == nullptr && |
| 2815 | "No associated statement allowed for 'omp flush' directive"); |
| 2816 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2817 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2818 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2819 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2820 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2821 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2822 | case OMPD_atomic: |
| 2823 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2824 | EndLoc); |
| 2825 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2826 | case OMPD_teams: |
| 2827 | Res = |
| 2828 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2829 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2830 | case OMPD_target: |
| 2831 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2832 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2833 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2834 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2835 | case OMPD_cancellation_point: |
| 2836 | assert(ClausesWithImplicit.empty() && |
| 2837 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2838 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2839 | "cancellation point' directive"); |
| 2840 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2841 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2842 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2843 | assert(AStmt == nullptr && |
| 2844 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2845 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2846 | CancelRegion); |
| 2847 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2848 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2849 | case OMPD_target_data: |
| 2850 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2851 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2852 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2853 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2854 | case OMPD_target_enter_data: |
| 2855 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2856 | EndLoc); |
| 2857 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2858 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2859 | case OMPD_target_exit_data: |
| 2860 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2861 | EndLoc); |
| 2862 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2863 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2864 | case OMPD_taskloop: |
| 2865 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2866 | EndLoc, VarsWithInheritedDSA); |
| 2867 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2868 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2869 | case OMPD_taskloop_simd: |
| 2870 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2871 | EndLoc, VarsWithInheritedDSA); |
| 2872 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2873 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2874 | case OMPD_distribute: |
| 2875 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2876 | EndLoc, VarsWithInheritedDSA); |
| 2877 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2878 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2879 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2880 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2881 | llvm_unreachable("Unknown OpenMP directive"); |
| 2882 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2883 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2884 | for (auto P : VarsWithInheritedDSA) { |
| 2885 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2886 | << P.first << P.second->getSourceRange(); |
| 2887 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2888 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2889 | |
| 2890 | if (!AllowedNameModifiers.empty()) |
| 2891 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2892 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2893 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2894 | if (ErrorFound) |
| 2895 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2896 | return Res; |
| 2897 | } |
| 2898 | |
| 2899 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2900 | Stmt *AStmt, |
| 2901 | SourceLocation StartLoc, |
| 2902 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2903 | if (!AStmt) |
| 2904 | return StmtError(); |
| 2905 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2906 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2907 | // 1.2.2 OpenMP Language Terminology |
| 2908 | // Structured block - An executable statement with a single entry at the |
| 2909 | // top and a single exit at the bottom. |
| 2910 | // The point of exit cannot be a branch out of the structured block. |
| 2911 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2912 | CS->getCapturedDecl()->setNothrow(); |
| 2913 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2914 | getCurFunction()->setHasBranchProtectedScope(); |
| 2915 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2916 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2917 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2920 | namespace { |
| 2921 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2922 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2923 | /// for IR generation. |
| 2924 | class OpenMPIterationSpaceChecker { |
| 2925 | /// \brief Reference to Sema. |
| 2926 | Sema &SemaRef; |
| 2927 | /// \brief A location for diagnostics (when there is no some better location). |
| 2928 | SourceLocation DefaultLoc; |
| 2929 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2930 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2931 | /// \brief A source location for referring to loop init later. |
| 2932 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2933 | /// \brief A source location for referring to condition later. |
| 2934 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2935 | /// \brief A source location for referring to increment later. |
| 2936 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2937 | /// \brief Loop variable. |
| 2938 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2939 | /// \brief Reference to loop variable. |
| 2940 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2941 | /// \brief Lower bound (initializer for the var). |
| 2942 | Expr *LB; |
| 2943 | /// \brief Upper bound. |
| 2944 | Expr *UB; |
| 2945 | /// \brief Loop step (increment). |
| 2946 | Expr *Step; |
| 2947 | /// \brief This flag is true when condition is one of: |
| 2948 | /// Var < UB |
| 2949 | /// Var <= UB |
| 2950 | /// UB > Var |
| 2951 | /// UB >= Var |
| 2952 | bool TestIsLessOp; |
| 2953 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2954 | bool TestIsStrictOp; |
| 2955 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2956 | bool SubtractStep; |
| 2957 | |
| 2958 | public: |
| 2959 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2960 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2961 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2962 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2963 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2964 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2965 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2966 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2967 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2968 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2969 | /// for less/greater and for strict/non-strict comparison. |
| 2970 | bool CheckCond(Expr *S); |
| 2971 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2972 | /// does not conform, otherwise save loop step (#Step). |
| 2973 | bool CheckInc(Expr *S); |
| 2974 | /// \brief Return the loop counter variable. |
| 2975 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2976 | /// \brief Return the reference expression to loop counter variable. |
| 2977 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2978 | /// \brief Source range of the loop init. |
| 2979 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2980 | /// \brief Source range of the loop condition. |
| 2981 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2982 | /// \brief Source range of the loop increment. |
| 2983 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2984 | /// \brief True if the step should be subtracted. |
| 2985 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2986 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2987 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2988 | /// \brief Build the precondition expression for the loops. |
| 2989 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2990 | /// \brief Build reference expression to the counter be used for codegen. |
| 2991 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2992 | /// \brief Build reference expression to the private counter be used for |
| 2993 | /// codegen. |
| 2994 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2995 | /// \brief Build initization of the counter be used for codegen. |
| 2996 | Expr *BuildCounterInit() const; |
| 2997 | /// \brief Build step of the counter be used for codegen. |
| 2998 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2999 | /// \brief Return true if any expression is dependent. |
| 3000 | bool Dependent() const; |
| 3001 | |
| 3002 | private: |
| 3003 | /// \brief Check the right-hand side of an assignment in the increment |
| 3004 | /// expression. |
| 3005 | bool CheckIncRHS(Expr *RHS); |
| 3006 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3007 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3008 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3009 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3010 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3011 | /// \brief Helper to set loop increment. |
| 3012 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3013 | }; |
| 3014 | |
| 3015 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3016 | if (!Var) { |
| 3017 | assert(!LB && !UB && !Step); |
| 3018 | return false; |
| 3019 | } |
| 3020 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3021 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3022 | } |
| 3023 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3024 | template <typename T> |
| 3025 | static T *getExprAsWritten(T *E) { |
| 3026 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3027 | E = ExprTemp->getSubExpr(); |
| 3028 | |
| 3029 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3030 | E = MTE->GetTemporaryExpr(); |
| 3031 | |
| 3032 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3033 | E = Binder->getSubExpr(); |
| 3034 | |
| 3035 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3036 | E = ICE->getSubExprAsWritten(); |
| 3037 | return E->IgnoreParens(); |
| 3038 | } |
| 3039 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3040 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3041 | DeclRefExpr *NewVarRefExpr, |
| 3042 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3043 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3044 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3045 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3046 | if (!NewVar || !NewLB) |
| 3047 | return true; |
| 3048 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3049 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3050 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3051 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3052 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3053 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3054 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3055 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3056 | LB = NewLB; |
| 3057 | return false; |
| 3058 | } |
| 3059 | |
| 3060 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3061 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3062 | // State consistency checking to ensure correct usage. |
| 3063 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3064 | !TestIsLessOp && !TestIsStrictOp); |
| 3065 | if (!NewUB) |
| 3066 | return true; |
| 3067 | UB = NewUB; |
| 3068 | TestIsLessOp = LessOp; |
| 3069 | TestIsStrictOp = StrictOp; |
| 3070 | ConditionSrcRange = SR; |
| 3071 | ConditionLoc = SL; |
| 3072 | return false; |
| 3073 | } |
| 3074 | |
| 3075 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3076 | // State consistency checking to ensure correct usage. |
| 3077 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3078 | if (!NewStep) |
| 3079 | return true; |
| 3080 | if (!NewStep->isValueDependent()) { |
| 3081 | // Check that the step is integer expression. |
| 3082 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3083 | ExprResult Val = |
| 3084 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3085 | if (Val.isInvalid()) |
| 3086 | return true; |
| 3087 | NewStep = Val.get(); |
| 3088 | |
| 3089 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3090 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3091 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3092 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3093 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3094 | // the loop. |
| 3095 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3096 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3097 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3098 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3099 | // the loop. |
| 3100 | llvm::APSInt Result; |
| 3101 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3102 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3103 | bool IsConstNeg = |
| 3104 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3105 | bool IsConstPos = |
| 3106 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3107 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3108 | if (UB && (IsConstZero || |
| 3109 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3110 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3111 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3112 | diag::err_omp_loop_incr_not_compatible) |
| 3113 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3114 | SemaRef.Diag(ConditionLoc, |
| 3115 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3116 | << TestIsLessOp << ConditionSrcRange; |
| 3117 | return true; |
| 3118 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3119 | if (TestIsLessOp == Subtract) { |
| 3120 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3121 | NewStep).get(); |
| 3122 | Subtract = !Subtract; |
| 3123 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | Step = NewStep; |
| 3127 | SubtractStep = Subtract; |
| 3128 | return false; |
| 3129 | } |
| 3130 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3131 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3132 | // Check init-expr for canonical loop form and save loop counter |
| 3133 | // variable - #Var and its initialization value - #LB. |
| 3134 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3135 | // var = lb |
| 3136 | // integer-type var = lb |
| 3137 | // random-access-iterator-type var = lb |
| 3138 | // pointer-type var = lb |
| 3139 | // |
| 3140 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3141 | if (EmitDiags) { |
| 3142 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3143 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3144 | return true; |
| 3145 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3146 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3147 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3148 | S = E->IgnoreParens(); |
| 3149 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3150 | if (BO->getOpcode() == BO_Assign) |
| 3151 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3152 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3153 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3154 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3155 | if (DS->isSingleDecl()) { |
| 3156 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3157 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3158 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3159 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3160 | SemaRef.Diag(S->getLocStart(), |
| 3161 | diag::ext_omp_loop_not_canonical_init) |
| 3162 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3163 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3168 | if (CE->getOperator() == OO_Equal) |
| 3169 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3170 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3171 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3172 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3173 | if (EmitDiags) { |
| 3174 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3175 | << S->getSourceRange(); |
| 3176 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3177 | return true; |
| 3178 | } |
| 3179 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3180 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3181 | /// variable (which may be the loop variable) if possible. |
| 3182 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3183 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3184 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3185 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3187 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3188 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3189 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3190 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3191 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3192 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3193 | if (!DRE) |
| 3194 | return nullptr; |
| 3195 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3196 | } |
| 3197 | |
| 3198 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3199 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3200 | // less/greater and for strict/non-strict comparison. |
| 3201 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3202 | // var relational-op b |
| 3203 | // b relational-op var |
| 3204 | // |
| 3205 | if (!S) { |
| 3206 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3207 | return true; |
| 3208 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3209 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3210 | SourceLocation CondLoc = S->getLocStart(); |
| 3211 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3212 | if (BO->isRelationalOp()) { |
| 3213 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3214 | return SetUB(BO->getRHS(), |
| 3215 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3216 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3217 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3218 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3219 | return SetUB(BO->getLHS(), |
| 3220 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3221 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3222 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3223 | } |
| 3224 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3225 | if (CE->getNumArgs() == 2) { |
| 3226 | auto Op = CE->getOperator(); |
| 3227 | switch (Op) { |
| 3228 | case OO_Greater: |
| 3229 | case OO_GreaterEqual: |
| 3230 | case OO_Less: |
| 3231 | case OO_LessEqual: |
| 3232 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3233 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3234 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3235 | CE->getOperatorLoc()); |
| 3236 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3237 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3238 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3239 | CE->getOperatorLoc()); |
| 3240 | break; |
| 3241 | default: |
| 3242 | break; |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3247 | << S->getSourceRange() << Var; |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
| 3251 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3252 | // RHS of canonical loop form increment can be: |
| 3253 | // var + incr |
| 3254 | // incr + var |
| 3255 | // var - incr |
| 3256 | // |
| 3257 | RHS = RHS->IgnoreParenImpCasts(); |
| 3258 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3259 | if (BO->isAdditiveOp()) { |
| 3260 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3261 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3262 | return SetStep(BO->getRHS(), !IsAdd); |
| 3263 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3264 | return SetStep(BO->getLHS(), false); |
| 3265 | } |
| 3266 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3267 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3268 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3269 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3270 | return SetStep(CE->getArg(1), !IsAdd); |
| 3271 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3272 | return SetStep(CE->getArg(0), false); |
| 3273 | } |
| 3274 | } |
| 3275 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3276 | << RHS->getSourceRange() << Var; |
| 3277 | return true; |
| 3278 | } |
| 3279 | |
| 3280 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3281 | // Check incr-expr for canonical loop form and return true if it |
| 3282 | // does not conform. |
| 3283 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3284 | // ++var |
| 3285 | // var++ |
| 3286 | // --var |
| 3287 | // var-- |
| 3288 | // var += incr |
| 3289 | // var -= incr |
| 3290 | // var = var + incr |
| 3291 | // var = incr + var |
| 3292 | // var = var - incr |
| 3293 | // |
| 3294 | if (!S) { |
| 3295 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3296 | return true; |
| 3297 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3298 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3299 | S = S->IgnoreParens(); |
| 3300 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3301 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3302 | return SetStep( |
| 3303 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3304 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3305 | false); |
| 3306 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3307 | switch (BO->getOpcode()) { |
| 3308 | case BO_AddAssign: |
| 3309 | case BO_SubAssign: |
| 3310 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3311 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3312 | break; |
| 3313 | case BO_Assign: |
| 3314 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3315 | return CheckIncRHS(BO->getRHS()); |
| 3316 | break; |
| 3317 | default: |
| 3318 | break; |
| 3319 | } |
| 3320 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3321 | switch (CE->getOperator()) { |
| 3322 | case OO_PlusPlus: |
| 3323 | case OO_MinusMinus: |
| 3324 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3325 | return SetStep( |
| 3326 | SemaRef.ActOnIntegerConstant( |
| 3327 | CE->getLocStart(), |
| 3328 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3329 | false); |
| 3330 | break; |
| 3331 | case OO_PlusEqual: |
| 3332 | case OO_MinusEqual: |
| 3333 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3334 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3335 | break; |
| 3336 | case OO_Equal: |
| 3337 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3338 | return CheckIncRHS(CE->getArg(1)); |
| 3339 | break; |
| 3340 | default: |
| 3341 | break; |
| 3342 | } |
| 3343 | } |
| 3344 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3345 | << S->getSourceRange() << Var; |
| 3346 | return true; |
| 3347 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3348 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3349 | namespace { |
| 3350 | // Transform variables declared in GNU statement expressions to new ones to |
| 3351 | // avoid crash on codegen. |
| 3352 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3353 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3354 | |
| 3355 | public: |
| 3356 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3357 | |
| 3358 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3359 | if (auto *VD = cast<VarDecl>(D)) |
| 3360 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3361 | !isa<ImplicitParamDecl>(D)) { |
| 3362 | auto *NewVD = VarDecl::Create( |
| 3363 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3364 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3365 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3366 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3367 | NewVD->setInit(VD->getInit()); |
| 3368 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3369 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3370 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3371 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3372 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3373 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3374 | NewVD->setPreviousDeclInSameBlockScope( |
| 3375 | VD->isPreviousDeclInSameBlockScope()); |
| 3376 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3377 | if (VD->hasAttrs()) |
| 3378 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3379 | transformedLocalDecl(VD, NewVD); |
| 3380 | return NewVD; |
| 3381 | } |
| 3382 | return BaseTransform::TransformDefinition(Loc, D); |
| 3383 | } |
| 3384 | |
| 3385 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3386 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3387 | if (E->getDecl() != NewD) { |
| 3388 | NewD->setReferenced(); |
| 3389 | NewD->markUsed(SemaRef.Context); |
| 3390 | return DeclRefExpr::Create( |
| 3391 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3392 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3393 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3394 | } |
| 3395 | return BaseTransform::TransformDeclRefExpr(E); |
| 3396 | } |
| 3397 | }; |
| 3398 | } |
| 3399 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3400 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3401 | Expr * |
| 3402 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3403 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3404 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3405 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3406 | auto VarType = Var->getType().getNonReferenceType(); |
| 3407 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3408 | SemaRef.getLangOpts().CPlusPlus) { |
| 3409 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3410 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3411 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3412 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3413 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3414 | if (!Upper || !Lower) |
| 3415 | return nullptr; |
| 3416 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3417 | Sema::AA_Converting, |
| 3418 | /*AllowExplicit=*/true) |
| 3419 | .get(); |
| 3420 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3421 | Sema::AA_Converting, |
| 3422 | /*AllowExplicit=*/true) |
| 3423 | .get(); |
| 3424 | if (!Upper || !Lower) |
| 3425 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3426 | |
| 3427 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3428 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3429 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3430 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3431 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3432 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3433 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3434 | return nullptr; |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | if (!Diff.isUsable()) |
| 3439 | return nullptr; |
| 3440 | |
| 3441 | // Upper - Lower [- 1] |
| 3442 | if (TestIsStrictOp) |
| 3443 | Diff = SemaRef.BuildBinOp( |
| 3444 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3445 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3446 | if (!Diff.isUsable()) |
| 3447 | return nullptr; |
| 3448 | |
| 3449 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3450 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3451 | if (NewStep.isInvalid()) |
| 3452 | return nullptr; |
| 3453 | NewStep = SemaRef.PerformImplicitConversion( |
| 3454 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3455 | /*AllowExplicit=*/true); |
| 3456 | if (NewStep.isInvalid()) |
| 3457 | return nullptr; |
| 3458 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3459 | if (!Diff.isUsable()) |
| 3460 | return nullptr; |
| 3461 | |
| 3462 | // Parentheses (for dumping/debugging purposes only). |
| 3463 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3464 | if (!Diff.isUsable()) |
| 3465 | return nullptr; |
| 3466 | |
| 3467 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3468 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3469 | if (NewStep.isInvalid()) |
| 3470 | return nullptr; |
| 3471 | NewStep = SemaRef.PerformImplicitConversion( |
| 3472 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3473 | /*AllowExplicit=*/true); |
| 3474 | if (NewStep.isInvalid()) |
| 3475 | return nullptr; |
| 3476 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3477 | if (!Diff.isUsable()) |
| 3478 | return nullptr; |
| 3479 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3480 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3481 | QualType Type = Diff.get()->getType(); |
| 3482 | auto &C = SemaRef.Context; |
| 3483 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3484 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3485 | if (!Type->isIntegerType() || UseVarType) { |
| 3486 | unsigned NewSize = |
| 3487 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3488 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3489 | : Type->hasSignedIntegerRepresentation(); |
| 3490 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3491 | Diff = SemaRef.PerformImplicitConversion( |
| 3492 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3493 | if (!Diff.isUsable()) |
| 3494 | return nullptr; |
| 3495 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3496 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3497 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3498 | if (NewSize != C.getTypeSize(Type)) { |
| 3499 | if (NewSize < C.getTypeSize(Type)) { |
| 3500 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3501 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3502 | << InitSrcRange << ConditionSrcRange; |
| 3503 | } |
| 3504 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3505 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3506 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3507 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3508 | Sema::AA_Converting, true); |
| 3509 | if (!Diff.isUsable()) |
| 3510 | return nullptr; |
| 3511 | } |
| 3512 | } |
| 3513 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3514 | return Diff.get(); |
| 3515 | } |
| 3516 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3517 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3518 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3519 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3520 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3521 | TransformToNewDefs Transform(SemaRef); |
| 3522 | |
| 3523 | auto NewLB = Transform.TransformExpr(LB); |
| 3524 | auto NewUB = Transform.TransformExpr(UB); |
| 3525 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3526 | return Cond; |
| 3527 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3528 | Sema::AA_Converting, |
| 3529 | /*AllowExplicit=*/true); |
| 3530 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3531 | Sema::AA_Converting, |
| 3532 | /*AllowExplicit=*/true); |
| 3533 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3534 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3535 | auto CondExpr = SemaRef.BuildBinOp( |
| 3536 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3537 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3538 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3539 | if (CondExpr.isUsable()) { |
| 3540 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3541 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3542 | /*AllowExplicit=*/true); |
| 3543 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3544 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3545 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3546 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3547 | } |
| 3548 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3549 | /// \brief Build reference expression to the counter be used for codegen. |
| 3550 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3551 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3552 | DefaultLoc); |
| 3553 | } |
| 3554 | |
| 3555 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3556 | if (Var && !Var->isInvalidDecl()) { |
| 3557 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3558 | auto *PrivateVar = |
| 3559 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3560 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3561 | if (PrivateVar->isInvalidDecl()) |
| 3562 | return nullptr; |
| 3563 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3564 | } |
| 3565 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | /// \brief Build initization of the counter be used for codegen. |
| 3569 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3570 | |
| 3571 | /// \brief Build step of the counter be used for codegen. |
| 3572 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3573 | |
| 3574 | /// \brief Iteration space of a single for loop. |
| 3575 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3576 | /// \brief Condition of the loop. |
| 3577 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3578 | /// \brief This expression calculates the number of iterations in the loop. |
| 3579 | /// It is always possible to calculate it before starting the loop. |
| 3580 | Expr *NumIterations; |
| 3581 | /// \brief The loop counter variable. |
| 3582 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3583 | /// \brief Private loop counter variable. |
| 3584 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3585 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3586 | Expr *CounterInit; |
| 3587 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3588 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3589 | Expr *CounterStep; |
| 3590 | /// \brief Should step be subtracted? |
| 3591 | bool Subtract; |
| 3592 | /// \brief Source range of the loop init. |
| 3593 | SourceRange InitSrcRange; |
| 3594 | /// \brief Source range of the loop condition. |
| 3595 | SourceRange CondSrcRange; |
| 3596 | /// \brief Source range of the loop increment. |
| 3597 | SourceRange IncSrcRange; |
| 3598 | }; |
| 3599 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3600 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3601 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3602 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3603 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3604 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3605 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3606 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3607 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3608 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3609 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3610 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3611 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3615 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3616 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3617 | static bool CheckOpenMPIterationSpace( |
| 3618 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3619 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3620 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3621 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3622 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3623 | // OpenMP [2.6, Canonical Loop Form] |
| 3624 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3625 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3626 | if (!For) { |
| 3627 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3628 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3629 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3630 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3631 | if (NestedLoopCount > 1) { |
| 3632 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3633 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3634 | diag::note_omp_collapse_ordered_expr) |
| 3635 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3636 | << OrderedLoopCountExpr->getSourceRange(); |
| 3637 | else if (CollapseLoopCountExpr) |
| 3638 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3639 | diag::note_omp_collapse_ordered_expr) |
| 3640 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3641 | else |
| 3642 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3643 | diag::note_omp_collapse_ordered_expr) |
| 3644 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3645 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3646 | return true; |
| 3647 | } |
| 3648 | assert(For->getBody()); |
| 3649 | |
| 3650 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3651 | |
| 3652 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3653 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3654 | if (ISC.CheckInit(Init)) { |
| 3655 | return true; |
| 3656 | } |
| 3657 | |
| 3658 | bool HasErrors = false; |
| 3659 | |
| 3660 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3661 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3662 | |
| 3663 | // OpenMP [2.6, Canonical Loop Form] |
| 3664 | // Var is one of the following: |
| 3665 | // A variable of signed or unsigned integer type. |
| 3666 | // For C++, a variable of a random access iterator type. |
| 3667 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3668 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3669 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3670 | !VarType->isPointerType() && |
| 3671 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3672 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3673 | << SemaRef.getLangOpts().CPlusPlus; |
| 3674 | HasErrors = true; |
| 3675 | } |
| 3676 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3677 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3678 | // Construct |
| 3679 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3680 | // parallel for construct is (are) private. |
| 3681 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3682 | // with just one associated for-loop is linear with a constant-linear-step |
| 3683 | // that is the increment of the associated for-loop. |
| 3684 | // Exclude loop var from the list of variables with implicitly defined data |
| 3685 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3686 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3687 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3688 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3689 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3690 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3691 | // with just one associated for-loop may be listed in a linear clause with a |
| 3692 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3693 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3694 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3695 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3696 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3697 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3698 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3699 | auto PredeterminedCKind = |
| 3700 | isOpenMPSimdDirective(DKind) |
| 3701 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3702 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3703 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3704 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3705 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3706 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3707 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3708 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3709 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3710 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3711 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3712 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3713 | if (DVar.RefExpr == nullptr) |
| 3714 | DVar.CKind = PredeterminedCKind; |
| 3715 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3716 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3717 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3718 | // Make the loop iteration variable private (for worksharing constructs), |
| 3719 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3720 | // lastprivate (for simd directives with several collapsed or ordered |
| 3721 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3722 | if (DVar.CKind == OMPC_unknown) |
| 3723 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3724 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3725 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3728 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3729 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3730 | // Check test-expr. |
| 3731 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3732 | |
| 3733 | // Check incr-expr. |
| 3734 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3735 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3736 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3737 | return HasErrors; |
| 3738 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3739 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3740 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3741 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3742 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3743 | isOpenMPTaskLoopDirective(DKind) || |
| 3744 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3745 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3746 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3747 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3748 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3749 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3750 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3751 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3752 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3753 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3754 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3755 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3756 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3757 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3758 | ResultIterSpace.CounterInit == nullptr || |
| 3759 | ResultIterSpace.CounterStep == nullptr); |
| 3760 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3761 | return HasErrors; |
| 3762 | } |
| 3763 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3764 | /// \brief Build 'VarRef = Start. |
| 3765 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3766 | ExprResult VarRef, ExprResult Start) { |
| 3767 | TransformToNewDefs Transform(SemaRef); |
| 3768 | // Build 'VarRef = Start. |
| 3769 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3770 | if (NewStart.isInvalid()) |
| 3771 | return ExprError(); |
| 3772 | NewStart = SemaRef.PerformImplicitConversion( |
| 3773 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3774 | Sema::AA_Converting, |
| 3775 | /*AllowExplicit=*/true); |
| 3776 | if (NewStart.isInvalid()) |
| 3777 | return ExprError(); |
| 3778 | NewStart = SemaRef.PerformImplicitConversion( |
| 3779 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3780 | /*AllowExplicit=*/true); |
| 3781 | if (!NewStart.isUsable()) |
| 3782 | return ExprError(); |
| 3783 | |
| 3784 | auto Init = |
| 3785 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3786 | return Init; |
| 3787 | } |
| 3788 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3789 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3790 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3791 | SourceLocation Loc, ExprResult VarRef, |
| 3792 | ExprResult Start, ExprResult Iter, |
| 3793 | ExprResult Step, bool Subtract) { |
| 3794 | // Add parentheses (for debugging purposes only). |
| 3795 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3796 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3797 | !Step.isUsable()) |
| 3798 | return ExprError(); |
| 3799 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3800 | TransformToNewDefs Transform(SemaRef); |
| 3801 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3802 | if (NewStep.isInvalid()) |
| 3803 | return ExprError(); |
| 3804 | NewStep = SemaRef.PerformImplicitConversion( |
| 3805 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3806 | Sema::AA_Converting, |
| 3807 | /*AllowExplicit=*/true); |
| 3808 | if (NewStep.isInvalid()) |
| 3809 | return ExprError(); |
| 3810 | ExprResult Update = |
| 3811 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3812 | if (!Update.isUsable()) |
| 3813 | return ExprError(); |
| 3814 | |
| 3815 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3816 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3817 | if (NewStart.isInvalid()) |
| 3818 | return ExprError(); |
| 3819 | NewStart = SemaRef.PerformImplicitConversion( |
| 3820 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3821 | Sema::AA_Converting, |
| 3822 | /*AllowExplicit=*/true); |
| 3823 | if (NewStart.isInvalid()) |
| 3824 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3825 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3826 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3827 | if (!Update.isUsable()) |
| 3828 | return ExprError(); |
| 3829 | |
| 3830 | Update = SemaRef.PerformImplicitConversion( |
| 3831 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3832 | if (!Update.isUsable()) |
| 3833 | return ExprError(); |
| 3834 | |
| 3835 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3836 | return Update; |
| 3837 | } |
| 3838 | |
| 3839 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3840 | /// bits. |
| 3841 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3842 | Sema &SemaRef) { |
| 3843 | if (E == nullptr) |
| 3844 | return ExprError(); |
| 3845 | auto &C = SemaRef.Context; |
| 3846 | QualType OldType = E->getType(); |
| 3847 | unsigned HasBits = C.getTypeSize(OldType); |
| 3848 | if (HasBits >= Bits) |
| 3849 | return ExprResult(E); |
| 3850 | // OK to convert to signed, because new type has more bits than old. |
| 3851 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3852 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3853 | true); |
| 3854 | } |
| 3855 | |
| 3856 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3857 | /// into \a Bits bits. |
| 3858 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3859 | if (E == nullptr) |
| 3860 | return false; |
| 3861 | llvm::APSInt Result; |
| 3862 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3863 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3864 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | /// \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] | 3868 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3869 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3870 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3871 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3872 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3873 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3874 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3875 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3876 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3877 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3878 | // Found 'collapse' clause - calculate collapse number. |
| 3879 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3880 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3881 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3882 | } |
| 3883 | if (OrderedLoopCountExpr) { |
| 3884 | // Found 'ordered' clause - calculate collapse number. |
| 3885 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3886 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3887 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3888 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3889 | diag::err_omp_wrong_ordered_loop_count) |
| 3890 | << OrderedLoopCountExpr->getSourceRange(); |
| 3891 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3892 | diag::note_collapse_loop_count) |
| 3893 | << CollapseLoopCountExpr->getSourceRange(); |
| 3894 | } |
| 3895 | NestedLoopCount = Result.getLimitedValue(); |
| 3896 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3897 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3898 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3899 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3900 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3901 | IterSpaces.resize(NestedLoopCount); |
| 3902 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3903 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3904 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3905 | NestedLoopCount, CollapseLoopCountExpr, |
| 3906 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3907 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3908 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3909 | // 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] | 3910 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3911 | // All loops associated with the construct must be perfectly nested; that |
| 3912 | // is, there must be no intervening code nor any OpenMP directive between |
| 3913 | // any two loops. |
| 3914 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3917 | Built.clear(/* size */ NestedLoopCount); |
| 3918 | |
| 3919 | if (SemaRef.CurContext->isDependentContext()) |
| 3920 | return NestedLoopCount; |
| 3921 | |
| 3922 | // An example of what is generated for the following code: |
| 3923 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3924 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3925 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3926 | // for (k = 0; k < NK; ++k) |
| 3927 | // for (j = J0; j < NJ; j+=2) { |
| 3928 | // <loop body> |
| 3929 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3930 | // |
| 3931 | // We generate the code below. |
| 3932 | // Note: the loop body may be outlined in CodeGen. |
| 3933 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3934 | // iterations and operator+= to calculate counter value. |
| 3935 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3936 | // or i64 is currently supported). |
| 3937 | // |
| 3938 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3939 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3940 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3941 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3942 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3943 | // <loop body (using local i and j)> |
| 3944 | // } |
| 3945 | // i = NI; // assign final values of counters |
| 3946 | // j = NJ; |
| 3947 | // |
| 3948 | |
| 3949 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3950 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3951 | // Precondition tests if there is at least one iteration (all conditions are |
| 3952 | // true). |
| 3953 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3954 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3955 | ExprResult LastIteration32 = WidenIterationCount( |
| 3956 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3957 | N0->IgnoreImpCasts(), N0->getType(), |
| 3958 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3959 | .get(), |
| 3960 | SemaRef); |
| 3961 | ExprResult LastIteration64 = WidenIterationCount( |
| 3962 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3963 | N0->IgnoreImpCasts(), N0->getType(), |
| 3964 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3965 | .get(), |
| 3966 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3967 | |
| 3968 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3969 | return NestedLoopCount; |
| 3970 | |
| 3971 | auto &C = SemaRef.Context; |
| 3972 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3973 | |
| 3974 | Scope *CurScope = DSA.getCurScope(); |
| 3975 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3976 | if (PreCond.isUsable()) { |
| 3977 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3978 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3979 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3980 | auto N = IterSpaces[Cnt].NumIterations; |
| 3981 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3982 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3983 | LastIteration32 = SemaRef.BuildBinOp( |
| 3984 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3985 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3986 | Sema::AA_Converting, |
| 3987 | /*AllowExplicit=*/true) |
| 3988 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3989 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3990 | LastIteration64 = SemaRef.BuildBinOp( |
| 3991 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3992 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3993 | Sema::AA_Converting, |
| 3994 | /*AllowExplicit=*/true) |
| 3995 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | // Choose either the 32-bit or 64-bit version. |
| 3999 | ExprResult LastIteration = LastIteration64; |
| 4000 | if (LastIteration32.isUsable() && |
| 4001 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4002 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4003 | FitsInto( |
| 4004 | 32 /* Bits */, |
| 4005 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4006 | LastIteration64.get(), SemaRef))) |
| 4007 | LastIteration = LastIteration32; |
| 4008 | |
| 4009 | if (!LastIteration.isUsable()) |
| 4010 | return 0; |
| 4011 | |
| 4012 | // Save the number of iterations. |
| 4013 | ExprResult NumIterations = LastIteration; |
| 4014 | { |
| 4015 | LastIteration = SemaRef.BuildBinOp( |
| 4016 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4017 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4018 | if (!LastIteration.isUsable()) |
| 4019 | return 0; |
| 4020 | } |
| 4021 | |
| 4022 | // Calculate the last iteration number beforehand instead of doing this on |
| 4023 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4024 | llvm::APSInt Result; |
| 4025 | bool IsConstant = |
| 4026 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4027 | ExprResult CalcLastIteration; |
| 4028 | if (!IsConstant) { |
| 4029 | SourceLocation SaveLoc; |
| 4030 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4031 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4032 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4033 | ExprResult SaveRef = buildDeclRefExpr( |
| 4034 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4035 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4036 | SaveRef.get(), LastIteration.get()); |
| 4037 | LastIteration = SaveRef; |
| 4038 | |
| 4039 | // Prepare SaveRef + 1. |
| 4040 | NumIterations = SemaRef.BuildBinOp( |
| 4041 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4042 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4043 | if (!NumIterations.isUsable()) |
| 4044 | return 0; |
| 4045 | } |
| 4046 | |
| 4047 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4048 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4049 | QualType VType = LastIteration.get()->getType(); |
| 4050 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4051 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4052 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4053 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4054 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4055 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4056 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4057 | SemaRef.AddInitializerToDecl( |
| 4058 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4059 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4060 | |
| 4061 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4062 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4063 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4064 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4065 | /*DirectInit*/ false, |
| 4066 | /*TypeMayContainAuto*/ false); |
| 4067 | |
| 4068 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4069 | // This will be used to implement clause 'lastprivate'. |
| 4070 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4071 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4072 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4073 | SemaRef.AddInitializerToDecl( |
| 4074 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4075 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4076 | |
| 4077 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4078 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4079 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4080 | SemaRef.AddInitializerToDecl( |
| 4081 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4082 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4083 | |
| 4084 | // Build expression: UB = min(UB, LastIteration) |
| 4085 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4086 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4087 | UB.get(), LastIteration.get()); |
| 4088 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4089 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4090 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4091 | CondOp.get()); |
| 4092 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4093 | } |
| 4094 | |
| 4095 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4096 | ExprResult IV; |
| 4097 | ExprResult Init; |
| 4098 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4099 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4100 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4101 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4102 | isOpenMPTaskLoopDirective(DKind) || |
| 4103 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4104 | ? LB.get() |
| 4105 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4106 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4107 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4110 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4111 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4112 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4113 | (isOpenMPWorksharingDirective(DKind) || |
| 4114 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4115 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4116 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4117 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4118 | |
| 4119 | // Loop increment (IV = IV + 1) |
| 4120 | SourceLocation IncLoc; |
| 4121 | ExprResult Inc = |
| 4122 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4123 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4124 | if (!Inc.isUsable()) |
| 4125 | return 0; |
| 4126 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4127 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4128 | if (!Inc.isUsable()) |
| 4129 | return 0; |
| 4130 | |
| 4131 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4132 | // Used for directives with static scheduling. |
| 4133 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4134 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4135 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4136 | // LB + ST |
| 4137 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4138 | if (!NextLB.isUsable()) |
| 4139 | return 0; |
| 4140 | // LB = LB + ST |
| 4141 | NextLB = |
| 4142 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4143 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4144 | if (!NextLB.isUsable()) |
| 4145 | return 0; |
| 4146 | // UB + ST |
| 4147 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4148 | if (!NextUB.isUsable()) |
| 4149 | return 0; |
| 4150 | // UB = UB + ST |
| 4151 | NextUB = |
| 4152 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4153 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4154 | if (!NextUB.isUsable()) |
| 4155 | return 0; |
| 4156 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4157 | |
| 4158 | // Build updates and final values of the loop counters. |
| 4159 | bool HasErrors = false; |
| 4160 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4161 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4162 | Built.Updates.resize(NestedLoopCount); |
| 4163 | Built.Finals.resize(NestedLoopCount); |
| 4164 | { |
| 4165 | ExprResult Div; |
| 4166 | // Go from inner nested loop to outer. |
| 4167 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4168 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4169 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4170 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4171 | // where Div is product of previous iterations' IS.NumIters. |
| 4172 | ExprResult Iter; |
| 4173 | if (Div.isUsable()) { |
| 4174 | Iter = |
| 4175 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4176 | } else { |
| 4177 | Iter = IV; |
| 4178 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4179 | "unusable div expected on first iteration only"); |
| 4180 | } |
| 4181 | |
| 4182 | if (Cnt != 0 && Iter.isUsable()) |
| 4183 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4184 | IS.NumIterations); |
| 4185 | if (!Iter.isUsable()) { |
| 4186 | HasErrors = true; |
| 4187 | break; |
| 4188 | } |
| 4189 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4190 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4191 | auto *CounterVar = buildDeclRefExpr( |
| 4192 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4193 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4194 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4195 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4196 | IS.CounterInit); |
| 4197 | if (!Init.isUsable()) { |
| 4198 | HasErrors = true; |
| 4199 | break; |
| 4200 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4201 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4202 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4203 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4204 | if (!Update.isUsable()) { |
| 4205 | HasErrors = true; |
| 4206 | break; |
| 4207 | } |
| 4208 | |
| 4209 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4210 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4211 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4212 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4213 | if (!Final.isUsable()) { |
| 4214 | HasErrors = true; |
| 4215 | break; |
| 4216 | } |
| 4217 | |
| 4218 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4219 | if (Cnt != 0) { |
| 4220 | if (Div.isUnset()) |
| 4221 | Div = IS.NumIterations; |
| 4222 | else |
| 4223 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4224 | IS.NumIterations); |
| 4225 | |
| 4226 | // Add parentheses (for debugging purposes only). |
| 4227 | if (Div.isUsable()) |
| 4228 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4229 | if (!Div.isUsable()) { |
| 4230 | HasErrors = true; |
| 4231 | break; |
| 4232 | } |
| 4233 | } |
| 4234 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4235 | HasErrors = true; |
| 4236 | break; |
| 4237 | } |
| 4238 | // Save results |
| 4239 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4240 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4241 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4242 | Built.Updates[Cnt] = Update.get(); |
| 4243 | Built.Finals[Cnt] = Final.get(); |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | if (HasErrors) |
| 4248 | return 0; |
| 4249 | |
| 4250 | // Save results |
| 4251 | Built.IterationVarRef = IV.get(); |
| 4252 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4253 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4254 | Built.CalcLastIteration = |
| 4255 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4256 | Built.PreCond = PreCond.get(); |
| 4257 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4258 | Built.Init = Init.get(); |
| 4259 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4260 | Built.LB = LB.get(); |
| 4261 | Built.UB = UB.get(); |
| 4262 | Built.IL = IL.get(); |
| 4263 | Built.ST = ST.get(); |
| 4264 | Built.EUB = EUB.get(); |
| 4265 | Built.NLB = NextLB.get(); |
| 4266 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4267 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4268 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4271 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4272 | auto CollapseClauses = |
| 4273 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4274 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4275 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4276 | return nullptr; |
| 4277 | } |
| 4278 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4279 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4280 | auto OrderedClauses = |
| 4281 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4282 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4283 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4284 | return nullptr; |
| 4285 | } |
| 4286 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4287 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4288 | const Expr *Safelen) { |
| 4289 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4290 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4291 | Simdlen->isInstantiationDependent() || |
| 4292 | Simdlen->containsUnexpandedParameterPack()) |
| 4293 | return false; |
| 4294 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4295 | Safelen->isInstantiationDependent() || |
| 4296 | Safelen->containsUnexpandedParameterPack()) |
| 4297 | return false; |
| 4298 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4299 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4300 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4301 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4302 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4303 | if (SimdlenRes > SafelenRes) { |
| 4304 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4305 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4306 | return true; |
| 4307 | } |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4311 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4312 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4313 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4314 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4315 | if (!AStmt) |
| 4316 | return StmtError(); |
| 4317 | |
| 4318 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4319 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4320 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4321 | // define the nested loops number. |
| 4322 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4323 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4324 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4325 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4326 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4327 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4328 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4329 | "omp simd loop exprs were not built"); |
| 4330 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4331 | if (!CurContext->isDependentContext()) { |
| 4332 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4333 | for (auto C : Clauses) { |
| 4334 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4335 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4336 | B.NumIterations, *this, CurScope)) |
| 4337 | return StmtError(); |
| 4338 | } |
| 4339 | } |
| 4340 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4341 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4342 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4343 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4344 | OMPSafelenClause *Safelen = nullptr; |
| 4345 | OMPSimdlenClause *Simdlen = nullptr; |
| 4346 | for (auto *Clause : Clauses) { |
| 4347 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4348 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4349 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4350 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4351 | if (Safelen && Simdlen) |
| 4352 | break; |
| 4353 | } |
| 4354 | if (Simdlen && Safelen && |
| 4355 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4356 | Safelen->getSafelen())) |
| 4357 | return StmtError(); |
| 4358 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4359 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4360 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4361 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4364 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4365 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4366 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4367 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4368 | if (!AStmt) |
| 4369 | return StmtError(); |
| 4370 | |
| 4371 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4372 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4373 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4374 | // define the nested loops number. |
| 4375 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4376 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4377 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4378 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4379 | return StmtError(); |
| 4380 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4381 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4382 | "omp for loop exprs were not built"); |
| 4383 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4384 | if (!CurContext->isDependentContext()) { |
| 4385 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4386 | for (auto C : Clauses) { |
| 4387 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4388 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4389 | B.NumIterations, *this, CurScope)) |
| 4390 | return StmtError(); |
| 4391 | } |
| 4392 | } |
| 4393 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4394 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4395 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4396 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4399 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4400 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4401 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4402 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4403 | if (!AStmt) |
| 4404 | return StmtError(); |
| 4405 | |
| 4406 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4407 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4408 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4409 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4410 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4411 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4412 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4413 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4414 | if (NestedLoopCount == 0) |
| 4415 | return StmtError(); |
| 4416 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4417 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4418 | "omp for simd loop exprs were not built"); |
| 4419 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4420 | if (!CurContext->isDependentContext()) { |
| 4421 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4422 | for (auto C : Clauses) { |
| 4423 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4424 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4425 | B.NumIterations, *this, CurScope)) |
| 4426 | return StmtError(); |
| 4427 | } |
| 4428 | } |
| 4429 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4430 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4431 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4432 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4433 | OMPSafelenClause *Safelen = nullptr; |
| 4434 | OMPSimdlenClause *Simdlen = nullptr; |
| 4435 | for (auto *Clause : Clauses) { |
| 4436 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4437 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4438 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4439 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4440 | if (Safelen && Simdlen) |
| 4441 | break; |
| 4442 | } |
| 4443 | if (Simdlen && Safelen && |
| 4444 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4445 | Safelen->getSafelen())) |
| 4446 | return StmtError(); |
| 4447 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4448 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4449 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4450 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4451 | } |
| 4452 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4453 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4454 | Stmt *AStmt, |
| 4455 | SourceLocation StartLoc, |
| 4456 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4457 | if (!AStmt) |
| 4458 | return StmtError(); |
| 4459 | |
| 4460 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4461 | auto BaseStmt = AStmt; |
| 4462 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4463 | BaseStmt = CS->getCapturedStmt(); |
| 4464 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4465 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4466 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4467 | return StmtError(); |
| 4468 | // All associated statements must be '#pragma omp section' except for |
| 4469 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4470 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4471 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4472 | if (SectionStmt) |
| 4473 | Diag(SectionStmt->getLocStart(), |
| 4474 | diag::err_omp_sections_substmt_not_section); |
| 4475 | return StmtError(); |
| 4476 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4477 | cast<OMPSectionDirective>(SectionStmt) |
| 4478 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4479 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4480 | } else { |
| 4481 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4482 | return StmtError(); |
| 4483 | } |
| 4484 | |
| 4485 | getCurFunction()->setHasBranchProtectedScope(); |
| 4486 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4487 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4488 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4491 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4492 | SourceLocation StartLoc, |
| 4493 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4494 | if (!AStmt) |
| 4495 | return StmtError(); |
| 4496 | |
| 4497 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4498 | |
| 4499 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4500 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4501 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4502 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4503 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4504 | } |
| 4505 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4506 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4507 | Stmt *AStmt, |
| 4508 | SourceLocation StartLoc, |
| 4509 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4510 | if (!AStmt) |
| 4511 | return StmtError(); |
| 4512 | |
| 4513 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4514 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4515 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4516 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4517 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4518 | // The copyprivate clause must not be used with the nowait clause. |
| 4519 | OMPClause *Nowait = nullptr; |
| 4520 | OMPClause *Copyprivate = nullptr; |
| 4521 | for (auto *Clause : Clauses) { |
| 4522 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4523 | Nowait = Clause; |
| 4524 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4525 | Copyprivate = Clause; |
| 4526 | if (Copyprivate && Nowait) { |
| 4527 | Diag(Copyprivate->getLocStart(), |
| 4528 | diag::err_omp_single_copyprivate_with_nowait); |
| 4529 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4530 | return StmtError(); |
| 4531 | } |
| 4532 | } |
| 4533 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4534 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4535 | } |
| 4536 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4537 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4538 | SourceLocation StartLoc, |
| 4539 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4540 | if (!AStmt) |
| 4541 | return StmtError(); |
| 4542 | |
| 4543 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4544 | |
| 4545 | getCurFunction()->setHasBranchProtectedScope(); |
| 4546 | |
| 4547 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4548 | } |
| 4549 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4550 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4551 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4552 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4553 | if (!AStmt) |
| 4554 | return StmtError(); |
| 4555 | |
| 4556 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4557 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4558 | bool ErrorFound = false; |
| 4559 | llvm::APSInt Hint; |
| 4560 | SourceLocation HintLoc; |
| 4561 | bool DependentHint = false; |
| 4562 | for (auto *C : Clauses) { |
| 4563 | if (C->getClauseKind() == OMPC_hint) { |
| 4564 | if (!DirName.getName()) { |
| 4565 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4566 | ErrorFound = true; |
| 4567 | } |
| 4568 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4569 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4570 | E->isInstantiationDependent()) |
| 4571 | DependentHint = true; |
| 4572 | else { |
| 4573 | Hint = E->EvaluateKnownConstInt(Context); |
| 4574 | HintLoc = C->getLocStart(); |
| 4575 | } |
| 4576 | } |
| 4577 | } |
| 4578 | if (ErrorFound) |
| 4579 | return StmtError(); |
| 4580 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4581 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4582 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4583 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4584 | if (HintLoc.isValid()) { |
| 4585 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4586 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4587 | } else |
| 4588 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4589 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4590 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4591 | << 1 |
| 4592 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4593 | /*Radix=*/10, /*Signed=*/false); |
| 4594 | } else |
| 4595 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4596 | } |
| 4597 | } |
| 4598 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4599 | getCurFunction()->setHasBranchProtectedScope(); |
| 4600 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4601 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4602 | Clauses, AStmt); |
| 4603 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4604 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4605 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4606 | } |
| 4607 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4608 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4609 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4610 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4611 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4612 | if (!AStmt) |
| 4613 | return StmtError(); |
| 4614 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4615 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4616 | // 1.2.2 OpenMP Language Terminology |
| 4617 | // Structured block - An executable statement with a single entry at the |
| 4618 | // top and a single exit at the bottom. |
| 4619 | // The point of exit cannot be a branch out of the structured block. |
| 4620 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4621 | CS->getCapturedDecl()->setNothrow(); |
| 4622 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4623 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4624 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4625 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4626 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4627 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4628 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4629 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4630 | if (NestedLoopCount == 0) |
| 4631 | return StmtError(); |
| 4632 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4633 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4634 | "omp parallel for loop exprs were not built"); |
| 4635 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4636 | if (!CurContext->isDependentContext()) { |
| 4637 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4638 | for (auto C : Clauses) { |
| 4639 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4640 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4641 | B.NumIterations, *this, CurScope)) |
| 4642 | return StmtError(); |
| 4643 | } |
| 4644 | } |
| 4645 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4646 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4647 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4648 | NestedLoopCount, Clauses, AStmt, B, |
| 4649 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4652 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4653 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4654 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4655 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4656 | if (!AStmt) |
| 4657 | return StmtError(); |
| 4658 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4659 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4660 | // 1.2.2 OpenMP Language Terminology |
| 4661 | // Structured block - An executable statement with a single entry at the |
| 4662 | // top and a single exit at the bottom. |
| 4663 | // The point of exit cannot be a branch out of the structured block. |
| 4664 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4665 | CS->getCapturedDecl()->setNothrow(); |
| 4666 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4667 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4668 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4669 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4670 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4671 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4672 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4673 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4674 | if (NestedLoopCount == 0) |
| 4675 | return StmtError(); |
| 4676 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4677 | if (!CurContext->isDependentContext()) { |
| 4678 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4679 | for (auto C : Clauses) { |
| 4680 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4681 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4682 | B.NumIterations, *this, CurScope)) |
| 4683 | return StmtError(); |
| 4684 | } |
| 4685 | } |
| 4686 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4687 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4688 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4689 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4690 | OMPSafelenClause *Safelen = nullptr; |
| 4691 | OMPSimdlenClause *Simdlen = nullptr; |
| 4692 | for (auto *Clause : Clauses) { |
| 4693 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4694 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4695 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4696 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4697 | if (Safelen && Simdlen) |
| 4698 | break; |
| 4699 | } |
| 4700 | if (Simdlen && Safelen && |
| 4701 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4702 | Safelen->getSafelen())) |
| 4703 | return StmtError(); |
| 4704 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4705 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4706 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4707 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4710 | StmtResult |
| 4711 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4712 | Stmt *AStmt, SourceLocation StartLoc, |
| 4713 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4714 | if (!AStmt) |
| 4715 | return StmtError(); |
| 4716 | |
| 4717 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4718 | auto BaseStmt = AStmt; |
| 4719 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4720 | BaseStmt = CS->getCapturedStmt(); |
| 4721 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4722 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4723 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4724 | return StmtError(); |
| 4725 | // All associated statements must be '#pragma omp section' except for |
| 4726 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4727 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4728 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4729 | if (SectionStmt) |
| 4730 | Diag(SectionStmt->getLocStart(), |
| 4731 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4732 | return StmtError(); |
| 4733 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4734 | cast<OMPSectionDirective>(SectionStmt) |
| 4735 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4736 | } |
| 4737 | } else { |
| 4738 | Diag(AStmt->getLocStart(), |
| 4739 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4740 | return StmtError(); |
| 4741 | } |
| 4742 | |
| 4743 | getCurFunction()->setHasBranchProtectedScope(); |
| 4744 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4745 | return OMPParallelSectionsDirective::Create( |
| 4746 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4749 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4750 | Stmt *AStmt, SourceLocation StartLoc, |
| 4751 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4752 | if (!AStmt) |
| 4753 | return StmtError(); |
| 4754 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4755 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4756 | // 1.2.2 OpenMP Language Terminology |
| 4757 | // Structured block - An executable statement with a single entry at the |
| 4758 | // top and a single exit at the bottom. |
| 4759 | // The point of exit cannot be a branch out of the structured block. |
| 4760 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4761 | CS->getCapturedDecl()->setNothrow(); |
| 4762 | |
| 4763 | getCurFunction()->setHasBranchProtectedScope(); |
| 4764 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4765 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4766 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4769 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4770 | SourceLocation EndLoc) { |
| 4771 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4772 | } |
| 4773 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4774 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4775 | SourceLocation EndLoc) { |
| 4776 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4777 | } |
| 4778 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4779 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4780 | SourceLocation EndLoc) { |
| 4781 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4782 | } |
| 4783 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4784 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4785 | SourceLocation StartLoc, |
| 4786 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4787 | if (!AStmt) |
| 4788 | return StmtError(); |
| 4789 | |
| 4790 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4791 | |
| 4792 | getCurFunction()->setHasBranchProtectedScope(); |
| 4793 | |
| 4794 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4795 | } |
| 4796 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4797 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4798 | SourceLocation StartLoc, |
| 4799 | SourceLocation EndLoc) { |
| 4800 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4801 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4802 | } |
| 4803 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4804 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4805 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4806 | SourceLocation StartLoc, |
| 4807 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4808 | OMPClause *DependFound = nullptr; |
| 4809 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4810 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4811 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4812 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4813 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4814 | for (auto *C : Clauses) { |
| 4815 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4816 | DependFound = C; |
| 4817 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4818 | if (DependSourceClause) { |
| 4819 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4820 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4821 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4822 | ErrorFound = true; |
| 4823 | } else |
| 4824 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4825 | if (DependSinkClause) { |
| 4826 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4827 | << 0; |
| 4828 | ErrorFound = true; |
| 4829 | } |
| 4830 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4831 | if (DependSourceClause) { |
| 4832 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4833 | << 1; |
| 4834 | ErrorFound = true; |
| 4835 | } |
| 4836 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4837 | } |
| 4838 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4839 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4840 | else if (C->getClauseKind() == OMPC_simd) |
| 4841 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4842 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4843 | if (!ErrorFound && !SC && |
| 4844 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4845 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4846 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4847 | // that can appear in the simd region. |
| 4848 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4849 | ErrorFound = true; |
| 4850 | } else if (DependFound && (TC || SC)) { |
| 4851 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4852 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4853 | ErrorFound = true; |
| 4854 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4855 | Diag(DependFound->getLocStart(), |
| 4856 | diag::err_omp_ordered_directive_without_param); |
| 4857 | ErrorFound = true; |
| 4858 | } else if (TC || Clauses.empty()) { |
| 4859 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4860 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4861 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4862 | << (TC != nullptr); |
| 4863 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4864 | ErrorFound = true; |
| 4865 | } |
| 4866 | } |
| 4867 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4868 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4869 | |
| 4870 | if (AStmt) { |
| 4871 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4872 | |
| 4873 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4874 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4875 | |
| 4876 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4877 | } |
| 4878 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4879 | namespace { |
| 4880 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4881 | /// construct. |
| 4882 | class OpenMPAtomicUpdateChecker { |
| 4883 | /// \brief Error results for atomic update expressions. |
| 4884 | enum ExprAnalysisErrorCode { |
| 4885 | /// \brief A statement is not an expression statement. |
| 4886 | NotAnExpression, |
| 4887 | /// \brief Expression is not builtin binary or unary operation. |
| 4888 | NotABinaryOrUnaryExpression, |
| 4889 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4890 | NotAnUnaryIncDecExpression, |
| 4891 | /// \brief An expression is not of scalar type. |
| 4892 | NotAScalarType, |
| 4893 | /// \brief A binary operation is not an assignment operation. |
| 4894 | NotAnAssignmentOp, |
| 4895 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4896 | NotABinaryExpression, |
| 4897 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4898 | /// expression. |
| 4899 | NotABinaryOperator, |
| 4900 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4901 | /// part. |
| 4902 | NotAnUpdateExpression, |
| 4903 | /// \brief No errors is found. |
| 4904 | NoError |
| 4905 | }; |
| 4906 | /// \brief Reference to Sema. |
| 4907 | Sema &SemaRef; |
| 4908 | /// \brief A location for note diagnostics (when error is found). |
| 4909 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4910 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4911 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4912 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4913 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4914 | /// \brief Helper expression of the form |
| 4915 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4916 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4917 | Expr *UpdateExpr; |
| 4918 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4919 | /// important for non-associative operations. |
| 4920 | bool IsXLHSInRHSPart; |
| 4921 | BinaryOperatorKind Op; |
| 4922 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4923 | /// \brief true if the source expression is a postfix unary operation, false |
| 4924 | /// if it is a prefix unary operation. |
| 4925 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4926 | |
| 4927 | public: |
| 4928 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4929 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4930 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4931 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4932 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4933 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4934 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4935 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4936 | /// \param NoteId Diagnostic note for the main error message. |
| 4937 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4938 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4939 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4940 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4941 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4942 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4943 | /// \brief Return the update expression used in calculation of the updated |
| 4944 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4945 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4946 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4947 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4948 | /// false otherwise. |
| 4949 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4950 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4951 | /// \brief true if the source expression is a postfix unary operation, false |
| 4952 | /// if it is a prefix unary operation. |
| 4953 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4954 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4955 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4956 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4957 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4958 | }; |
| 4959 | } // namespace |
| 4960 | |
| 4961 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4962 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4963 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4964 | SourceLocation ErrorLoc, NoteLoc; |
| 4965 | SourceRange ErrorRange, NoteRange; |
| 4966 | // Allowed constructs are: |
| 4967 | // x = x binop expr; |
| 4968 | // x = expr binop x; |
| 4969 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4970 | X = AtomicBinOp->getLHS(); |
| 4971 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4972 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4973 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4974 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4975 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4976 | Op = AtomicInnerBinOp->getOpcode(); |
| 4977 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4978 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4979 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4980 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4981 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4982 | /*Canonical=*/true); |
| 4983 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4984 | /*Canonical=*/true); |
| 4985 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4986 | /*Canonical=*/true); |
| 4987 | if (XId == LHSId) { |
| 4988 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4989 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4990 | } else if (XId == RHSId) { |
| 4991 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4992 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4993 | } else { |
| 4994 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4995 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4996 | NoteLoc = X->getExprLoc(); |
| 4997 | NoteRange = X->getSourceRange(); |
| 4998 | ErrorFound = NotAnUpdateExpression; |
| 4999 | } |
| 5000 | } else { |
| 5001 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5002 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5003 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5004 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5005 | ErrorFound = NotABinaryOperator; |
| 5006 | } |
| 5007 | } else { |
| 5008 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5009 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5010 | ErrorFound = NotABinaryExpression; |
| 5011 | } |
| 5012 | } else { |
| 5013 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5014 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5015 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5016 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5017 | ErrorFound = NotAnAssignmentOp; |
| 5018 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5019 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5020 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5021 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5022 | return true; |
| 5023 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5024 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5025 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5029 | unsigned NoteId) { |
| 5030 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5031 | SourceLocation ErrorLoc, NoteLoc; |
| 5032 | SourceRange ErrorRange, NoteRange; |
| 5033 | // Allowed constructs are: |
| 5034 | // x++; |
| 5035 | // x--; |
| 5036 | // ++x; |
| 5037 | // --x; |
| 5038 | // x binop= expr; |
| 5039 | // x = x binop expr; |
| 5040 | // x = expr binop x; |
| 5041 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5042 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5043 | if (AtomicBody->getType()->isScalarType() || |
| 5044 | AtomicBody->isInstantiationDependent()) { |
| 5045 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5046 | AtomicBody->IgnoreParenImpCasts())) { |
| 5047 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5048 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5049 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5050 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5051 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5052 | X = AtomicCompAssignOp->getLHS(); |
| 5053 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5054 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5055 | AtomicBody->IgnoreParenImpCasts())) { |
| 5056 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5057 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5058 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5059 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5060 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5061 | // Check for Unary Operation |
| 5062 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5063 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5064 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5065 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5066 | X = AtomicUnaryOp->getSubExpr(); |
| 5067 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5068 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5069 | } else { |
| 5070 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5071 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5072 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5073 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5074 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5075 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5076 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5077 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5078 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5079 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5080 | } |
| 5081 | } else { |
| 5082 | ErrorFound = NotAScalarType; |
| 5083 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5084 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5085 | } |
| 5086 | } else { |
| 5087 | ErrorFound = NotAnExpression; |
| 5088 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5089 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5090 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5091 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5092 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5093 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5094 | return true; |
| 5095 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5096 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5097 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5098 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5099 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5100 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5101 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5102 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5103 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5104 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5105 | auto Update = |
| 5106 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5107 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5108 | if (Update.isInvalid()) |
| 5109 | return true; |
| 5110 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5111 | Sema::AA_Casting); |
| 5112 | if (Update.isInvalid()) |
| 5113 | return true; |
| 5114 | UpdateExpr = Update.get(); |
| 5115 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5116 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5119 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5120 | Stmt *AStmt, |
| 5121 | SourceLocation StartLoc, |
| 5122 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5123 | if (!AStmt) |
| 5124 | return StmtError(); |
| 5125 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5126 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5127 | // 1.2.2 OpenMP Language Terminology |
| 5128 | // Structured block - An executable statement with a single entry at the |
| 5129 | // top and a single exit at the bottom. |
| 5130 | // The point of exit cannot be a branch out of the structured block. |
| 5131 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5132 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5133 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5134 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5135 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5136 | C->getClauseKind() == OMPC_update || |
| 5137 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5138 | if (AtomicKind != OMPC_unknown) { |
| 5139 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5140 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5141 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5142 | << getOpenMPClauseName(AtomicKind); |
| 5143 | } else { |
| 5144 | AtomicKind = C->getClauseKind(); |
| 5145 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5149 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5150 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5151 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5152 | Body = EWC->getSubExpr(); |
| 5153 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5154 | Expr *X = nullptr; |
| 5155 | Expr *V = nullptr; |
| 5156 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5157 | Expr *UE = nullptr; |
| 5158 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5159 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5160 | // OpenMP [2.12.6, atomic Construct] |
| 5161 | // In the next expressions: |
| 5162 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5163 | // * During the execution of an atomic region, multiple syntactic |
| 5164 | // occurrences of x must designate the same storage location. |
| 5165 | // * Neither of v and expr (as applicable) may access the storage location |
| 5166 | // designated by x. |
| 5167 | // * Neither of x and expr (as applicable) may access the storage location |
| 5168 | // designated by v. |
| 5169 | // * expr is an expression with scalar type. |
| 5170 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5171 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5172 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5173 | // (expr). This requirement is satisfied if the operators in expr have |
| 5174 | // precedence greater than binop, or by using parentheses around expr or |
| 5175 | // subexpressions of expr. |
| 5176 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5177 | // binop x. This requirement is satisfied if the operators in expr have |
| 5178 | // precedence equal to or greater than binop, or by using parentheses around |
| 5179 | // expr or subexpressions of expr. |
| 5180 | // * For forms that allow multiple occurrences of x, the number of times |
| 5181 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5182 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5183 | enum { |
| 5184 | NotAnExpression, |
| 5185 | NotAnAssignmentOp, |
| 5186 | NotAScalarType, |
| 5187 | NotAnLValue, |
| 5188 | NoError |
| 5189 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5190 | SourceLocation ErrorLoc, NoteLoc; |
| 5191 | SourceRange ErrorRange, NoteRange; |
| 5192 | // If clause is read: |
| 5193 | // v = x; |
| 5194 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5195 | auto AtomicBinOp = |
| 5196 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5197 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5198 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5199 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5200 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5201 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5202 | if (!X->isLValue() || !V->isLValue()) { |
| 5203 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5204 | ErrorFound = NotAnLValue; |
| 5205 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5206 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5207 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5208 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5209 | } |
| 5210 | } else if (!X->isInstantiationDependent() || |
| 5211 | !V->isInstantiationDependent()) { |
| 5212 | auto NotScalarExpr = |
| 5213 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5214 | ? V |
| 5215 | : X; |
| 5216 | ErrorFound = NotAScalarType; |
| 5217 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5218 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5219 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5220 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5221 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5222 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5223 | ErrorFound = NotAnAssignmentOp; |
| 5224 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5225 | ErrorRange = AtomicBody->getSourceRange(); |
| 5226 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5227 | : AtomicBody->getExprLoc(); |
| 5228 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5229 | : AtomicBody->getSourceRange(); |
| 5230 | } |
| 5231 | } else { |
| 5232 | ErrorFound = NotAnExpression; |
| 5233 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5234 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5235 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5236 | if (ErrorFound != NoError) { |
| 5237 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5238 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5239 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5240 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5241 | return StmtError(); |
| 5242 | } else if (CurContext->isDependentContext()) |
| 5243 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5244 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5245 | enum { |
| 5246 | NotAnExpression, |
| 5247 | NotAnAssignmentOp, |
| 5248 | NotAScalarType, |
| 5249 | NotAnLValue, |
| 5250 | NoError |
| 5251 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5252 | SourceLocation ErrorLoc, NoteLoc; |
| 5253 | SourceRange ErrorRange, NoteRange; |
| 5254 | // If clause is write: |
| 5255 | // x = expr; |
| 5256 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5257 | auto AtomicBinOp = |
| 5258 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5259 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5260 | X = AtomicBinOp->getLHS(); |
| 5261 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5262 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5263 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5264 | if (!X->isLValue()) { |
| 5265 | ErrorFound = NotAnLValue; |
| 5266 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5267 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5268 | NoteLoc = X->getExprLoc(); |
| 5269 | NoteRange = X->getSourceRange(); |
| 5270 | } |
| 5271 | } else if (!X->isInstantiationDependent() || |
| 5272 | !E->isInstantiationDependent()) { |
| 5273 | auto NotScalarExpr = |
| 5274 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5275 | ? E |
| 5276 | : X; |
| 5277 | ErrorFound = NotAScalarType; |
| 5278 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5279 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5280 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5281 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5282 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5283 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5284 | ErrorFound = NotAnAssignmentOp; |
| 5285 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5286 | ErrorRange = AtomicBody->getSourceRange(); |
| 5287 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5288 | : AtomicBody->getExprLoc(); |
| 5289 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5290 | : AtomicBody->getSourceRange(); |
| 5291 | } |
| 5292 | } else { |
| 5293 | ErrorFound = NotAnExpression; |
| 5294 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5295 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5296 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5297 | if (ErrorFound != NoError) { |
| 5298 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5299 | << ErrorRange; |
| 5300 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5301 | << NoteRange; |
| 5302 | return StmtError(); |
| 5303 | } else if (CurContext->isDependentContext()) |
| 5304 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5305 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5306 | // If clause is update: |
| 5307 | // x++; |
| 5308 | // x--; |
| 5309 | // ++x; |
| 5310 | // --x; |
| 5311 | // x binop= expr; |
| 5312 | // x = x binop expr; |
| 5313 | // x = expr binop x; |
| 5314 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5315 | if (Checker.checkStatement( |
| 5316 | Body, (AtomicKind == OMPC_update) |
| 5317 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5318 | : diag::err_omp_atomic_not_expression_statement, |
| 5319 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5320 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5321 | if (!CurContext->isDependentContext()) { |
| 5322 | E = Checker.getExpr(); |
| 5323 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5324 | UE = Checker.getUpdateExpr(); |
| 5325 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5326 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5327 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5328 | enum { |
| 5329 | NotAnAssignmentOp, |
| 5330 | NotACompoundStatement, |
| 5331 | NotTwoSubstatements, |
| 5332 | NotASpecificExpression, |
| 5333 | NoError |
| 5334 | } ErrorFound = NoError; |
| 5335 | SourceLocation ErrorLoc, NoteLoc; |
| 5336 | SourceRange ErrorRange, NoteRange; |
| 5337 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5338 | // If clause is a capture: |
| 5339 | // v = x++; |
| 5340 | // v = x--; |
| 5341 | // v = ++x; |
| 5342 | // v = --x; |
| 5343 | // v = x binop= expr; |
| 5344 | // v = x = x binop expr; |
| 5345 | // v = x = expr binop x; |
| 5346 | auto *AtomicBinOp = |
| 5347 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5348 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5349 | V = AtomicBinOp->getLHS(); |
| 5350 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5351 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5352 | if (Checker.checkStatement( |
| 5353 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5354 | diag::note_omp_atomic_update)) |
| 5355 | return StmtError(); |
| 5356 | E = Checker.getExpr(); |
| 5357 | X = Checker.getX(); |
| 5358 | UE = Checker.getUpdateExpr(); |
| 5359 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5360 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5361 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5362 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5363 | ErrorRange = AtomicBody->getSourceRange(); |
| 5364 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5365 | : AtomicBody->getExprLoc(); |
| 5366 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5367 | : AtomicBody->getSourceRange(); |
| 5368 | ErrorFound = NotAnAssignmentOp; |
| 5369 | } |
| 5370 | if (ErrorFound != NoError) { |
| 5371 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5372 | << ErrorRange; |
| 5373 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5374 | return StmtError(); |
| 5375 | } else if (CurContext->isDependentContext()) { |
| 5376 | UE = V = E = X = nullptr; |
| 5377 | } |
| 5378 | } else { |
| 5379 | // If clause is a capture: |
| 5380 | // { v = x; x = expr; } |
| 5381 | // { v = x; x++; } |
| 5382 | // { v = x; x--; } |
| 5383 | // { v = x; ++x; } |
| 5384 | // { v = x; --x; } |
| 5385 | // { v = x; x binop= expr; } |
| 5386 | // { v = x; x = x binop expr; } |
| 5387 | // { v = x; x = expr binop x; } |
| 5388 | // { x++; v = x; } |
| 5389 | // { x--; v = x; } |
| 5390 | // { ++x; v = x; } |
| 5391 | // { --x; v = x; } |
| 5392 | // { x binop= expr; v = x; } |
| 5393 | // { x = x binop expr; v = x; } |
| 5394 | // { x = expr binop x; v = x; } |
| 5395 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5396 | // Check that this is { expr1; expr2; } |
| 5397 | if (CS->size() == 2) { |
| 5398 | auto *First = CS->body_front(); |
| 5399 | auto *Second = CS->body_back(); |
| 5400 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5401 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5402 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5403 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5404 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5405 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5406 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5407 | BinaryOperator *BinOp = nullptr; |
| 5408 | if (IsUpdateExprFound) { |
| 5409 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5410 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5411 | } |
| 5412 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5413 | // { v = x; x++; } |
| 5414 | // { v = x; x--; } |
| 5415 | // { v = x; ++x; } |
| 5416 | // { v = x; --x; } |
| 5417 | // { v = x; x binop= expr; } |
| 5418 | // { v = x; x = x binop expr; } |
| 5419 | // { v = x; x = expr binop x; } |
| 5420 | // Check that the first expression has form v = x. |
| 5421 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5422 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5423 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5424 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5425 | IsUpdateExprFound = XId == PossibleXId; |
| 5426 | if (IsUpdateExprFound) { |
| 5427 | V = BinOp->getLHS(); |
| 5428 | X = Checker.getX(); |
| 5429 | E = Checker.getExpr(); |
| 5430 | UE = Checker.getUpdateExpr(); |
| 5431 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5432 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5433 | } |
| 5434 | } |
| 5435 | if (!IsUpdateExprFound) { |
| 5436 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5437 | BinOp = nullptr; |
| 5438 | if (IsUpdateExprFound) { |
| 5439 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5440 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5441 | } |
| 5442 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5443 | // { x++; v = x; } |
| 5444 | // { x--; v = x; } |
| 5445 | // { ++x; v = x; } |
| 5446 | // { --x; v = x; } |
| 5447 | // { x binop= expr; v = x; } |
| 5448 | // { x = x binop expr; v = x; } |
| 5449 | // { x = expr binop x; v = x; } |
| 5450 | // Check that the second expression has form v = x. |
| 5451 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5452 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5453 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5454 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5455 | IsUpdateExprFound = XId == PossibleXId; |
| 5456 | if (IsUpdateExprFound) { |
| 5457 | V = BinOp->getLHS(); |
| 5458 | X = Checker.getX(); |
| 5459 | E = Checker.getExpr(); |
| 5460 | UE = Checker.getUpdateExpr(); |
| 5461 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5462 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5463 | } |
| 5464 | } |
| 5465 | } |
| 5466 | if (!IsUpdateExprFound) { |
| 5467 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5468 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5469 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5470 | if (!FirstExpr || !SecondExpr || |
| 5471 | !(FirstExpr->isInstantiationDependent() || |
| 5472 | SecondExpr->isInstantiationDependent())) { |
| 5473 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5474 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5475 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5476 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5477 | : First->getLocStart(); |
| 5478 | NoteRange = ErrorRange = FirstBinOp |
| 5479 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5480 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5481 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5482 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5483 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5484 | ErrorFound = NotAnAssignmentOp; |
| 5485 | NoteLoc = ErrorLoc = SecondBinOp |
| 5486 | ? SecondBinOp->getOperatorLoc() |
| 5487 | : Second->getLocStart(); |
| 5488 | NoteRange = ErrorRange = |
| 5489 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5490 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5491 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5492 | auto *PossibleXRHSInFirst = |
| 5493 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5494 | auto *PossibleXLHSInSecond = |
| 5495 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5496 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5497 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5498 | /*Canonical=*/true); |
| 5499 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5500 | /*Canonical=*/true); |
| 5501 | IsUpdateExprFound = X1Id == X2Id; |
| 5502 | if (IsUpdateExprFound) { |
| 5503 | V = FirstBinOp->getLHS(); |
| 5504 | X = SecondBinOp->getLHS(); |
| 5505 | E = SecondBinOp->getRHS(); |
| 5506 | UE = nullptr; |
| 5507 | IsXLHSInRHSPart = false; |
| 5508 | IsPostfixUpdate = true; |
| 5509 | } else { |
| 5510 | ErrorFound = NotASpecificExpression; |
| 5511 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5512 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5513 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5514 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5515 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5516 | } |
| 5517 | } |
| 5518 | } |
| 5519 | } |
| 5520 | } else { |
| 5521 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5522 | NoteRange = ErrorRange = |
| 5523 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5524 | ErrorFound = NotTwoSubstatements; |
| 5525 | } |
| 5526 | } else { |
| 5527 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5528 | NoteRange = ErrorRange = |
| 5529 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5530 | ErrorFound = NotACompoundStatement; |
| 5531 | } |
| 5532 | if (ErrorFound != NoError) { |
| 5533 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5534 | << ErrorRange; |
| 5535 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5536 | return StmtError(); |
| 5537 | } else if (CurContext->isDependentContext()) { |
| 5538 | UE = V = E = X = nullptr; |
| 5539 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5540 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5541 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5542 | |
| 5543 | getCurFunction()->setHasBranchProtectedScope(); |
| 5544 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5545 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5546 | X, V, E, UE, IsXLHSInRHSPart, |
| 5547 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5548 | } |
| 5549 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5550 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5551 | Stmt *AStmt, |
| 5552 | SourceLocation StartLoc, |
| 5553 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5554 | if (!AStmt) |
| 5555 | return StmtError(); |
| 5556 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5557 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5558 | // 1.2.2 OpenMP Language Terminology |
| 5559 | // Structured block - An executable statement with a single entry at the |
| 5560 | // top and a single exit at the bottom. |
| 5561 | // The point of exit cannot be a branch out of the structured block. |
| 5562 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5563 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5564 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5565 | // OpenMP [2.16, Nesting of Regions] |
| 5566 | // If specified, a teams construct must be contained within a target |
| 5567 | // construct. That target construct must contain no statements or directives |
| 5568 | // outside of the teams construct. |
| 5569 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5570 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5571 | bool OMPTeamsFound = true; |
| 5572 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5573 | auto I = CS->body_begin(); |
| 5574 | while (I != CS->body_end()) { |
| 5575 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5576 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5577 | OMPTeamsFound = false; |
| 5578 | break; |
| 5579 | } |
| 5580 | ++I; |
| 5581 | } |
| 5582 | assert(I != CS->body_end() && "Not found statement"); |
| 5583 | S = *I; |
| 5584 | } |
| 5585 | if (!OMPTeamsFound) { |
| 5586 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5587 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5588 | diag::note_omp_nested_teams_construct_here); |
| 5589 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5590 | << isa<OMPExecutableDirective>(S); |
| 5591 | return StmtError(); |
| 5592 | } |
| 5593 | } |
| 5594 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5595 | getCurFunction()->setHasBranchProtectedScope(); |
| 5596 | |
| 5597 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5598 | } |
| 5599 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5600 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5601 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5602 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5603 | I != E; ++I) { |
| 5604 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5605 | return true; |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | return false; |
| 5610 | } |
| 5611 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5612 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5613 | Stmt *AStmt, |
| 5614 | SourceLocation StartLoc, |
| 5615 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5616 | if (!AStmt) |
| 5617 | return StmtError(); |
| 5618 | |
| 5619 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5620 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5621 | getCurFunction()->setHasBranchProtectedScope(); |
| 5622 | |
| 5623 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5624 | AStmt); |
| 5625 | } |
| 5626 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5627 | StmtResult |
| 5628 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5629 | SourceLocation StartLoc, |
| 5630 | SourceLocation EndLoc) { |
| 5631 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5632 | // At least one map clause must appear on the directive. |
| 5633 | if (!HasMapClause(Clauses)) { |
| 5634 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5635 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5636 | return StmtError(); |
| 5637 | } |
| 5638 | |
| 5639 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5640 | Clauses); |
| 5641 | } |
| 5642 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5643 | StmtResult |
| 5644 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5645 | SourceLocation StartLoc, |
| 5646 | SourceLocation EndLoc) { |
| 5647 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5648 | // At least one map clause must appear on the directive. |
| 5649 | if (!HasMapClause(Clauses)) { |
| 5650 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5651 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5652 | return StmtError(); |
| 5653 | } |
| 5654 | |
| 5655 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5656 | } |
| 5657 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5658 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5659 | Stmt *AStmt, SourceLocation StartLoc, |
| 5660 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5661 | if (!AStmt) |
| 5662 | return StmtError(); |
| 5663 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5664 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5665 | // 1.2.2 OpenMP Language Terminology |
| 5666 | // Structured block - An executable statement with a single entry at the |
| 5667 | // top and a single exit at the bottom. |
| 5668 | // The point of exit cannot be a branch out of the structured block. |
| 5669 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5670 | CS->getCapturedDecl()->setNothrow(); |
| 5671 | |
| 5672 | getCurFunction()->setHasBranchProtectedScope(); |
| 5673 | |
| 5674 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5675 | } |
| 5676 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5677 | StmtResult |
| 5678 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5679 | SourceLocation EndLoc, |
| 5680 | OpenMPDirectiveKind CancelRegion) { |
| 5681 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5682 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5683 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5684 | << getOpenMPDirectiveName(CancelRegion); |
| 5685 | return StmtError(); |
| 5686 | } |
| 5687 | if (DSAStack->isParentNowaitRegion()) { |
| 5688 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5689 | return StmtError(); |
| 5690 | } |
| 5691 | if (DSAStack->isParentOrderedRegion()) { |
| 5692 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5693 | return StmtError(); |
| 5694 | } |
| 5695 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5696 | CancelRegion); |
| 5697 | } |
| 5698 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5699 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5700 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5701 | SourceLocation EndLoc, |
| 5702 | OpenMPDirectiveKind CancelRegion) { |
| 5703 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5704 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5705 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5706 | << getOpenMPDirectiveName(CancelRegion); |
| 5707 | return StmtError(); |
| 5708 | } |
| 5709 | if (DSAStack->isParentNowaitRegion()) { |
| 5710 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5711 | return StmtError(); |
| 5712 | } |
| 5713 | if (DSAStack->isParentOrderedRegion()) { |
| 5714 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5715 | return StmtError(); |
| 5716 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5717 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5718 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5719 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5720 | } |
| 5721 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5722 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5723 | ArrayRef<OMPClause *> Clauses) { |
| 5724 | OMPClause *PrevClause = nullptr; |
| 5725 | bool ErrorFound = false; |
| 5726 | for (auto *C : Clauses) { |
| 5727 | if (C->getClauseKind() == OMPC_grainsize || |
| 5728 | C->getClauseKind() == OMPC_num_tasks) { |
| 5729 | if (!PrevClause) |
| 5730 | PrevClause = C; |
| 5731 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5732 | S.Diag(C->getLocStart(), |
| 5733 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5734 | << getOpenMPClauseName(C->getClauseKind()) |
| 5735 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5736 | S.Diag(PrevClause->getLocStart(), |
| 5737 | diag::note_omp_previous_grainsize_num_tasks) |
| 5738 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5739 | ErrorFound = true; |
| 5740 | } |
| 5741 | } |
| 5742 | } |
| 5743 | return ErrorFound; |
| 5744 | } |
| 5745 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5746 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5747 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5748 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5749 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5750 | if (!AStmt) |
| 5751 | return StmtError(); |
| 5752 | |
| 5753 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5754 | OMPLoopDirective::HelperExprs B; |
| 5755 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5756 | // define the nested loops number. |
| 5757 | unsigned NestedLoopCount = |
| 5758 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5759 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5760 | VarsWithImplicitDSA, B); |
| 5761 | if (NestedLoopCount == 0) |
| 5762 | return StmtError(); |
| 5763 | |
| 5764 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5765 | "omp for loop exprs were not built"); |
| 5766 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5767 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5768 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5769 | // not appear on the same taskloop directive. |
| 5770 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5771 | return StmtError(); |
| 5772 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5773 | getCurFunction()->setHasBranchProtectedScope(); |
| 5774 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5775 | NestedLoopCount, Clauses, AStmt, B); |
| 5776 | } |
| 5777 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5778 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5779 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5780 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5781 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5782 | if (!AStmt) |
| 5783 | return StmtError(); |
| 5784 | |
| 5785 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5786 | OMPLoopDirective::HelperExprs B; |
| 5787 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5788 | // define the nested loops number. |
| 5789 | unsigned NestedLoopCount = |
| 5790 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5791 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5792 | VarsWithImplicitDSA, B); |
| 5793 | if (NestedLoopCount == 0) |
| 5794 | return StmtError(); |
| 5795 | |
| 5796 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5797 | "omp for loop exprs were not built"); |
| 5798 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5799 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5800 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5801 | // not appear on the same taskloop directive. |
| 5802 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5803 | return StmtError(); |
| 5804 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5805 | getCurFunction()->setHasBranchProtectedScope(); |
| 5806 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5807 | NestedLoopCount, Clauses, AStmt, B); |
| 5808 | } |
| 5809 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5810 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5811 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5812 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5813 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5814 | if (!AStmt) |
| 5815 | return StmtError(); |
| 5816 | |
| 5817 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5818 | OMPLoopDirective::HelperExprs B; |
| 5819 | // In presence of clause 'collapse' with number of loops, it will |
| 5820 | // define the nested loops number. |
| 5821 | unsigned NestedLoopCount = |
| 5822 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5823 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5824 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5825 | if (NestedLoopCount == 0) |
| 5826 | return StmtError(); |
| 5827 | |
| 5828 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5829 | "omp for loop exprs were not built"); |
| 5830 | |
| 5831 | getCurFunction()->setHasBranchProtectedScope(); |
| 5832 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5833 | NestedLoopCount, Clauses, AStmt, B); |
| 5834 | } |
| 5835 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5836 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5837 | SourceLocation StartLoc, |
| 5838 | SourceLocation LParenLoc, |
| 5839 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5840 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5841 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5842 | case OMPC_final: |
| 5843 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5844 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5845 | case OMPC_num_threads: |
| 5846 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5847 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5848 | case OMPC_safelen: |
| 5849 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5850 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5851 | case OMPC_simdlen: |
| 5852 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5853 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5854 | case OMPC_collapse: |
| 5855 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5856 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5857 | case OMPC_ordered: |
| 5858 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5859 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5860 | case OMPC_device: |
| 5861 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5862 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5863 | case OMPC_num_teams: |
| 5864 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5865 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5866 | case OMPC_thread_limit: |
| 5867 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5868 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5869 | case OMPC_priority: |
| 5870 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5871 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5872 | case OMPC_grainsize: |
| 5873 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5874 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5875 | case OMPC_num_tasks: |
| 5876 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5877 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5878 | case OMPC_hint: |
| 5879 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5880 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5881 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5882 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5883 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5884 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5885 | case OMPC_private: |
| 5886 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5887 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5888 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5889 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5890 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5891 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5892 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5893 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5894 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5895 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5896 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5897 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5898 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5899 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5900 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5901 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5902 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5903 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5904 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5905 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5906 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5907 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5908 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 5909 | case OMPC_dist_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5910 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5911 | llvm_unreachable("Clause is not allowed."); |
| 5912 | } |
| 5913 | return Res; |
| 5914 | } |
| 5915 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5916 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5917 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5918 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5919 | SourceLocation NameModifierLoc, |
| 5920 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5921 | SourceLocation EndLoc) { |
| 5922 | Expr *ValExpr = Condition; |
| 5923 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5924 | !Condition->isInstantiationDependent() && |
| 5925 | !Condition->containsUnexpandedParameterPack()) { |
| 5926 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5927 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5928 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5929 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5930 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5931 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5934 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5935 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5936 | } |
| 5937 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5938 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5939 | SourceLocation StartLoc, |
| 5940 | SourceLocation LParenLoc, |
| 5941 | SourceLocation EndLoc) { |
| 5942 | Expr *ValExpr = Condition; |
| 5943 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5944 | !Condition->isInstantiationDependent() && |
| 5945 | !Condition->containsUnexpandedParameterPack()) { |
| 5946 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5947 | Condition->getExprLoc(), Condition); |
| 5948 | if (Val.isInvalid()) |
| 5949 | return nullptr; |
| 5950 | |
| 5951 | ValExpr = Val.get(); |
| 5952 | } |
| 5953 | |
| 5954 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5955 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5956 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5957 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5958 | if (!Op) |
| 5959 | return ExprError(); |
| 5960 | |
| 5961 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5962 | public: |
| 5963 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5964 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5965 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5966 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5967 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5968 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5969 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5970 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5971 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5972 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5973 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5974 | QualType T, |
| 5975 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5976 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5977 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5978 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5979 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5980 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5981 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5982 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5983 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5984 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5985 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5986 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5987 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5988 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5989 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5990 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5991 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5992 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5993 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5994 | llvm_unreachable("conversion functions are permitted"); |
| 5995 | } |
| 5996 | } ConvertDiagnoser; |
| 5997 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5998 | } |
| 5999 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6000 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6001 | OpenMPClauseKind CKind, |
| 6002 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6003 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6004 | !ValExpr->isInstantiationDependent()) { |
| 6005 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6006 | ExprResult Value = |
| 6007 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6008 | if (Value.isInvalid()) |
| 6009 | return false; |
| 6010 | |
| 6011 | ValExpr = Value.get(); |
| 6012 | // The expression must evaluate to a non-negative integer value. |
| 6013 | llvm::APSInt Result; |
| 6014 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6015 | Result.isSigned() && |
| 6016 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6017 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6018 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6019 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6020 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6021 | return false; |
| 6022 | } |
| 6023 | } |
| 6024 | return true; |
| 6025 | } |
| 6026 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6027 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6028 | SourceLocation StartLoc, |
| 6029 | SourceLocation LParenLoc, |
| 6030 | SourceLocation EndLoc) { |
| 6031 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6032 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6033 | // OpenMP [2.5, Restrictions] |
| 6034 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6035 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6036 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6037 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6038 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6039 | return new (Context) |
| 6040 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6043 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6044 | OpenMPClauseKind CKind, |
| 6045 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6046 | if (!E) |
| 6047 | return ExprError(); |
| 6048 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6049 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6050 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6051 | llvm::APSInt Result; |
| 6052 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6053 | if (ICE.isInvalid()) |
| 6054 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6055 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6056 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6057 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6058 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6059 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6060 | return ExprError(); |
| 6061 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6062 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6063 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6064 | << E->getSourceRange(); |
| 6065 | return ExprError(); |
| 6066 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6067 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6068 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6069 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6070 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6071 | return ICE; |
| 6072 | } |
| 6073 | |
| 6074 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6075 | SourceLocation LParenLoc, |
| 6076 | SourceLocation EndLoc) { |
| 6077 | // OpenMP [2.8.1, simd construct, Description] |
| 6078 | // The parameter of the safelen clause must be a constant |
| 6079 | // positive integer expression. |
| 6080 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6081 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6082 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6083 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6084 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6087 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6088 | SourceLocation LParenLoc, |
| 6089 | SourceLocation EndLoc) { |
| 6090 | // OpenMP [2.8.1, simd construct, Description] |
| 6091 | // The parameter of the simdlen clause must be a constant |
| 6092 | // positive integer expression. |
| 6093 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6094 | if (Simdlen.isInvalid()) |
| 6095 | return nullptr; |
| 6096 | return new (Context) |
| 6097 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6098 | } |
| 6099 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6100 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6101 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6102 | SourceLocation LParenLoc, |
| 6103 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6104 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6105 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6106 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6107 | // The parameter of the collapse clause must be a constant |
| 6108 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6109 | ExprResult NumForLoopsResult = |
| 6110 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6111 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6112 | return nullptr; |
| 6113 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6114 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6115 | } |
| 6116 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6117 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6118 | SourceLocation EndLoc, |
| 6119 | SourceLocation LParenLoc, |
| 6120 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6121 | // OpenMP [2.7.1, loop construct, Description] |
| 6122 | // OpenMP [2.8.1, simd construct, Description] |
| 6123 | // OpenMP [2.9.6, distribute construct, Description] |
| 6124 | // The parameter of the ordered clause must be a constant |
| 6125 | // positive integer expression if any. |
| 6126 | if (NumForLoops && LParenLoc.isValid()) { |
| 6127 | ExprResult NumForLoopsResult = |
| 6128 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6129 | if (NumForLoopsResult.isInvalid()) |
| 6130 | return nullptr; |
| 6131 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6132 | } else |
| 6133 | NumForLoops = nullptr; |
| 6134 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6135 | return new (Context) |
| 6136 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6137 | } |
| 6138 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6139 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6140 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6141 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6142 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6143 | switch (Kind) { |
| 6144 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6145 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6146 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6147 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6148 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6149 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6150 | Res = ActOnOpenMPProcBindClause( |
| 6151 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6152 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6153 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6154 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6155 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6156 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6157 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6158 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6159 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6160 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6161 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6162 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6163 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6164 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6165 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6166 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6167 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6168 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6169 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6170 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6171 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6172 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6173 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6174 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6175 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6176 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6177 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6178 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6179 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6180 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6181 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6182 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6183 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6184 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6185 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6186 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6187 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6188 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6189 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6190 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6191 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6192 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6193 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6194 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6195 | llvm_unreachable("Clause is not allowed."); |
| 6196 | } |
| 6197 | return Res; |
| 6198 | } |
| 6199 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6200 | static std::string |
| 6201 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6202 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6203 | std::string Values; |
| 6204 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6205 | unsigned Skipped = Exclude.size(); |
| 6206 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6207 | for (unsigned i = First; i < Last; ++i) { |
| 6208 | if (std::find(S, E, i) != E) { |
| 6209 | --Skipped; |
| 6210 | continue; |
| 6211 | } |
| 6212 | Values += "'"; |
| 6213 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6214 | Values += "'"; |
| 6215 | if (i == Bound - Skipped) |
| 6216 | Values += " or "; |
| 6217 | else if (i != Bound + 1 - Skipped) |
| 6218 | Values += ", "; |
| 6219 | } |
| 6220 | return Values; |
| 6221 | } |
| 6222 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6223 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6224 | SourceLocation KindKwLoc, |
| 6225 | SourceLocation StartLoc, |
| 6226 | SourceLocation LParenLoc, |
| 6227 | SourceLocation EndLoc) { |
| 6228 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6229 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6230 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6231 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6232 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6233 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6234 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6235 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6236 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6237 | switch (Kind) { |
| 6238 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6239 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6240 | break; |
| 6241 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6242 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6243 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6244 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6245 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6246 | break; |
| 6247 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6248 | return new (Context) |
| 6249 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6250 | } |
| 6251 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6252 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6253 | SourceLocation KindKwLoc, |
| 6254 | SourceLocation StartLoc, |
| 6255 | SourceLocation LParenLoc, |
| 6256 | SourceLocation EndLoc) { |
| 6257 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6258 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6259 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6260 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6261 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6262 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6263 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6264 | return new (Context) |
| 6265 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6268 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6269 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6270 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6271 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6272 | SourceLocation EndLoc) { |
| 6273 | OMPClause *Res = nullptr; |
| 6274 | switch (Kind) { |
| 6275 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6276 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6277 | assert(Argument.size() == NumberOfElements && |
| 6278 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6279 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6280 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6281 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6282 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6283 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6284 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6285 | break; |
| 6286 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6287 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6288 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6289 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6290 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6291 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6292 | case OMPC_dist_schedule: |
| 6293 | Res = ActOnOpenMPDistScheduleClause( |
| 6294 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6295 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6296 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6297 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6298 | case OMPC_num_threads: |
| 6299 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6300 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6301 | case OMPC_collapse: |
| 6302 | case OMPC_default: |
| 6303 | case OMPC_proc_bind: |
| 6304 | case OMPC_private: |
| 6305 | case OMPC_firstprivate: |
| 6306 | case OMPC_lastprivate: |
| 6307 | case OMPC_shared: |
| 6308 | case OMPC_reduction: |
| 6309 | case OMPC_linear: |
| 6310 | case OMPC_aligned: |
| 6311 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6312 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6313 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6314 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6315 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6316 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6317 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6318 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6319 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6320 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6321 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6322 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6323 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6324 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6325 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6326 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6327 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6328 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6329 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6330 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6331 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6332 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6333 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6334 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6335 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6336 | case OMPC_unknown: |
| 6337 | llvm_unreachable("Clause is not allowed."); |
| 6338 | } |
| 6339 | return Res; |
| 6340 | } |
| 6341 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6342 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6343 | OpenMPScheduleClauseModifier M2, |
| 6344 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6345 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6346 | SmallVector<unsigned, 2> Excluded; |
| 6347 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6348 | Excluded.push_back(M2); |
| 6349 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6350 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6351 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6352 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6353 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6354 | << getListOfPossibleValues(OMPC_schedule, |
| 6355 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6356 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6357 | Excluded) |
| 6358 | << getOpenMPClauseName(OMPC_schedule); |
| 6359 | return true; |
| 6360 | } |
| 6361 | return false; |
| 6362 | } |
| 6363 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6364 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6365 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6366 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6367 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6368 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6369 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6370 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6371 | return nullptr; |
| 6372 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6373 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6374 | // but not both. |
| 6375 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6376 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6377 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6378 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6379 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6380 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6381 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6382 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6383 | return nullptr; |
| 6384 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6385 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6386 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6387 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6388 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6389 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6390 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6391 | Exclude); |
| 6392 | } else { |
| 6393 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6394 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6395 | } |
| 6396 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6397 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6398 | return nullptr; |
| 6399 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6400 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6401 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6402 | // schedule(guided). |
| 6403 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6404 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6405 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6406 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6407 | diag::err_omp_schedule_nonmonotonic_static); |
| 6408 | return nullptr; |
| 6409 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6410 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6411 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6412 | if (ChunkSize) { |
| 6413 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6414 | !ChunkSize->isInstantiationDependent() && |
| 6415 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6416 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6417 | ExprResult Val = |
| 6418 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6419 | if (Val.isInvalid()) |
| 6420 | return nullptr; |
| 6421 | |
| 6422 | ValExpr = Val.get(); |
| 6423 | |
| 6424 | // OpenMP [2.7.1, Restrictions] |
| 6425 | // chunk_size must be a loop invariant integer expression with a positive |
| 6426 | // value. |
| 6427 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6428 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6429 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6430 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6431 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6432 | return nullptr; |
| 6433 | } |
| 6434 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6435 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6436 | ChunkSize->getType(), ".chunk."); |
| 6437 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6438 | ChunkSize->getExprLoc(), |
| 6439 | /*RefersToCapture=*/true); |
| 6440 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6441 | } |
| 6442 | } |
| 6443 | } |
| 6444 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6445 | return new (Context) |
| 6446 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6447 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6448 | } |
| 6449 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6450 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6451 | SourceLocation StartLoc, |
| 6452 | SourceLocation EndLoc) { |
| 6453 | OMPClause *Res = nullptr; |
| 6454 | switch (Kind) { |
| 6455 | case OMPC_ordered: |
| 6456 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6457 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6458 | case OMPC_nowait: |
| 6459 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6460 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6461 | case OMPC_untied: |
| 6462 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6463 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6464 | case OMPC_mergeable: |
| 6465 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6466 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6467 | case OMPC_read: |
| 6468 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6469 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6470 | case OMPC_write: |
| 6471 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6472 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6473 | case OMPC_update: |
| 6474 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6475 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6476 | case OMPC_capture: |
| 6477 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6478 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6479 | case OMPC_seq_cst: |
| 6480 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6481 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6482 | case OMPC_threads: |
| 6483 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6484 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6485 | case OMPC_simd: |
| 6486 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6487 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6488 | case OMPC_nogroup: |
| 6489 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6490 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6491 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6492 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6493 | case OMPC_num_threads: |
| 6494 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6495 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6496 | case OMPC_collapse: |
| 6497 | case OMPC_schedule: |
| 6498 | case OMPC_private: |
| 6499 | case OMPC_firstprivate: |
| 6500 | case OMPC_lastprivate: |
| 6501 | case OMPC_shared: |
| 6502 | case OMPC_reduction: |
| 6503 | case OMPC_linear: |
| 6504 | case OMPC_aligned: |
| 6505 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6506 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6507 | case OMPC_default: |
| 6508 | case OMPC_proc_bind: |
| 6509 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6510 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6511 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6512 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6513 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6514 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6515 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6516 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6517 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6518 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6519 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6520 | case OMPC_dist_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6521 | case OMPC_unknown: |
| 6522 | llvm_unreachable("Clause is not allowed."); |
| 6523 | } |
| 6524 | return Res; |
| 6525 | } |
| 6526 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6527 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6528 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6529 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6530 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6531 | } |
| 6532 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6533 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6534 | SourceLocation EndLoc) { |
| 6535 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6536 | } |
| 6537 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6538 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6539 | SourceLocation EndLoc) { |
| 6540 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6541 | } |
| 6542 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6543 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6544 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6545 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6546 | } |
| 6547 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6548 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6549 | SourceLocation EndLoc) { |
| 6550 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6551 | } |
| 6552 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6553 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6554 | SourceLocation EndLoc) { |
| 6555 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6556 | } |
| 6557 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6558 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6559 | SourceLocation EndLoc) { |
| 6560 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6561 | } |
| 6562 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6563 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6564 | SourceLocation EndLoc) { |
| 6565 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6566 | } |
| 6567 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6568 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6569 | SourceLocation EndLoc) { |
| 6570 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6571 | } |
| 6572 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6573 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6574 | SourceLocation EndLoc) { |
| 6575 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6576 | } |
| 6577 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6578 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6579 | SourceLocation EndLoc) { |
| 6580 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6581 | } |
| 6582 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6583 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6584 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6585 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6586 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6587 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6588 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6589 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6590 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6591 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6592 | switch (Kind) { |
| 6593 | case OMPC_private: |
| 6594 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6595 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6596 | case OMPC_firstprivate: |
| 6597 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6598 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6599 | case OMPC_lastprivate: |
| 6600 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6601 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6602 | case OMPC_shared: |
| 6603 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6604 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6605 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6606 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6607 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6608 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6609 | case OMPC_linear: |
| 6610 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6611 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6612 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6613 | case OMPC_aligned: |
| 6614 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6615 | ColonLoc, EndLoc); |
| 6616 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6617 | case OMPC_copyin: |
| 6618 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6619 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6620 | case OMPC_copyprivate: |
| 6621 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6622 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6623 | case OMPC_flush: |
| 6624 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6625 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6626 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6627 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6628 | StartLoc, LParenLoc, EndLoc); |
| 6629 | break; |
| 6630 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6631 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 6632 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 6633 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6634 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6635 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6636 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6637 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6638 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6639 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6640 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6641 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6642 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6643 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6644 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6645 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6646 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6647 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6648 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6649 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6650 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6651 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6652 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6653 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6654 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6655 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6656 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6657 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6658 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6659 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6660 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6661 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6662 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6663 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6664 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6665 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6666 | llvm_unreachable("Clause is not allowed."); |
| 6667 | } |
| 6668 | return Res; |
| 6669 | } |
| 6670 | |
| 6671 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6672 | SourceLocation StartLoc, |
| 6673 | SourceLocation LParenLoc, |
| 6674 | SourceLocation EndLoc) { |
| 6675 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6676 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6677 | for (auto &RefExpr : VarList) { |
| 6678 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6679 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6680 | RefExpr->containsUnexpandedParameterPack()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6681 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6682 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6683 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6684 | continue; |
| 6685 | } |
| 6686 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6687 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Carlo Bertolli | 9e8c6c1 | 2016-01-19 16:53:55 +0000 | [diff] [blame] | 6688 | // OpenMP [3.1, C/C++] |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6689 | // A list item is a variable name. |
| 6690 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6691 | // A variable that is part of another variable (as an array or |
| 6692 | // structure element) cannot appear in a private clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6693 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr->IgnoreParens()); |
| 6694 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr->IgnoreParens()); |
| 6695 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 6696 | (getCurrentThisType().isNull() || !ME || |
| 6697 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 6698 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 6699 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6700 | << (getCurrentThisType().isNull() ? 0 : 1) |
| 6701 | << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6702 | continue; |
| 6703 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6704 | ValueDecl *D = DE ? DE->getDecl() : ME->getMemberDecl(); |
| 6705 | QualType Type = D->getType(); |
| 6706 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6707 | |
| 6708 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6709 | // A variable that appears in a private clause must not have an incomplete |
| 6710 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6711 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6712 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6713 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6714 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6715 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6716 | // in a Construct] |
| 6717 | // Variables with the predetermined data-sharing attributes may not be |
| 6718 | // listed in data-sharing attributes clauses, except for the cases |
| 6719 | // listed below. For these exceptions only, listing a predetermined |
| 6720 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6721 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6722 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6723 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6724 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6725 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6726 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6727 | continue; |
| 6728 | } |
| 6729 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6730 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6731 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6732 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6733 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6734 | << getOpenMPClauseName(OMPC_private) << Type |
| 6735 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6736 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6737 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6738 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6739 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6740 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6741 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6742 | continue; |
| 6743 | } |
| 6744 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6745 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6746 | // A variable of class type (or array thereof) that appears in a private |
| 6747 | // clause requires an accessible, unambiguous default constructor for the |
| 6748 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6749 | // Generate helper private variable and initialize it with the default |
| 6750 | // value. The address of the original variable is replaced by the address of |
| 6751 | // the new private variable in CodeGen. This new variable is not added to |
| 6752 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6753 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6754 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6755 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 6756 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6757 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6758 | if (VDPrivate->isInvalidDecl()) |
| 6759 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6760 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6761 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6762 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6763 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private); |
| 6764 | Vars.push_back(RefExpr->IgnoreParens()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6765 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6766 | } |
| 6767 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6768 | if (Vars.empty()) |
| 6769 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6770 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6771 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6772 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6773 | } |
| 6774 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6775 | namespace { |
| 6776 | class DiagsUninitializedSeveretyRAII { |
| 6777 | private: |
| 6778 | DiagnosticsEngine &Diags; |
| 6779 | SourceLocation SavedLoc; |
| 6780 | bool IsIgnored; |
| 6781 | |
| 6782 | public: |
| 6783 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6784 | bool IsIgnored) |
| 6785 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6786 | if (!IsIgnored) { |
| 6787 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6788 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6789 | } |
| 6790 | } |
| 6791 | ~DiagsUninitializedSeveretyRAII() { |
| 6792 | if (!IsIgnored) |
| 6793 | Diags.popMappings(SavedLoc); |
| 6794 | } |
| 6795 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6796 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6797 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6798 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6799 | SourceLocation StartLoc, |
| 6800 | SourceLocation LParenLoc, |
| 6801 | SourceLocation EndLoc) { |
| 6802 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6803 | SmallVector<Expr *, 8> PrivateCopies; |
| 6804 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6805 | bool IsImplicitClause = |
| 6806 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6807 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6808 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6809 | for (auto &RefExpr : VarList) { |
| 6810 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6811 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6812 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6813 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6814 | PrivateCopies.push_back(nullptr); |
| 6815 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6816 | continue; |
| 6817 | } |
| 6818 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6819 | SourceLocation ELoc = |
| 6820 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6821 | // OpenMP [2.1, C/C++] |
| 6822 | // A list item is a variable name. |
| 6823 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6824 | // A variable that is part of another variable (as an array or |
| 6825 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6826 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6827 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6828 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6829 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6830 | continue; |
| 6831 | } |
| 6832 | Decl *D = DE->getDecl(); |
| 6833 | VarDecl *VD = cast<VarDecl>(D); |
| 6834 | |
| 6835 | QualType Type = VD->getType(); |
| 6836 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6837 | // It will be analyzed later. |
| 6838 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6839 | PrivateCopies.push_back(nullptr); |
| 6840 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6841 | continue; |
| 6842 | } |
| 6843 | |
| 6844 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6845 | // A variable that appears in a private clause must not have an incomplete |
| 6846 | // type or a reference type. |
| 6847 | if (RequireCompleteType(ELoc, Type, |
| 6848 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6849 | continue; |
| 6850 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6851 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6852 | |
| 6853 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6854 | // 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] | 6855 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6856 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6857 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6858 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6859 | // If an implicit firstprivate variable found it was checked already. |
| 6860 | if (!IsImplicitClause) { |
| 6861 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6862 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6863 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6864 | // A list item that specifies a given variable may not appear in more |
| 6865 | // than one clause on the same directive, except that a variable may be |
| 6866 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6867 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6868 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6869 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6870 | << getOpenMPClauseName(DVar.CKind) |
| 6871 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6872 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6873 | continue; |
| 6874 | } |
| 6875 | |
| 6876 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6877 | // in a Construct] |
| 6878 | // Variables with the predetermined data-sharing attributes may not be |
| 6879 | // listed in data-sharing attributes clauses, except for the cases |
| 6880 | // listed below. For these exceptions only, listing a predetermined |
| 6881 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6882 | // the variable's predetermined data-sharing attributes. |
| 6883 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6884 | // in a Construct, C/C++, p.2] |
| 6885 | // Variables with const-qualified type having no mutable member may be |
| 6886 | // listed in a firstprivate clause, even if they are static data members. |
| 6887 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6888 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6889 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6890 | << getOpenMPClauseName(DVar.CKind) |
| 6891 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6892 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6893 | continue; |
| 6894 | } |
| 6895 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6896 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6897 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6898 | // A list item that is private within a parallel region must not appear |
| 6899 | // in a firstprivate clause on a worksharing construct if any of the |
| 6900 | // worksharing regions arising from the worksharing construct ever bind |
| 6901 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6902 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6903 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6904 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6905 | if (DVar.CKind != OMPC_shared && |
| 6906 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6907 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6908 | Diag(ELoc, diag::err_omp_required_access) |
| 6909 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6910 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6911 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6912 | continue; |
| 6913 | } |
| 6914 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6915 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6916 | // A list item that appears in a reduction clause of a parallel construct |
| 6917 | // must not appear in a firstprivate clause on a worksharing or task |
| 6918 | // construct if any of the worksharing or task regions arising from the |
| 6919 | // worksharing or task construct ever bind to any of the parallel regions |
| 6920 | // arising from the parallel construct. |
| 6921 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6922 | // A list item that appears in a reduction clause in worksharing |
| 6923 | // construct must not appear in a firstprivate clause in a task construct |
| 6924 | // encountered during execution of any of the worksharing regions arising |
| 6925 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6926 | if (CurrDir == OMPD_task) { |
| 6927 | DVar = |
| 6928 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6929 | [](OpenMPDirectiveKind K) -> bool { |
| 6930 | return isOpenMPParallelDirective(K) || |
| 6931 | isOpenMPWorksharingDirective(K); |
| 6932 | }, |
| 6933 | false); |
| 6934 | if (DVar.CKind == OMPC_reduction && |
| 6935 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6936 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6937 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6938 | << getOpenMPDirectiveName(DVar.DKind); |
| 6939 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6940 | continue; |
| 6941 | } |
| 6942 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6943 | |
| 6944 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6945 | // A list item that is private within a teams region must not appear in a |
| 6946 | // firstprivate clause on a distribute construct if any of the distribute |
| 6947 | // regions arising from the distribute construct ever bind to any of the |
| 6948 | // teams regions arising from the teams construct. |
| 6949 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6950 | // A list item that appears in a reduction clause of a teams construct |
| 6951 | // must not appear in a firstprivate clause on a distribute construct if |
| 6952 | // any of the distribute regions arising from the distribute construct |
| 6953 | // ever bind to any of the teams regions arising from the teams construct. |
| 6954 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6955 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6956 | // both. |
| 6957 | if (CurrDir == OMPD_distribute) { |
| 6958 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6959 | [](OpenMPDirectiveKind K) -> bool { |
| 6960 | return isOpenMPTeamsDirective(K); |
| 6961 | }, |
| 6962 | false); |
| 6963 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6964 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6965 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6966 | continue; |
| 6967 | } |
| 6968 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6969 | [](OpenMPDirectiveKind K) -> bool { |
| 6970 | return isOpenMPTeamsDirective(K); |
| 6971 | }, |
| 6972 | false); |
| 6973 | if (DVar.CKind == OMPC_reduction && |
| 6974 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6975 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6976 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6977 | continue; |
| 6978 | } |
| 6979 | DVar = DSAStack->getTopDSA(VD, false); |
| 6980 | if (DVar.CKind == OMPC_lastprivate) { |
| 6981 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6982 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6983 | continue; |
| 6984 | } |
| 6985 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6986 | } |
| 6987 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6988 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6989 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6990 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6991 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6992 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6993 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6994 | bool IsDecl = |
| 6995 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6996 | Diag(VD->getLocation(), |
| 6997 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6998 | << VD; |
| 6999 | continue; |
| 7000 | } |
| 7001 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7002 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7003 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7004 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7005 | // Generate helper private variable and initialize it with the value of the |
| 7006 | // original variable. The address of the original variable is replaced by |
| 7007 | // the address of the new private variable in the CodeGen. This new variable |
| 7008 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7009 | // original variable for proper diagnostics and variable capturing. |
| 7010 | Expr *VDInitRefExpr = nullptr; |
| 7011 | // For arrays generate initializer for single element and replace it by the |
| 7012 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7013 | if (Type->isArrayType()) { |
| 7014 | auto VDInit = |
| 7015 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 7016 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7017 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7018 | ElemType = ElemType.getUnqualifiedType(); |
| 7019 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 7020 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7021 | InitializedEntity Entity = |
| 7022 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7023 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7024 | |
| 7025 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7026 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7027 | if (Result.isInvalid()) |
| 7028 | VDPrivate->setInvalidDecl(); |
| 7029 | else |
| 7030 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7031 | // Remove temp variable declaration. |
| 7032 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7033 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7034 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7035 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7036 | VDInitRefExpr = |
| 7037 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7038 | AddInitializerToDecl(VDPrivate, |
| 7039 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7040 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7041 | } |
| 7042 | if (VDPrivate->isInvalidDecl()) { |
| 7043 | if (IsImplicitClause) { |
| 7044 | Diag(DE->getExprLoc(), |
| 7045 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7046 | } |
| 7047 | continue; |
| 7048 | } |
| 7049 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7050 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 7051 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7052 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 7053 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7054 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7055 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7056 | } |
| 7057 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7058 | if (Vars.empty()) |
| 7059 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7060 | |
| 7061 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7062 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7063 | } |
| 7064 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7065 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7066 | SourceLocation StartLoc, |
| 7067 | SourceLocation LParenLoc, |
| 7068 | SourceLocation EndLoc) { |
| 7069 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7070 | SmallVector<Expr *, 8> SrcExprs; |
| 7071 | SmallVector<Expr *, 8> DstExprs; |
| 7072 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7073 | for (auto &RefExpr : VarList) { |
| 7074 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7075 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7076 | // It will be analyzed later. |
| 7077 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7078 | SrcExprs.push_back(nullptr); |
| 7079 | DstExprs.push_back(nullptr); |
| 7080 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7081 | continue; |
| 7082 | } |
| 7083 | |
| 7084 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7085 | // OpenMP [2.1, C/C++] |
| 7086 | // A list item is a variable name. |
| 7087 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 7088 | // A variable that is part of another variable (as an array or structure |
| 7089 | // element) cannot appear in a lastprivate clause. |
| 7090 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7091 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7092 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7093 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7094 | continue; |
| 7095 | } |
| 7096 | Decl *D = DE->getDecl(); |
| 7097 | VarDecl *VD = cast<VarDecl>(D); |
| 7098 | |
| 7099 | QualType Type = VD->getType(); |
| 7100 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7101 | // It will be analyzed later. |
| 7102 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7103 | SrcExprs.push_back(nullptr); |
| 7104 | DstExprs.push_back(nullptr); |
| 7105 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7106 | continue; |
| 7107 | } |
| 7108 | |
| 7109 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7110 | // A variable that appears in a lastprivate clause must not have an |
| 7111 | // incomplete type or a reference type. |
| 7112 | if (RequireCompleteType(ELoc, Type, |
| 7113 | diag::err_omp_lastprivate_incomplete_type)) { |
| 7114 | continue; |
| 7115 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7116 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7117 | |
| 7118 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7119 | // in a Construct] |
| 7120 | // Variables with the predetermined data-sharing attributes may not be |
| 7121 | // listed in data-sharing attributes clauses, except for the cases |
| 7122 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7123 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7124 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7125 | DVar.CKind != OMPC_firstprivate && |
| 7126 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7127 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7128 | << getOpenMPClauseName(DVar.CKind) |
| 7129 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7130 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7131 | continue; |
| 7132 | } |
| 7133 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7134 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7135 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7136 | // A list item that is private within a parallel region, or that appears in |
| 7137 | // the reduction clause of a parallel construct, must not appear in a |
| 7138 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7139 | // worksharing regions ever binds to any of the corresponding parallel |
| 7140 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7141 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7142 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7143 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7144 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7145 | if (DVar.CKind != OMPC_shared) { |
| 7146 | Diag(ELoc, diag::err_omp_required_access) |
| 7147 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7148 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7149 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7150 | continue; |
| 7151 | } |
| 7152 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7153 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7154 | // A variable of class type (or array thereof) that appears in a |
| 7155 | // lastprivate clause requires an accessible, unambiguous default |
| 7156 | // constructor for the class type, unless the list item is also specified |
| 7157 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7158 | // A variable of class type (or array thereof) that appears in a |
| 7159 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7160 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7161 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7162 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7163 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 7164 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7165 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 7166 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7167 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7168 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 7169 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7170 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7171 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7172 | // For arrays generate assignment operation for single element and replace |
| 7173 | // it by the original array element in CodeGen. |
| 7174 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7175 | PseudoDstExpr, PseudoSrcExpr); |
| 7176 | if (AssignmentOp.isInvalid()) |
| 7177 | continue; |
| 7178 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7179 | /*DiscardedValue=*/true); |
| 7180 | if (AssignmentOp.isInvalid()) |
| 7181 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7182 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7183 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7184 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7185 | // both. |
| 7186 | if (CurrDir == OMPD_distribute) { |
| 7187 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 7188 | if (DVar.CKind == OMPC_firstprivate) { |
| 7189 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7190 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7191 | continue; |
| 7192 | } |
| 7193 | } |
| 7194 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7195 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7196 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7197 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7198 | SrcExprs.push_back(PseudoSrcExpr); |
| 7199 | DstExprs.push_back(PseudoDstExpr); |
| 7200 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
| 7203 | if (Vars.empty()) |
| 7204 | return nullptr; |
| 7205 | |
| 7206 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7207 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7208 | } |
| 7209 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7210 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7211 | SourceLocation StartLoc, |
| 7212 | SourceLocation LParenLoc, |
| 7213 | SourceLocation EndLoc) { |
| 7214 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7215 | for (auto &RefExpr : VarList) { |
| 7216 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7217 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7218 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7219 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7220 | continue; |
| 7221 | } |
| 7222 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7223 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7224 | // OpenMP [2.1, C/C++] |
| 7225 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7226 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7227 | // A variable that is part of another variable (as an array or structure |
| 7228 | // element) cannot appear in a shared unless it is a static data member |
| 7229 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7230 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7231 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7232 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7233 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7234 | continue; |
| 7235 | } |
| 7236 | Decl *D = DE->getDecl(); |
| 7237 | VarDecl *VD = cast<VarDecl>(D); |
| 7238 | |
| 7239 | QualType Type = VD->getType(); |
| 7240 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7241 | // It will be analyzed later. |
| 7242 | Vars.push_back(DE); |
| 7243 | continue; |
| 7244 | } |
| 7245 | |
| 7246 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7247 | // in a Construct] |
| 7248 | // Variables with the predetermined data-sharing attributes may not be |
| 7249 | // listed in data-sharing attributes clauses, except for the cases |
| 7250 | // listed below. For these exceptions only, listing a predetermined |
| 7251 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7252 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7253 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7254 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7255 | DVar.RefExpr) { |
| 7256 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7257 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7258 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7259 | continue; |
| 7260 | } |
| 7261 | |
| 7262 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7263 | Vars.push_back(DE); |
| 7264 | } |
| 7265 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7266 | if (Vars.empty()) |
| 7267 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7268 | |
| 7269 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7270 | } |
| 7271 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7272 | namespace { |
| 7273 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7274 | DSAStackTy *Stack; |
| 7275 | |
| 7276 | public: |
| 7277 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7278 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7279 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7280 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7281 | return false; |
| 7282 | if (DVar.CKind != OMPC_unknown) |
| 7283 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7284 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7285 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7286 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7287 | return true; |
| 7288 | return false; |
| 7289 | } |
| 7290 | return false; |
| 7291 | } |
| 7292 | bool VisitStmt(Stmt *S) { |
| 7293 | for (auto Child : S->children()) { |
| 7294 | if (Child && Visit(Child)) |
| 7295 | return true; |
| 7296 | } |
| 7297 | return false; |
| 7298 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7299 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7300 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7301 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7302 | |
| 7303 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7304 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7305 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7306 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7307 | const DeclarationNameInfo &ReductionId) { |
| 7308 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7309 | // supported. |
| 7310 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7311 | "No support for scoped reduction identifiers yet."); |
| 7312 | |
| 7313 | auto DN = ReductionId.getName(); |
| 7314 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7315 | BinaryOperatorKind BOK = BO_Comma; |
| 7316 | |
| 7317 | // OpenMP [2.14.3.6, reduction clause] |
| 7318 | // C |
| 7319 | // reduction-identifier is either an identifier or one of the following |
| 7320 | // operators: +, -, *, &, |, ^, && and || |
| 7321 | // C++ |
| 7322 | // reduction-identifier is either an id-expression or one of the following |
| 7323 | // operators: +, -, *, &, |, ^, && and || |
| 7324 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7325 | switch (OOK) { |
| 7326 | case OO_Plus: |
| 7327 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7328 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7329 | break; |
| 7330 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7331 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7332 | break; |
| 7333 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7334 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7335 | break; |
| 7336 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7337 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7338 | break; |
| 7339 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7340 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7341 | break; |
| 7342 | case OO_AmpAmp: |
| 7343 | BOK = BO_LAnd; |
| 7344 | break; |
| 7345 | case OO_PipePipe: |
| 7346 | BOK = BO_LOr; |
| 7347 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7348 | case OO_New: |
| 7349 | case OO_Delete: |
| 7350 | case OO_Array_New: |
| 7351 | case OO_Array_Delete: |
| 7352 | case OO_Slash: |
| 7353 | case OO_Percent: |
| 7354 | case OO_Tilde: |
| 7355 | case OO_Exclaim: |
| 7356 | case OO_Equal: |
| 7357 | case OO_Less: |
| 7358 | case OO_Greater: |
| 7359 | case OO_LessEqual: |
| 7360 | case OO_GreaterEqual: |
| 7361 | case OO_PlusEqual: |
| 7362 | case OO_MinusEqual: |
| 7363 | case OO_StarEqual: |
| 7364 | case OO_SlashEqual: |
| 7365 | case OO_PercentEqual: |
| 7366 | case OO_CaretEqual: |
| 7367 | case OO_AmpEqual: |
| 7368 | case OO_PipeEqual: |
| 7369 | case OO_LessLess: |
| 7370 | case OO_GreaterGreater: |
| 7371 | case OO_LessLessEqual: |
| 7372 | case OO_GreaterGreaterEqual: |
| 7373 | case OO_EqualEqual: |
| 7374 | case OO_ExclaimEqual: |
| 7375 | case OO_PlusPlus: |
| 7376 | case OO_MinusMinus: |
| 7377 | case OO_Comma: |
| 7378 | case OO_ArrowStar: |
| 7379 | case OO_Arrow: |
| 7380 | case OO_Call: |
| 7381 | case OO_Subscript: |
| 7382 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7383 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7384 | case NUM_OVERLOADED_OPERATORS: |
| 7385 | llvm_unreachable("Unexpected reduction identifier"); |
| 7386 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7387 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7388 | if (II->isStr("max")) |
| 7389 | BOK = BO_GT; |
| 7390 | else if (II->isStr("min")) |
| 7391 | BOK = BO_LT; |
| 7392 | } |
| 7393 | break; |
| 7394 | } |
| 7395 | SourceRange ReductionIdRange; |
| 7396 | if (ReductionIdScopeSpec.isValid()) { |
| 7397 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7398 | } |
| 7399 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7400 | if (BOK == BO_Comma) { |
| 7401 | // Not allowed reduction identifier is found. |
| 7402 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7403 | << ReductionIdRange; |
| 7404 | return nullptr; |
| 7405 | } |
| 7406 | |
| 7407 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7408 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7409 | SmallVector<Expr *, 8> LHSs; |
| 7410 | SmallVector<Expr *, 8> RHSs; |
| 7411 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7412 | for (auto RefExpr : VarList) { |
| 7413 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7414 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7415 | // It will be analyzed later. |
| 7416 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7417 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7418 | LHSs.push_back(nullptr); |
| 7419 | RHSs.push_back(nullptr); |
| 7420 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7421 | continue; |
| 7422 | } |
| 7423 | |
| 7424 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7425 | RefExpr->isInstantiationDependent() || |
| 7426 | RefExpr->containsUnexpandedParameterPack()) { |
| 7427 | // It will be analyzed later. |
| 7428 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7429 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7430 | LHSs.push_back(nullptr); |
| 7431 | RHSs.push_back(nullptr); |
| 7432 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7433 | continue; |
| 7434 | } |
| 7435 | |
| 7436 | auto ELoc = RefExpr->getExprLoc(); |
| 7437 | auto ERange = RefExpr->getSourceRange(); |
| 7438 | // OpenMP [2.1, C/C++] |
| 7439 | // A list item is a variable or array section, subject to the restrictions |
| 7440 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7441 | // describing clauses and directives for which a list appears. |
| 7442 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7443 | // A variable that is part of another variable (as an array or |
| 7444 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7445 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7446 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7447 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7448 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7449 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 7450 | << 0 << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7451 | continue; |
| 7452 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7453 | QualType Type; |
| 7454 | VarDecl *VD = nullptr; |
| 7455 | if (DE) { |
| 7456 | auto D = DE->getDecl(); |
| 7457 | VD = cast<VarDecl>(D); |
| 7458 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7459 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7460 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7461 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7462 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7463 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7464 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7465 | if (DE) |
| 7466 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7467 | if (!VD) { |
| 7468 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7469 | << 0 << Base->getSourceRange(); |
| 7470 | continue; |
| 7471 | } |
| 7472 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7473 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7474 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7475 | Type = ATy->getElementType(); |
| 7476 | else |
| 7477 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7478 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7479 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7480 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7481 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7482 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7483 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7484 | if (DE) |
| 7485 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7486 | if (!VD) { |
| 7487 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7488 | << 1 << Base->getSourceRange(); |
| 7489 | continue; |
| 7490 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7493 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7494 | // A variable that appears in a private clause must not have an incomplete |
| 7495 | // type or a reference type. |
| 7496 | if (RequireCompleteType(ELoc, Type, |
| 7497 | diag::err_omp_reduction_incomplete_type)) |
| 7498 | continue; |
| 7499 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7500 | // Arrays may not appear in a reduction clause. |
| 7501 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7502 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7503 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7504 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7505 | VarDecl::DeclarationOnly; |
| 7506 | Diag(VD->getLocation(), |
| 7507 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7508 | << VD; |
| 7509 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7510 | continue; |
| 7511 | } |
| 7512 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7513 | // A list item that appears in a reduction clause must not be |
| 7514 | // const-qualified. |
| 7515 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7516 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7517 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7518 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7519 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7520 | VarDecl::DeclarationOnly; |
| 7521 | Diag(VD->getLocation(), |
| 7522 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7523 | << VD; |
| 7524 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7525 | continue; |
| 7526 | } |
| 7527 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7528 | // If a list-item is a reference type then it must bind to the same object |
| 7529 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7530 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7531 | VarDecl *VDDef = VD->getDefinition(); |
| 7532 | if (Type->isReferenceType() && VDDef) { |
| 7533 | DSARefChecker Check(DSAStack); |
| 7534 | if (Check.Visit(VDDef->getInit())) { |
| 7535 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7536 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7537 | continue; |
| 7538 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7539 | } |
| 7540 | } |
| 7541 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7542 | // The type of a list item that appears in a reduction clause must be valid |
| 7543 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7544 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7545 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7546 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7547 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7548 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7549 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7550 | !(Type->isScalarType() || |
| 7551 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7552 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7553 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7554 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7555 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7556 | VarDecl::DeclarationOnly; |
| 7557 | Diag(VD->getLocation(), |
| 7558 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7559 | << VD; |
| 7560 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7561 | continue; |
| 7562 | } |
| 7563 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7564 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7565 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7566 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7567 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7568 | VarDecl::DeclarationOnly; |
| 7569 | Diag(VD->getLocation(), |
| 7570 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7571 | << VD; |
| 7572 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7573 | continue; |
| 7574 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7575 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7576 | // in a Construct] |
| 7577 | // Variables with the predetermined data-sharing attributes may not be |
| 7578 | // listed in data-sharing attributes clauses, except for the cases |
| 7579 | // listed below. For these exceptions only, listing a predetermined |
| 7580 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7581 | // the variable's predetermined data-sharing attributes. |
| 7582 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7583 | // Any number of reduction clauses can be specified on the directive, |
| 7584 | // but a list item can appear only once in the reduction clauses for that |
| 7585 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7586 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7587 | DVar = DSAStack->getTopDSA(VD, false); |
| 7588 | if (DVar.CKind == OMPC_reduction) { |
| 7589 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7590 | << getOpenMPClauseName(OMPC_reduction); |
| 7591 | if (DVar.RefExpr) { |
| 7592 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7593 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7594 | } else if (DVar.CKind != OMPC_unknown) { |
| 7595 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7596 | << getOpenMPClauseName(DVar.CKind) |
| 7597 | << getOpenMPClauseName(OMPC_reduction); |
| 7598 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7599 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7600 | } |
| 7601 | |
| 7602 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7603 | // A list item that appears in a reduction clause of a worksharing |
| 7604 | // construct must be shared in the parallel regions to which any of the |
| 7605 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7606 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7607 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7608 | !isOpenMPParallelDirective(CurrDir)) { |
| 7609 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7610 | if (DVar.CKind != OMPC_shared) { |
| 7611 | Diag(ELoc, diag::err_omp_required_access) |
| 7612 | << getOpenMPClauseName(OMPC_reduction) |
| 7613 | << getOpenMPClauseName(OMPC_shared); |
| 7614 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7615 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7616 | } |
| 7617 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7618 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7619 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7620 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7621 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7622 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7623 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7624 | auto PrivateTy = Type; |
| 7625 | if (OASE) { |
| 7626 | // For array sections only: |
| 7627 | // Create pseudo array type for private copy. The size for this array will |
| 7628 | // be generated during codegen. |
| 7629 | // For array subscripts or single variables Private Ty is the same as Type |
| 7630 | // (type of the variable or single array element). |
| 7631 | PrivateTy = Context.getVariableArrayType( |
| 7632 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7633 | Context.getSizeType(), VK_RValue), |
| 7634 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7635 | } |
| 7636 | // Private copy. |
| 7637 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7638 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7639 | // Add initializer for private variable. |
| 7640 | Expr *Init = nullptr; |
| 7641 | switch (BOK) { |
| 7642 | case BO_Add: |
| 7643 | case BO_Xor: |
| 7644 | case BO_Or: |
| 7645 | case BO_LOr: |
| 7646 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7647 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7648 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7649 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7650 | break; |
| 7651 | case BO_Mul: |
| 7652 | case BO_LAnd: |
| 7653 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7654 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7655 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7656 | } |
| 7657 | break; |
| 7658 | case BO_And: { |
| 7659 | // '&' reduction op - initializer is '~0'. |
| 7660 | QualType OrigType = Type; |
| 7661 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7662 | Type = ComplexTy->getElementType(); |
| 7663 | } |
| 7664 | if (Type->isRealFloatingType()) { |
| 7665 | llvm::APFloat InitValue = |
| 7666 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7667 | /*isIEEE=*/true); |
| 7668 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7669 | Type, ELoc); |
| 7670 | } else if (Type->isScalarType()) { |
| 7671 | auto Size = Context.getTypeSize(Type); |
| 7672 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7673 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7674 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7675 | } |
| 7676 | if (Init && OrigType->isAnyComplexType()) { |
| 7677 | // Init = 0xFFFF + 0xFFFFi; |
| 7678 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7679 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7680 | } |
| 7681 | Type = OrigType; |
| 7682 | break; |
| 7683 | } |
| 7684 | case BO_LT: |
| 7685 | case BO_GT: { |
| 7686 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7687 | // the reduction list item type'. |
| 7688 | // 'max' reduction op - initializer is 'Least representable number in |
| 7689 | // the reduction list item type'. |
| 7690 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7691 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7692 | auto Size = Context.getTypeSize(Type); |
| 7693 | QualType IntTy = |
| 7694 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7695 | llvm::APInt InitValue = |
| 7696 | (BOK != BO_LT) |
| 7697 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7698 | : llvm::APInt::getMinValue(Size) |
| 7699 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7700 | : llvm::APInt::getMaxValue(Size); |
| 7701 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7702 | if (Type->isPointerType()) { |
| 7703 | // Cast to pointer type. |
| 7704 | auto CastExpr = BuildCStyleCastExpr( |
| 7705 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7706 | SourceLocation(), Init); |
| 7707 | if (CastExpr.isInvalid()) |
| 7708 | continue; |
| 7709 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7710 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7711 | } else if (Type->isRealFloatingType()) { |
| 7712 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7713 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7714 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7715 | Type, ELoc); |
| 7716 | } |
| 7717 | break; |
| 7718 | } |
| 7719 | case BO_PtrMemD: |
| 7720 | case BO_PtrMemI: |
| 7721 | case BO_MulAssign: |
| 7722 | case BO_Div: |
| 7723 | case BO_Rem: |
| 7724 | case BO_Sub: |
| 7725 | case BO_Shl: |
| 7726 | case BO_Shr: |
| 7727 | case BO_LE: |
| 7728 | case BO_GE: |
| 7729 | case BO_EQ: |
| 7730 | case BO_NE: |
| 7731 | case BO_AndAssign: |
| 7732 | case BO_XorAssign: |
| 7733 | case BO_OrAssign: |
| 7734 | case BO_Assign: |
| 7735 | case BO_AddAssign: |
| 7736 | case BO_SubAssign: |
| 7737 | case BO_DivAssign: |
| 7738 | case BO_RemAssign: |
| 7739 | case BO_ShlAssign: |
| 7740 | case BO_ShrAssign: |
| 7741 | case BO_Comma: |
| 7742 | llvm_unreachable("Unexpected reduction operation"); |
| 7743 | } |
| 7744 | if (Init) { |
| 7745 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7746 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7747 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7748 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7749 | if (!RHSVD->hasInit()) { |
| 7750 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7751 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7752 | if (VD) { |
| 7753 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7754 | VarDecl::DeclarationOnly; |
| 7755 | Diag(VD->getLocation(), |
| 7756 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7757 | << VD; |
| 7758 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7759 | continue; |
| 7760 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7761 | // Store initializer for single element in private copy. Will be used during |
| 7762 | // codegen. |
| 7763 | PrivateVD->setInit(RHSVD->getInit()); |
| 7764 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7765 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7766 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7767 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7768 | ExprResult ReductionOp = |
| 7769 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7770 | LHSDRE, RHSDRE); |
| 7771 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7772 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7773 | ReductionOp = |
| 7774 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7775 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7776 | } else { |
| 7777 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7778 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7779 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7780 | ReductionOp = |
| 7781 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7782 | BO_Assign, LHSDRE, ConditionalOp); |
| 7783 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7784 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7785 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7786 | if (ReductionOp.isInvalid()) |
| 7787 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7788 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7789 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7790 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7791 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7792 | LHSs.push_back(LHSDRE); |
| 7793 | RHSs.push_back(RHSDRE); |
| 7794 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7795 | } |
| 7796 | |
| 7797 | if (Vars.empty()) |
| 7798 | return nullptr; |
| 7799 | |
| 7800 | return OMPReductionClause::Create( |
| 7801 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7802 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7803 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7804 | } |
| 7805 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7806 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7807 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7808 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7809 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7810 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7811 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7812 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7813 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7814 | LinKind == OMPC_LINEAR_unknown) { |
| 7815 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7816 | LinKind = OMPC_LINEAR_val; |
| 7817 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7818 | for (auto &RefExpr : VarList) { |
| 7819 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7820 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7821 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7822 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7823 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7824 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7825 | continue; |
| 7826 | } |
| 7827 | |
| 7828 | // OpenMP [2.14.3.7, linear clause] |
| 7829 | // A list item that appears in a linear clause is subject to the private |
| 7830 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7831 | // noted. In addition, the value of the new list item on each iteration |
| 7832 | // of the associated loop(s) corresponds to the value of the original |
| 7833 | // list item before entering the construct plus the logical number of |
| 7834 | // the iteration times linear-step. |
| 7835 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7836 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7837 | // OpenMP [2.1, C/C++] |
| 7838 | // A list item is a variable name. |
| 7839 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7840 | // A variable that is part of another variable (as an array or |
| 7841 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7842 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7843 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7844 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7845 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7846 | continue; |
| 7847 | } |
| 7848 | |
| 7849 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7850 | |
| 7851 | // OpenMP [2.14.3.7, linear clause] |
| 7852 | // A list-item cannot appear in more than one linear clause. |
| 7853 | // A list-item that appears in a linear clause cannot appear in any |
| 7854 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7855 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7856 | if (DVar.RefExpr) { |
| 7857 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7858 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7859 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7860 | continue; |
| 7861 | } |
| 7862 | |
| 7863 | QualType QType = VD->getType(); |
| 7864 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7865 | // It will be analyzed later. |
| 7866 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7867 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7868 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7869 | continue; |
| 7870 | } |
| 7871 | |
| 7872 | // A variable must not have an incomplete type or a reference type. |
| 7873 | if (RequireCompleteType(ELoc, QType, |
| 7874 | diag::err_omp_linear_incomplete_type)) { |
| 7875 | continue; |
| 7876 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7877 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7878 | !QType->isReferenceType()) { |
| 7879 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7880 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7881 | continue; |
| 7882 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7883 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7884 | |
| 7885 | // A list item must not be const-qualified. |
| 7886 | if (QType.isConstant(Context)) { |
| 7887 | Diag(ELoc, diag::err_omp_const_variable) |
| 7888 | << getOpenMPClauseName(OMPC_linear); |
| 7889 | bool IsDecl = |
| 7890 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7891 | Diag(VD->getLocation(), |
| 7892 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7893 | << VD; |
| 7894 | continue; |
| 7895 | } |
| 7896 | |
| 7897 | // A list item must be of integral or pointer type. |
| 7898 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7899 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7900 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7901 | !Ty->isPointerType())) { |
| 7902 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7903 | bool IsDecl = |
| 7904 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7905 | Diag(VD->getLocation(), |
| 7906 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7907 | << VD; |
| 7908 | continue; |
| 7909 | } |
| 7910 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7911 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7912 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7913 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7914 | auto *PrivateRef = buildDeclRefExpr( |
| 7915 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7916 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7917 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7918 | Expr *InitExpr; |
| 7919 | if (LinKind == OMPC_LINEAR_uval) |
| 7920 | InitExpr = VD->getInit(); |
| 7921 | else |
| 7922 | InitExpr = DE; |
| 7923 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7924 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7925 | auto InitRef = buildDeclRefExpr( |
| 7926 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7927 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7928 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7929 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7930 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7931 | } |
| 7932 | |
| 7933 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7934 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7935 | |
| 7936 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7937 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7938 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7939 | !Step->isInstantiationDependent() && |
| 7940 | !Step->containsUnexpandedParameterPack()) { |
| 7941 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7942 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7943 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7944 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7945 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7946 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7947 | // Build var to save the step value. |
| 7948 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7949 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7950 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7951 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7952 | ExprResult CalcStep = |
| 7953 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7954 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7955 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7956 | // Warn about zero linear step (it would be probably better specified as |
| 7957 | // making corresponding variables 'const'). |
| 7958 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7959 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7960 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7961 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7962 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7963 | if (!IsConstant && CalcStep.isUsable()) { |
| 7964 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7965 | // (This is not used if the number of iterations may be kfold-ed). |
| 7966 | CalcStepExpr = CalcStep.get(); |
| 7967 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7968 | } |
| 7969 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7970 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7971 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7972 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7973 | } |
| 7974 | |
| 7975 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7976 | Expr *NumIterations, Sema &SemaRef, |
| 7977 | Scope *S) { |
| 7978 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7979 | SmallVector<Expr *, 8> Updates; |
| 7980 | SmallVector<Expr *, 8> Finals; |
| 7981 | Expr *Step = Clause.getStep(); |
| 7982 | Expr *CalcStep = Clause.getCalcStep(); |
| 7983 | // OpenMP [2.14.3.7, linear clause] |
| 7984 | // If linear-step is not specified it is assumed to be 1. |
| 7985 | if (Step == nullptr) |
| 7986 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7987 | else if (CalcStep) |
| 7988 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7989 | bool HasErrors = false; |
| 7990 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7991 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7992 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7993 | for (auto &RefExpr : Clause.varlists()) { |
| 7994 | Expr *InitExpr = *CurInit; |
| 7995 | |
| 7996 | // Build privatized reference to the current linear var. |
| 7997 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7998 | Expr *CapturedRef; |
| 7999 | if (LinKind == OMPC_LINEAR_uval) |
| 8000 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8001 | else |
| 8002 | CapturedRef = |
| 8003 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8004 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8005 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8006 | |
| 8007 | // Build update: Var = InitExpr + IV * Step |
| 8008 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8009 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8010 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8011 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8012 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8013 | |
| 8014 | // Build final: Var = InitExpr + NumIterations * Step |
| 8015 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8016 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8017 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8018 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8019 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8020 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8021 | Updates.push_back(nullptr); |
| 8022 | Finals.push_back(nullptr); |
| 8023 | HasErrors = true; |
| 8024 | } else { |
| 8025 | Updates.push_back(Update.get()); |
| 8026 | Finals.push_back(Final.get()); |
| 8027 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8028 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8029 | } |
| 8030 | Clause.setUpdates(Updates); |
| 8031 | Clause.setFinals(Finals); |
| 8032 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8033 | } |
| 8034 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8035 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8036 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8037 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8038 | |
| 8039 | SmallVector<Expr *, 8> Vars; |
| 8040 | for (auto &RefExpr : VarList) { |
| 8041 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8042 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8043 | // It will be analyzed later. |
| 8044 | Vars.push_back(RefExpr); |
| 8045 | continue; |
| 8046 | } |
| 8047 | |
| 8048 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8049 | // OpenMP [2.1, C/C++] |
| 8050 | // A list item is a variable name. |
| 8051 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8052 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8053 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8054 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8055 | continue; |
| 8056 | } |
| 8057 | |
| 8058 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8059 | |
| 8060 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8061 | // The type of list items appearing in the aligned clause must be |
| 8062 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8063 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8064 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8065 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8066 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8067 | !Ty->isPointerType())) { |
| 8068 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8069 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8070 | bool IsDecl = |
| 8071 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8072 | Diag(VD->getLocation(), |
| 8073 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8074 | << VD; |
| 8075 | continue; |
| 8076 | } |
| 8077 | |
| 8078 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8079 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8080 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8081 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8082 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8083 | << getOpenMPClauseName(OMPC_aligned); |
| 8084 | continue; |
| 8085 | } |
| 8086 | |
| 8087 | Vars.push_back(DE); |
| 8088 | } |
| 8089 | |
| 8090 | // OpenMP [2.8.1, simd construct, Description] |
| 8091 | // The parameter of the aligned clause, alignment, must be a constant |
| 8092 | // positive integer expression. |
| 8093 | // If no optional parameter is specified, implementation-defined default |
| 8094 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8095 | if (Alignment != nullptr) { |
| 8096 | ExprResult AlignResult = |
| 8097 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8098 | if (AlignResult.isInvalid()) |
| 8099 | return nullptr; |
| 8100 | Alignment = AlignResult.get(); |
| 8101 | } |
| 8102 | if (Vars.empty()) |
| 8103 | return nullptr; |
| 8104 | |
| 8105 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8106 | EndLoc, Vars, Alignment); |
| 8107 | } |
| 8108 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8109 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8110 | SourceLocation StartLoc, |
| 8111 | SourceLocation LParenLoc, |
| 8112 | SourceLocation EndLoc) { |
| 8113 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8114 | SmallVector<Expr *, 8> SrcExprs; |
| 8115 | SmallVector<Expr *, 8> DstExprs; |
| 8116 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8117 | for (auto &RefExpr : VarList) { |
| 8118 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8119 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8120 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8121 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8122 | SrcExprs.push_back(nullptr); |
| 8123 | DstExprs.push_back(nullptr); |
| 8124 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8125 | continue; |
| 8126 | } |
| 8127 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8128 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8129 | // OpenMP [2.1, C/C++] |
| 8130 | // A list item is a variable name. |
| 8131 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8132 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8133 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8134 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8135 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8136 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8137 | continue; |
| 8138 | } |
| 8139 | |
| 8140 | Decl *D = DE->getDecl(); |
| 8141 | VarDecl *VD = cast<VarDecl>(D); |
| 8142 | |
| 8143 | QualType Type = VD->getType(); |
| 8144 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8145 | // It will be analyzed later. |
| 8146 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8147 | SrcExprs.push_back(nullptr); |
| 8148 | DstExprs.push_back(nullptr); |
| 8149 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8150 | continue; |
| 8151 | } |
| 8152 | |
| 8153 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8154 | // A list item that appears in a copyin clause must be threadprivate. |
| 8155 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8156 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8157 | << getOpenMPClauseName(OMPC_copyin) |
| 8158 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8159 | continue; |
| 8160 | } |
| 8161 | |
| 8162 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8163 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8164 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8165 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8166 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8167 | auto *SrcVD = |
| 8168 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8169 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8170 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8171 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8172 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8173 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8174 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8175 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8176 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8177 | // For arrays generate assignment operation for single element and replace |
| 8178 | // it by the original array element in CodeGen. |
| 8179 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8180 | PseudoDstExpr, PseudoSrcExpr); |
| 8181 | if (AssignmentOp.isInvalid()) |
| 8182 | continue; |
| 8183 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8184 | /*DiscardedValue=*/true); |
| 8185 | if (AssignmentOp.isInvalid()) |
| 8186 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8187 | |
| 8188 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8189 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8190 | SrcExprs.push_back(PseudoSrcExpr); |
| 8191 | DstExprs.push_back(PseudoDstExpr); |
| 8192 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8193 | } |
| 8194 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8195 | if (Vars.empty()) |
| 8196 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8197 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8198 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8199 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8200 | } |
| 8201 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8202 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8203 | SourceLocation StartLoc, |
| 8204 | SourceLocation LParenLoc, |
| 8205 | SourceLocation EndLoc) { |
| 8206 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8207 | SmallVector<Expr *, 8> SrcExprs; |
| 8208 | SmallVector<Expr *, 8> DstExprs; |
| 8209 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8210 | for (auto &RefExpr : VarList) { |
| 8211 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8212 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8213 | // It will be analyzed later. |
| 8214 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8215 | SrcExprs.push_back(nullptr); |
| 8216 | DstExprs.push_back(nullptr); |
| 8217 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8218 | continue; |
| 8219 | } |
| 8220 | |
| 8221 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8222 | // OpenMP [2.1, C/C++] |
| 8223 | // A list item is a variable name. |
| 8224 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8225 | // A list item that appears in a copyin clause must be threadprivate. |
| 8226 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8227 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8228 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8229 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8230 | continue; |
| 8231 | } |
| 8232 | |
| 8233 | Decl *D = DE->getDecl(); |
| 8234 | VarDecl *VD = cast<VarDecl>(D); |
| 8235 | |
| 8236 | QualType Type = VD->getType(); |
| 8237 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8238 | // It will be analyzed later. |
| 8239 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8240 | SrcExprs.push_back(nullptr); |
| 8241 | DstExprs.push_back(nullptr); |
| 8242 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8243 | continue; |
| 8244 | } |
| 8245 | |
| 8246 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8247 | // A list item that appears in a copyprivate clause may not appear in a |
| 8248 | // private or firstprivate clause on the single construct. |
| 8249 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8250 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8251 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8252 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8253 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8254 | << getOpenMPClauseName(DVar.CKind) |
| 8255 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8256 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8257 | continue; |
| 8258 | } |
| 8259 | |
| 8260 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8261 | // All list items that appear in a copyprivate clause must be either |
| 8262 | // threadprivate or private in the enclosing context. |
| 8263 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8264 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8265 | if (DVar.CKind == OMPC_shared) { |
| 8266 | Diag(ELoc, diag::err_omp_required_access) |
| 8267 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8268 | << "threadprivate or private in the enclosing context"; |
| 8269 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8270 | continue; |
| 8271 | } |
| 8272 | } |
| 8273 | } |
| 8274 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8275 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8276 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8277 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8278 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8279 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8280 | bool IsDecl = |
| 8281 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8282 | Diag(VD->getLocation(), |
| 8283 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8284 | << VD; |
| 8285 | continue; |
| 8286 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8287 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8288 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8289 | // A variable of class type (or array thereof) that appears in a |
| 8290 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8291 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8292 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8293 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8294 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8295 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8296 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8297 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8298 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8299 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8300 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8301 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8302 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8303 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8304 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8305 | PseudoDstExpr, PseudoSrcExpr); |
| 8306 | if (AssignmentOp.isInvalid()) |
| 8307 | continue; |
| 8308 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8309 | /*DiscardedValue=*/true); |
| 8310 | if (AssignmentOp.isInvalid()) |
| 8311 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8312 | |
| 8313 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8314 | // implicitly private. |
| 8315 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8316 | SrcExprs.push_back(PseudoSrcExpr); |
| 8317 | DstExprs.push_back(PseudoDstExpr); |
| 8318 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8319 | } |
| 8320 | |
| 8321 | if (Vars.empty()) |
| 8322 | return nullptr; |
| 8323 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8324 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8325 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8326 | } |
| 8327 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8328 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8329 | SourceLocation StartLoc, |
| 8330 | SourceLocation LParenLoc, |
| 8331 | SourceLocation EndLoc) { |
| 8332 | if (VarList.empty()) |
| 8333 | return nullptr; |
| 8334 | |
| 8335 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8336 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8337 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8338 | OMPClause * |
| 8339 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8340 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8341 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8342 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8343 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8344 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8345 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8346 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8347 | return nullptr; |
| 8348 | } |
| 8349 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8350 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8351 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8352 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8353 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8354 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8355 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8356 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8357 | return nullptr; |
| 8358 | } |
| 8359 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8360 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8361 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8362 | if (DepKind == OMPC_DEPEND_sink) { |
| 8363 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8364 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8365 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8366 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8367 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8368 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8369 | DSAStack->getParentOrderedRegionParam()) { |
| 8370 | for (auto &RefExpr : VarList) { |
| 8371 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8372 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8373 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8374 | // It will be analyzed later. |
| 8375 | Vars.push_back(RefExpr); |
| 8376 | continue; |
| 8377 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8378 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8379 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8380 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8381 | if (DepKind == OMPC_DEPEND_sink) { |
| 8382 | if (DepCounter >= TotalDepCount) { |
| 8383 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8384 | continue; |
| 8385 | } |
| 8386 | ++DepCounter; |
| 8387 | // OpenMP [2.13.9, Summary] |
| 8388 | // depend(dependence-type : vec), where dependence-type is: |
| 8389 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8390 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8391 | // where n is the value specified by the ordered clause in the loop |
| 8392 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8393 | // loop associated with the loop directive, and di is a constant |
| 8394 | // non-negative integer. |
| 8395 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8396 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8397 | if (!DE) { |
| 8398 | OverloadedOperatorKind OOK = OO_None; |
| 8399 | SourceLocation OOLoc; |
| 8400 | Expr *LHS, *RHS; |
| 8401 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8402 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8403 | OOLoc = BO->getOperatorLoc(); |
| 8404 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8405 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8406 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8407 | OOK = OCE->getOperator(); |
| 8408 | OOLoc = OCE->getOperatorLoc(); |
| 8409 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8410 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8411 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8412 | OOK = MCE->getMethodDecl() |
| 8413 | ->getNameInfo() |
| 8414 | .getName() |
| 8415 | .getCXXOverloadedOperator(); |
| 8416 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8417 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8418 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8419 | } else { |
| 8420 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8421 | continue; |
| 8422 | } |
| 8423 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8424 | if (!DE) { |
| 8425 | Diag(LHS->getExprLoc(), |
| 8426 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8427 | << DSAStack->getParentLoopControlVariable( |
| 8428 | DepCounter.getZExtValue()); |
| 8429 | continue; |
| 8430 | } |
| 8431 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8432 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8433 | continue; |
| 8434 | } |
| 8435 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8436 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8437 | if (Res.isInvalid()) |
| 8438 | continue; |
| 8439 | } |
| 8440 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8441 | if (!CurContext->isDependentContext() && |
| 8442 | DSAStack->getParentOrderedRegionParam() && |
| 8443 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8444 | Diag(DE->getExprLoc(), |
| 8445 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8446 | << DSAStack->getParentLoopControlVariable( |
| 8447 | DepCounter.getZExtValue()); |
| 8448 | continue; |
| 8449 | } |
| 8450 | } else { |
| 8451 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8452 | // A variable that is part of another variable (such as a field of a |
| 8453 | // structure) but is not an array element or an array section cannot |
| 8454 | // appear in a depend clause. |
| 8455 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8456 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8457 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8458 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8459 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8460 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8461 | !ASE->getBase()->getType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8462 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8463 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8464 | continue; |
| 8465 | } |
| 8466 | } |
| 8467 | |
| 8468 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8469 | } |
| 8470 | |
| 8471 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8472 | TotalDepCount > VarList.size() && |
| 8473 | DSAStack->getParentOrderedRegionParam()) { |
| 8474 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8475 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8476 | } |
| 8477 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8478 | Vars.empty()) |
| 8479 | return nullptr; |
| 8480 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8481 | |
| 8482 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8483 | DepLoc, ColonLoc, Vars); |
| 8484 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8485 | |
| 8486 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8487 | SourceLocation LParenLoc, |
| 8488 | SourceLocation EndLoc) { |
| 8489 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8490 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8491 | // OpenMP [2.9.1, Restrictions] |
| 8492 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8493 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8494 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8495 | return nullptr; |
| 8496 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8497 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8498 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8499 | |
| 8500 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8501 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8502 | if (!RD || RD->isInvalidDecl()) |
| 8503 | return true; |
| 8504 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8505 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8506 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8507 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8508 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8509 | if (RD->isDynamicClass()) { |
| 8510 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8511 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8512 | return false; |
| 8513 | } |
| 8514 | auto *DC = RD; |
| 8515 | bool IsCorrect = true; |
| 8516 | for (auto *I : DC->decls()) { |
| 8517 | if (I) { |
| 8518 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8519 | if (MD->isStatic()) { |
| 8520 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8521 | SemaRef.Diag(MD->getLocation(), |
| 8522 | diag::note_omp_static_member_in_target); |
| 8523 | IsCorrect = false; |
| 8524 | } |
| 8525 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8526 | if (VD->isStaticDataMember()) { |
| 8527 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8528 | SemaRef.Diag(VD->getLocation(), |
| 8529 | diag::note_omp_static_member_in_target); |
| 8530 | IsCorrect = false; |
| 8531 | } |
| 8532 | } |
| 8533 | } |
| 8534 | } |
| 8535 | |
| 8536 | for (auto &I : RD->bases()) { |
| 8537 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8538 | I.getType()->getAsCXXRecordDecl())) |
| 8539 | IsCorrect = false; |
| 8540 | } |
| 8541 | return IsCorrect; |
| 8542 | } |
| 8543 | |
| 8544 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8545 | DSAStackTy *Stack, QualType QTy) { |
| 8546 | NamedDecl *ND; |
| 8547 | if (QTy->isIncompleteType(&ND)) { |
| 8548 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8549 | return false; |
| 8550 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8551 | if (!RD->isInvalidDecl() && |
| 8552 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8553 | return false; |
| 8554 | } |
| 8555 | return true; |
| 8556 | } |
| 8557 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8558 | OMPClause * |
| 8559 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 8560 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8561 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 8562 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8563 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8564 | SmallVector<Expr *, 4> Vars; |
| 8565 | |
| 8566 | for (auto &RE : VarList) { |
| 8567 | assert(RE && "Null expr in omp map"); |
| 8568 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8569 | // It will be analyzed later. |
| 8570 | Vars.push_back(RE); |
| 8571 | continue; |
| 8572 | } |
| 8573 | SourceLocation ELoc = RE->getExprLoc(); |
| 8574 | |
| 8575 | // OpenMP [2.14.5, Restrictions] |
| 8576 | // A variable that is part of another variable (such as field of a |
| 8577 | // structure) but is not an array element or an array section cannot appear |
| 8578 | // in a map clause. |
| 8579 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8580 | |
| 8581 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8582 | VE->isInstantiationDependent() || |
| 8583 | VE->containsUnexpandedParameterPack()) { |
| 8584 | // It will be analyzed later. |
| 8585 | Vars.push_back(RE); |
| 8586 | continue; |
| 8587 | } |
| 8588 | |
| 8589 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8590 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8591 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8592 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8593 | |
| 8594 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8595 | (!OASE && !ASE && !DE) || |
| 8596 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8597 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8598 | !ASE->getBase()->getType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8599 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8600 | << 0 << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8601 | continue; |
| 8602 | } |
| 8603 | |
| 8604 | Decl *D = nullptr; |
| 8605 | if (DE) { |
| 8606 | D = DE->getDecl(); |
| 8607 | } else if (ASE) { |
| 8608 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8609 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8610 | } else if (OASE) { |
| 8611 | auto *B = OASE->getBase(); |
| 8612 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8613 | } |
| 8614 | assert(D && "Null decl on map clause."); |
| 8615 | auto *VD = cast<VarDecl>(D); |
| 8616 | |
| 8617 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8618 | // threadprivate variables cannot appear in a map clause. |
| 8619 | if (DSAStack->isThreadPrivate(VD)) { |
| 8620 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8621 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8622 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8623 | continue; |
| 8624 | } |
| 8625 | |
| 8626 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8627 | // At most one list item can be an array item derived from a given variable |
| 8628 | // in map clauses of the same construct. |
| 8629 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8630 | // List items of map clauses in the same construct must not share original |
| 8631 | // storage. |
| 8632 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8633 | // A variable for which the type is pointer, reference to array, or |
| 8634 | // reference to pointer and an array section derived from that variable |
| 8635 | // must not appear as list items of map clauses of the same construct. |
| 8636 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8637 | if (MI.RefExpr) { |
| 8638 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8639 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8640 | << MI.RefExpr->getSourceRange(); |
| 8641 | continue; |
| 8642 | } |
| 8643 | |
| 8644 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8645 | // A variable for which the type is pointer, reference to array, or |
| 8646 | // reference to pointer must not appear as a list item if the enclosing |
| 8647 | // device data environment already contains an array section derived from |
| 8648 | // that variable. |
| 8649 | // An array section derived from a variable for which the type is pointer, |
| 8650 | // reference to array, or reference to pointer must not appear as a list |
| 8651 | // item if the enclosing device data environment already contains that |
| 8652 | // variable. |
| 8653 | QualType Type = VD->getType(); |
| 8654 | MI = DSAStack->getMapInfoForVar(VD); |
| 8655 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8656 | isa<DeclRefExpr>(VE)) && |
| 8657 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8658 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8659 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8660 | << MI.RefExpr->getSourceRange(); |
| 8661 | continue; |
| 8662 | } |
| 8663 | |
| 8664 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8665 | // A list item must have a mappable type. |
| 8666 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8667 | DSAStack, Type)) |
| 8668 | continue; |
| 8669 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8670 | // target enter data |
| 8671 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 8672 | // A map-type must be specified in all map clauses and must be either |
| 8673 | // to or alloc. |
| 8674 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 8675 | if (DKind == OMPD_target_enter_data && |
| 8676 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 8677 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8678 | << (IsMapTypeImplicit ? 1 : 0) |
| 8679 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8680 | << getOpenMPDirectiveName(DKind); |
| 8681 | // Proceed to add the variable in a map clause anyway, to prevent |
| 8682 | // further spurious messages |
| 8683 | } |
| 8684 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8685 | // target exit_data |
| 8686 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 8687 | // A map-type must be specified in all map clauses and must be either |
| 8688 | // from, release, or delete. |
| 8689 | DKind = DSAStack->getCurrentDirective(); |
| 8690 | if (DKind == OMPD_target_exit_data && |
| 8691 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 8692 | MapType == OMPC_MAP_delete)) { |
| 8693 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8694 | << (IsMapTypeImplicit ? 1 : 0) |
| 8695 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8696 | << getOpenMPDirectiveName(DKind); |
| 8697 | // Proceed to add the variable in a map clause anyway, to prevent |
| 8698 | // further spurious messages |
| 8699 | } |
| 8700 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8701 | Vars.push_back(RE); |
| 8702 | MI.RefExpr = RE; |
| 8703 | DSAStack->addMapInfoForVar(VD, MI); |
| 8704 | } |
| 8705 | if (Vars.empty()) |
| 8706 | return nullptr; |
| 8707 | |
| 8708 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8709 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8710 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8711 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8712 | |
| 8713 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8714 | SourceLocation StartLoc, |
| 8715 | SourceLocation LParenLoc, |
| 8716 | SourceLocation EndLoc) { |
| 8717 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8718 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8719 | // OpenMP [teams Constrcut, Restrictions] |
| 8720 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8721 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8722 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8723 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8724 | |
| 8725 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8726 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8727 | |
| 8728 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8729 | SourceLocation StartLoc, |
| 8730 | SourceLocation LParenLoc, |
| 8731 | SourceLocation EndLoc) { |
| 8732 | Expr *ValExpr = ThreadLimit; |
| 8733 | |
| 8734 | // OpenMP [teams Constrcut, Restrictions] |
| 8735 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8736 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8737 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8738 | return nullptr; |
| 8739 | |
| 8740 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8741 | EndLoc); |
| 8742 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8743 | |
| 8744 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8745 | SourceLocation StartLoc, |
| 8746 | SourceLocation LParenLoc, |
| 8747 | SourceLocation EndLoc) { |
| 8748 | Expr *ValExpr = Priority; |
| 8749 | |
| 8750 | // OpenMP [2.9.1, task Constrcut] |
| 8751 | // The priority-value is a non-negative numerical scalar expression. |
| 8752 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8753 | /*StrictlyPositive=*/false)) |
| 8754 | return nullptr; |
| 8755 | |
| 8756 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8757 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8758 | |
| 8759 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8760 | SourceLocation StartLoc, |
| 8761 | SourceLocation LParenLoc, |
| 8762 | SourceLocation EndLoc) { |
| 8763 | Expr *ValExpr = Grainsize; |
| 8764 | |
| 8765 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8766 | // The parameter of the grainsize clause must be a positive integer |
| 8767 | // expression. |
| 8768 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8769 | /*StrictlyPositive=*/true)) |
| 8770 | return nullptr; |
| 8771 | |
| 8772 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8773 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8774 | |
| 8775 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 8776 | SourceLocation StartLoc, |
| 8777 | SourceLocation LParenLoc, |
| 8778 | SourceLocation EndLoc) { |
| 8779 | Expr *ValExpr = NumTasks; |
| 8780 | |
| 8781 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8782 | // The parameter of the num_tasks clause must be a positive integer |
| 8783 | // expression. |
| 8784 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 8785 | /*StrictlyPositive=*/true)) |
| 8786 | return nullptr; |
| 8787 | |
| 8788 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8789 | } |
| 8790 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8791 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 8792 | SourceLocation LParenLoc, |
| 8793 | SourceLocation EndLoc) { |
| 8794 | // OpenMP [2.13.2, critical construct, Description] |
| 8795 | // ... where hint-expression is an integer constant expression that evaluates |
| 8796 | // to a valid lock hint. |
| 8797 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 8798 | if (HintExpr.isInvalid()) |
| 8799 | return nullptr; |
| 8800 | return new (Context) |
| 8801 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 8802 | } |
| 8803 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8804 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 8805 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 8806 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 8807 | SourceLocation EndLoc) { |
| 8808 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 8809 | std::string Values; |
| 8810 | Values += "'"; |
| 8811 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 8812 | Values += "'"; |
| 8813 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 8814 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 8815 | return nullptr; |
| 8816 | } |
| 8817 | Expr *ValExpr = ChunkSize; |
| 8818 | Expr *HelperValExpr = nullptr; |
| 8819 | if (ChunkSize) { |
| 8820 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 8821 | !ChunkSize->isInstantiationDependent() && |
| 8822 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 8823 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 8824 | ExprResult Val = |
| 8825 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 8826 | if (Val.isInvalid()) |
| 8827 | return nullptr; |
| 8828 | |
| 8829 | ValExpr = Val.get(); |
| 8830 | |
| 8831 | // OpenMP [2.7.1, Restrictions] |
| 8832 | // chunk_size must be a loop invariant integer expression with a positive |
| 8833 | // value. |
| 8834 | llvm::APSInt Result; |
| 8835 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 8836 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 8837 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 8838 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 8839 | return nullptr; |
| 8840 | } |
| 8841 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 8842 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 8843 | ChunkSize->getType(), ".chunk."); |
| 8844 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 8845 | ChunkSize->getExprLoc(), |
| 8846 | /*RefersToCapture=*/true); |
| 8847 | HelperValExpr = ImpVarRef; |
| 8848 | } |
| 8849 | } |
| 8850 | } |
| 8851 | |
| 8852 | return new (Context) |
| 8853 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 8854 | Kind, ValExpr, HelperValExpr); |
| 8855 | } |