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; |
| 73 | DeclRefExpr *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; |
| 88 | DeclRefExpr *RefExpr; |
| 89 | }; |
| 90 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 91 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 92 | typedef llvm::DenseMap<VarDecl *, unsigned> LoopControlVariablesMapTy; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 93 | typedef llvm::SmallDenseMap<VarDecl *, 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 | |
| 142 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *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. |
| 182 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 183 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 184 | /// \brief Register specified variable as loop control variable. |
| 185 | void addLoopControlVariable(VarDecl *D); |
| 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). |
| 190 | unsigned isLoopControlVariable(VarDecl *D); |
| 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). |
| 195 | unsigned isParentLoopControlVariable(VarDecl *D); |
| 196 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 197 | /// parent directive. |
| 198 | VarDecl *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. |
| 201 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 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 | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 205 | DSAVarData getTopDSA(VarDecl *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 | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 207 | DSAVarData getImplicitDSA(VarDecl *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> |
| 212 | DSAVarData hasDSA(VarDecl *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> |
| 218 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 219 | DirectivesPredicate DPred, |
| 220 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 221 | /// \brief Checks if the specified variables has explicit data-sharing |
| 222 | /// attributes which match specified \a CPred predicate at the specified |
| 223 | /// OpenMP region. |
| 224 | bool hasExplicitDSA(VarDecl *D, |
| 225 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 226 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 227 | |
| 228 | /// \brief Returns true if the directive at level \Level matches in the |
| 229 | /// specified \a DPred predicate. |
| 230 | bool hasExplicitDirective( |
| 231 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 232 | unsigned Level); |
| 233 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 234 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 235 | template <class NamedDirectivesPredicate> |
| 236 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 237 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | /// \brief Returns currently analyzed directive. |
| 239 | OpenMPDirectiveKind getCurrentDirective() const { |
| 240 | return Stack.back().Directive; |
| 241 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 242 | /// \brief Returns parent directive. |
| 243 | OpenMPDirectiveKind getParentDirective() const { |
| 244 | if (Stack.size() > 2) |
| 245 | return Stack[Stack.size() - 2].Directive; |
| 246 | return OMPD_unknown; |
| 247 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 248 | /// \brief Return the directive associated with the provided scope. |
| 249 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 250 | |
| 251 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 252 | void setDefaultDSANone(SourceLocation Loc) { |
| 253 | Stack.back().DefaultAttr = DSA_none; |
| 254 | Stack.back().DefaultAttrLoc = Loc; |
| 255 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 256 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 257 | void setDefaultDSAShared(SourceLocation Loc) { |
| 258 | Stack.back().DefaultAttr = DSA_shared; |
| 259 | Stack.back().DefaultAttrLoc = Loc; |
| 260 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 261 | |
| 262 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 263 | return Stack.back().DefaultAttr; |
| 264 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 265 | SourceLocation getDefaultDSALocation() const { |
| 266 | return Stack.back().DefaultAttrLoc; |
| 267 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 268 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 269 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 270 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 271 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 272 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 276 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 277 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 278 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 279 | } |
| 280 | /// \brief Returns true, if parent region is ordered (has associated |
| 281 | /// 'ordered' clause), false - otherwise. |
| 282 | bool isParentOrderedRegion() const { |
| 283 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 284 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 285 | return false; |
| 286 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 287 | /// \brief Returns optional parameter for the ordered region. |
| 288 | Expr *getParentOrderedRegionParam() const { |
| 289 | if (Stack.size() > 2) |
| 290 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 291 | return nullptr; |
| 292 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 293 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 294 | void setNowaitRegion(bool IsNowait = true) { |
| 295 | Stack.back().NowaitRegion = IsNowait; |
| 296 | } |
| 297 | /// \brief Returns true, if parent region is nowait (has associated |
| 298 | /// 'nowait' clause), false - otherwise. |
| 299 | bool isParentNowaitRegion() const { |
| 300 | if (Stack.size() > 2) |
| 301 | return Stack[Stack.size() - 2].NowaitRegion; |
| 302 | return false; |
| 303 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 304 | /// \brief Marks parent region as cancel region. |
| 305 | void setParentCancelRegion(bool Cancel = true) { |
| 306 | if (Stack.size() > 2) |
| 307 | Stack[Stack.size() - 2].CancelRegion = |
| 308 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 309 | } |
| 310 | /// \brief Return true if current region has inner cancel construct. |
| 311 | bool isCancelRegion() const { |
| 312 | return Stack.back().CancelRegion; |
| 313 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 314 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 315 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 316 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 317 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 318 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 319 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 320 | /// \brief Marks current target region as one with closely nested teams |
| 321 | /// region. |
| 322 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 323 | if (Stack.size() > 2) |
| 324 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 325 | } |
| 326 | /// \brief Returns true, if current region has closely nested teams region. |
| 327 | bool hasInnerTeamsRegion() const { |
| 328 | return getInnerTeamsRegionLoc().isValid(); |
| 329 | } |
| 330 | /// \brief Returns location of the nested teams region (if any). |
| 331 | SourceLocation getInnerTeamsRegionLoc() const { |
| 332 | if (Stack.size() > 1) |
| 333 | return Stack.back().InnerTeamsRegionLoc; |
| 334 | return SourceLocation(); |
| 335 | } |
| 336 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 337 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 338 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 339 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 340 | |
| 341 | MapInfo getMapInfoForVar(VarDecl *VD) { |
| 342 | MapInfo VarMI = {0}; |
| 343 | for (auto Cnt = Stack.size() - 1; Cnt > 0; --Cnt) { |
| 344 | if (Stack[Cnt].MappedDecls.count(VD)) { |
| 345 | VarMI = Stack[Cnt].MappedDecls[VD]; |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | return VarMI; |
| 350 | } |
| 351 | |
| 352 | void addMapInfoForVar(VarDecl *VD, MapInfo MI) { |
| 353 | if (Stack.size() > 1) { |
| 354 | Stack.back().MappedDecls[VD] = MI; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | MapInfo IsMappedInCurrentRegion(VarDecl *VD) { |
| 359 | assert(Stack.size() > 1 && "Target level is 0"); |
| 360 | MapInfo VarMI = {0}; |
| 361 | if (Stack.size() > 1 && Stack.back().MappedDecls.count(VD)) { |
| 362 | VarMI = Stack.back().MappedDecls[VD]; |
| 363 | } |
| 364 | return VarMI; |
| 365 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 366 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 367 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 368 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 369 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 370 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 371 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 372 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | |
| 374 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 375 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 376 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 377 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 378 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 379 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 380 | // in a region but not in construct] |
| 381 | // File-scope or namespace-scope variables referenced in called routines |
| 382 | // in the region are shared unless they appear in a threadprivate |
| 383 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 384 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 385 | DVar.CKind = OMPC_shared; |
| 386 | |
| 387 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 388 | // in a region but not in construct] |
| 389 | // Variables with static storage duration that are declared in called |
| 390 | // routines in the region are shared. |
| 391 | if (D->hasGlobalStorage()) |
| 392 | DVar.CKind = OMPC_shared; |
| 393 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 394 | return DVar; |
| 395 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 396 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 397 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 398 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 399 | // in a Construct, C/C++, predetermined, p.1] |
| 400 | // Variables with automatic storage duration that are declared in a scope |
| 401 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 402 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 403 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 404 | DVar.CKind = OMPC_private; |
| 405 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 408 | // Explicitly specified attributes and local variables with predetermined |
| 409 | // attributes. |
| 410 | if (Iter->SharingMap.count(D)) { |
| 411 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 412 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 413 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 414 | return DVar; |
| 415 | } |
| 416 | |
| 417 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 418 | // in a Construct, C/C++, implicitly determined, p.1] |
| 419 | // In a parallel or task construct, the data-sharing attributes of these |
| 420 | // variables are determined by the default clause, if present. |
| 421 | switch (Iter->DefaultAttr) { |
| 422 | case DSA_shared: |
| 423 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 424 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | return DVar; |
| 426 | case DSA_none: |
| 427 | return DVar; |
| 428 | case DSA_unspecified: |
| 429 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 430 | // in a Construct, implicitly determined, p.2] |
| 431 | // In a parallel construct, if no default clause is present, these |
| 432 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 433 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 434 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 435 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | DVar.CKind = OMPC_shared; |
| 437 | return DVar; |
| 438 | } |
| 439 | |
| 440 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 441 | // in a Construct, implicitly determined, p.4] |
| 442 | // In a task construct, if no default clause is present, a variable that in |
| 443 | // the enclosing context is determined to be shared by all implicit tasks |
| 444 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | if (DVar.DKind == OMPD_task) { |
| 446 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 447 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 448 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 449 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 450 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | // in a Construct, implicitly determined, p.6] |
| 452 | // In a task construct, if no default clause is present, a variable |
| 453 | // whose data-sharing attribute is not determined by the rules above is |
| 454 | // firstprivate. |
| 455 | DVarTemp = getDSA(I, D); |
| 456 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 457 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 458 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 459 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 460 | return DVar; |
| 461 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 462 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 463 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 464 | } |
| 465 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 466 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 467 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 468 | return DVar; |
| 469 | } |
| 470 | } |
| 471 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 472 | // in a Construct, implicitly determined, p.3] |
| 473 | // For constructs other than task, if no default clause is present, these |
| 474 | // variables inherit their data-sharing attributes from the enclosing |
| 475 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 476 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 479 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 480 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 481 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 482 | auto It = Stack.back().AlignedMap.find(D); |
| 483 | if (It == Stack.back().AlignedMap.end()) { |
| 484 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 485 | Stack.back().AlignedMap[D] = NewDE; |
| 486 | return nullptr; |
| 487 | } else { |
| 488 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 489 | return It->second; |
| 490 | } |
| 491 | return nullptr; |
| 492 | } |
| 493 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 494 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 495 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 496 | D = D->getCanonicalDecl(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 497 | 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] | 498 | } |
| 499 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 500 | unsigned DSAStackTy::isLoopControlVariable(VarDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 501 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 502 | D = D->getCanonicalDecl(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 503 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 504 | } |
| 505 | |
| 506 | unsigned DSAStackTy::isParentLoopControlVariable(VarDecl *D) { |
| 507 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 508 | D = D->getCanonicalDecl(); |
| 509 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 510 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 511 | : 0; |
| 512 | } |
| 513 | |
| 514 | VarDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
| 515 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 516 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 517 | return nullptr; |
| 518 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 519 | if (Pair.second == I) |
| 520 | return Pair.first; |
| 521 | } |
| 522 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 525 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 526 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 527 | if (A == OMPC_threadprivate) { |
| 528 | Stack[0].SharingMap[D].Attributes = A; |
| 529 | Stack[0].SharingMap[D].RefExpr = E; |
| 530 | } else { |
| 531 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 532 | Stack.back().SharingMap[D].Attributes = A; |
| 533 | Stack.back().SharingMap[D].RefExpr = E; |
| 534 | } |
| 535 | } |
| 536 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 537 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 538 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 539 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 540 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 541 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 542 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 543 | ++I; |
| 544 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 545 | if (I == E) |
| 546 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 547 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 548 | Scope *CurScope = getCurScope(); |
| 549 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 550 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 551 | } |
| 552 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 553 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 554 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 557 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 558 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 559 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 560 | DeclContext *DC = SemaRef.CurContext; |
| 561 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 562 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 563 | VarDecl *Decl = |
| 564 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 565 | if (Attrs) { |
| 566 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 567 | I != E; ++I) |
| 568 | Decl->addAttr(*I); |
| 569 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 570 | Decl->setImplicit(); |
| 571 | return Decl; |
| 572 | } |
| 573 | |
| 574 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 575 | SourceLocation Loc, |
| 576 | bool RefersToCapture = false) { |
| 577 | D->setReferenced(); |
| 578 | D->markUsed(S.Context); |
| 579 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 580 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 581 | VK_LValue); |
| 582 | } |
| 583 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 584 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 585 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | DSAVarData DVar; |
| 587 | |
| 588 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 589 | // in a Construct, C/C++, predetermined, p.1] |
| 590 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 591 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 592 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 593 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 594 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 595 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 596 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 597 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 598 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 599 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 600 | } |
| 601 | if (Stack[0].SharingMap.count(D)) { |
| 602 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 603 | DVar.CKind = OMPC_threadprivate; |
| 604 | return DVar; |
| 605 | } |
| 606 | |
| 607 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 608 | // in a Construct, C/C++, predetermined, p.4] |
| 609 | // Static data members are shared. |
| 610 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 611 | // in a Construct, C/C++, predetermined, p.7] |
| 612 | // Variables with static storage duration that are declared in a scope |
| 613 | // inside the construct are shared. |
| 614 | if (D->isStaticDataMember()) { |
| 615 | DSAVarData DVarTemp = |
| 616 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 617 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 618 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 619 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 620 | DVar.CKind = OMPC_shared; |
| 621 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 625 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 626 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 628 | // in a Construct, C/C++, predetermined, p.6] |
| 629 | // Variables with const qualified type having no mutable member are |
| 630 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 631 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 632 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 633 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 634 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 635 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 636 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 637 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 638 | // Variables with const-qualified type having no mutable member may be |
| 639 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 640 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 641 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 642 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 643 | return DVar; |
| 644 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 645 | DVar.CKind = OMPC_shared; |
| 646 | return DVar; |
| 647 | } |
| 648 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 649 | // Explicitly specified attributes and local variables with predetermined |
| 650 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 651 | auto StartI = std::next(Stack.rbegin()); |
| 652 | auto EndI = std::prev(Stack.rend()); |
| 653 | if (FromParent && StartI != EndI) { |
| 654 | StartI = std::next(StartI); |
| 655 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 656 | auto I = std::prev(StartI); |
| 657 | if (I->SharingMap.count(D)) { |
| 658 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 659 | DVar.CKind = I->SharingMap[D].Attributes; |
| 660 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return DVar; |
| 664 | } |
| 665 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 666 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 667 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 668 | auto StartI = Stack.rbegin(); |
| 669 | auto EndI = std::prev(Stack.rend()); |
| 670 | if (FromParent && StartI != EndI) { |
| 671 | StartI = std::next(StartI); |
| 672 | } |
| 673 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 676 | template <class ClausesPredicate, class DirectivesPredicate> |
| 677 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 678 | DirectivesPredicate DPred, |
| 679 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 680 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 681 | auto StartI = std::next(Stack.rbegin()); |
| 682 | auto EndI = std::prev(Stack.rend()); |
| 683 | if (FromParent && StartI != EndI) { |
| 684 | StartI = std::next(StartI); |
| 685 | } |
| 686 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 687 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 688 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 689 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 690 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 691 | return DVar; |
| 692 | } |
| 693 | return DSAVarData(); |
| 694 | } |
| 695 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 696 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 697 | DSAStackTy::DSAVarData |
| 698 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 699 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 700 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 701 | auto StartI = std::next(Stack.rbegin()); |
| 702 | auto EndI = std::prev(Stack.rend()); |
| 703 | if (FromParent && StartI != EndI) { |
| 704 | StartI = std::next(StartI); |
| 705 | } |
| 706 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 707 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 709 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 710 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 711 | return DVar; |
| 712 | return DSAVarData(); |
| 713 | } |
| 714 | return DSAVarData(); |
| 715 | } |
| 716 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 717 | bool DSAStackTy::hasExplicitDSA( |
| 718 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 719 | unsigned Level) { |
| 720 | if (CPred(ClauseKindMode)) |
| 721 | return true; |
| 722 | if (isClauseParsingMode()) |
| 723 | ++Level; |
| 724 | D = D->getCanonicalDecl(); |
| 725 | auto StartI = Stack.rbegin(); |
| 726 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 727 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 728 | return false; |
| 729 | std::advance(StartI, Level); |
| 730 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 731 | CPred(StartI->SharingMap[D].Attributes); |
| 732 | } |
| 733 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 734 | bool DSAStackTy::hasExplicitDirective( |
| 735 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 736 | unsigned Level) { |
| 737 | if (isClauseParsingMode()) |
| 738 | ++Level; |
| 739 | auto StartI = Stack.rbegin(); |
| 740 | auto EndI = std::prev(Stack.rend()); |
| 741 | if (std::distance(StartI, EndI) <= (int)Level) |
| 742 | return false; |
| 743 | std::advance(StartI, Level); |
| 744 | return DPred(StartI->Directive); |
| 745 | } |
| 746 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 747 | template <class NamedDirectivesPredicate> |
| 748 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 749 | auto StartI = std::next(Stack.rbegin()); |
| 750 | auto EndI = std::prev(Stack.rend()); |
| 751 | if (FromParent && StartI != EndI) { |
| 752 | StartI = std::next(StartI); |
| 753 | } |
| 754 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 755 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 756 | return true; |
| 757 | } |
| 758 | return false; |
| 759 | } |
| 760 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 761 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 762 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 763 | if (I->CurScope == S) |
| 764 | return I->Directive; |
| 765 | return OMPD_unknown; |
| 766 | } |
| 767 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 768 | void Sema::InitDataSharingAttributesStack() { |
| 769 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 770 | } |
| 771 | |
| 772 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 773 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 774 | bool Sema::IsOpenMPCapturedByRef(VarDecl *VD, |
| 775 | const CapturedRegionScopeInfo *RSI) { |
| 776 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 777 | |
| 778 | auto &Ctx = getASTContext(); |
| 779 | bool IsByRef = true; |
| 780 | |
| 781 | // Find the directive that is associated with the provided scope. |
| 782 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
| 783 | auto Ty = VD->getType(); |
| 784 | |
| 785 | if (isOpenMPTargetDirective(DKind)) { |
| 786 | // This table summarizes how a given variable should be passed to the device |
| 787 | // given its type and the clauses where it appears. This table is based on |
| 788 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 789 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 790 | // |
| 791 | // ========================================================================= |
| 792 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 793 | // | |(tofrom:scalar)| | pvt | | | | |
| 794 | // ========================================================================= |
| 795 | // | scl | | | | - | | bycopy| |
| 796 | // | scl | | - | x | - | - | bycopy| |
| 797 | // | scl | | x | - | - | - | null | |
| 798 | // | scl | x | | | - | | byref | |
| 799 | // | scl | x | - | x | - | - | bycopy| |
| 800 | // | scl | x | x | - | - | - | null | |
| 801 | // | scl | | - | - | - | x | byref | |
| 802 | // | scl | x | - | - | - | x | byref | |
| 803 | // |
| 804 | // | agg | n.a. | | | - | | byref | |
| 805 | // | agg | n.a. | - | x | - | - | byref | |
| 806 | // | agg | n.a. | x | - | - | - | null | |
| 807 | // | agg | n.a. | - | - | - | x | byref | |
| 808 | // | agg | n.a. | - | - | - | x[] | byref | |
| 809 | // |
| 810 | // | ptr | n.a. | | | - | | bycopy| |
| 811 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 812 | // | ptr | n.a. | x | - | - | - | null | |
| 813 | // | ptr | n.a. | - | - | - | x | byref | |
| 814 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 815 | // | ptr | n.a. | - | - | x | | bycopy| |
| 816 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 817 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 818 | // ========================================================================= |
| 819 | // Legend: |
| 820 | // scl - scalar |
| 821 | // ptr - pointer |
| 822 | // agg - aggregate |
| 823 | // x - applies |
| 824 | // - - invalid in this combination |
| 825 | // [] - mapped with an array section |
| 826 | // byref - should be mapped by reference |
| 827 | // byval - should be mapped by value |
| 828 | // null - initialize a local variable to null on the device |
| 829 | // |
| 830 | // Observations: |
| 831 | // - All scalar declarations that show up in a map clause have to be passed |
| 832 | // by reference, because they may have been mapped in the enclosing data |
| 833 | // environment. |
| 834 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 835 | // passed by reference, regardless the result in the table above. |
| 836 | // - For pointers mapped by value that have either an implicit map or an |
| 837 | // array section, the runtime library may pass the NULL value to the |
| 838 | // device instead of the value passed to it by the compiler. |
| 839 | |
| 840 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 841 | // values requires having the map, private, and firstprivate clauses SEMA |
| 842 | // and parsing in place, which we don't yet. |
| 843 | |
| 844 | if (Ty->isReferenceType()) |
| 845 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 846 | IsByRef = !Ty->isScalarType(); |
| 847 | } |
| 848 | |
| 849 | // When passing data by value, we need to make sure it fits the uintptr size |
| 850 | // and alignment, because the runtime library only deals with uintptr types. |
| 851 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 852 | // instead. |
| 853 | if (!IsByRef && |
| 854 | (Ctx.getTypeSizeInChars(Ty) > |
| 855 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| 856 | Ctx.getDeclAlign(VD) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
| 857 | IsByRef = true; |
| 858 | |
| 859 | return IsByRef; |
| 860 | } |
| 861 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 862 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 863 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 864 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 865 | |
| 866 | // If we are attempting to capture a global variable in a directive with |
| 867 | // 'target' we return true so that this global is also mapped to the device. |
| 868 | // |
| 869 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 870 | // then it should not be captured. Therefore, an extra check has to be |
| 871 | // inserted here once support for 'declare target' is added. |
| 872 | // |
| 873 | if (!VD->hasLocalStorage()) { |
| 874 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 875 | !DSAStack->isClauseParsingMode()) { |
| 876 | return true; |
| 877 | } |
| 878 | if (DSAStack->getCurScope() && |
| 879 | DSAStack->hasDirective( |
| 880 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 881 | SourceLocation Loc) -> bool { |
| 882 | return isOpenMPTargetDirective(K); |
| 883 | }, |
| 884 | false)) { |
| 885 | return true; |
| 886 | } |
| 887 | } |
| 888 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 889 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 890 | (!DSAStack->isClauseParsingMode() || |
| 891 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 892 | if (DSAStack->isLoopControlVariable(VD) || |
| 893 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 894 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 895 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 896 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 897 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 898 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 899 | return true; |
| 900 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 901 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 902 | return DVarPrivate.CKind != OMPC_unknown; |
| 903 | } |
| 904 | return false; |
| 905 | } |
| 906 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 907 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 908 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 909 | return DSAStack->hasExplicitDSA( |
| 910 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 911 | } |
| 912 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 913 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 914 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 915 | // Return true if the current level is no longer enclosed in a target region. |
| 916 | |
| 917 | return !VD->hasLocalStorage() && |
| 918 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 919 | } |
| 920 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 921 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 922 | |
| 923 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 924 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 925 | Scope *CurScope, SourceLocation Loc) { |
| 926 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 927 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 928 | } |
| 929 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 930 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 931 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 934 | void Sema::EndOpenMPClause() { |
| 935 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 938 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 939 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 940 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 941 | // clause requires an accessible, unambiguous default constructor for the |
| 942 | // class type, unless the list item is also specified in a firstprivate |
| 943 | // clause. |
| 944 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 945 | for (auto *C : D->clauses()) { |
| 946 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 947 | SmallVector<Expr *, 8> PrivateCopies; |
| 948 | for (auto *DE : Clause->varlists()) { |
| 949 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 950 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 951 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 952 | } |
| 953 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 954 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 955 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 956 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 957 | // Generate helper private variable and initialize it with the |
| 958 | // default value. The address of the original variable is replaced |
| 959 | // by the address of the new private variable in CodeGen. This new |
| 960 | // variable is not added to IdResolver, so the code in the OpenMP |
| 961 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 962 | auto *VDPrivate = buildVarDecl( |
| 963 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 964 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 965 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 966 | if (VDPrivate->isInvalidDecl()) |
| 967 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 968 | PrivateCopies.push_back(buildDeclRefExpr( |
| 969 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 970 | } else { |
| 971 | // The variable is also a firstprivate, so initialization sequence |
| 972 | // for private copy is generated already. |
| 973 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 974 | } |
| 975 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 976 | // Set initializers to private copies if no errors were found. |
| 977 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 978 | Clause->setPrivateCopies(PrivateCopies); |
| 979 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 984 | DSAStack->pop(); |
| 985 | DiscardCleanupsInEvaluationContext(); |
| 986 | PopExpressionEvaluationContext(); |
| 987 | } |
| 988 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 989 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 990 | Expr *NumIterations, Sema &SemaRef, |
| 991 | Scope *S); |
| 992 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 993 | namespace { |
| 994 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 995 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 996 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 997 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 998 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 999 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1000 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1001 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1002 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1003 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1004 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1005 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1006 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1007 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1008 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1009 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1010 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1011 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1012 | |
| 1013 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1014 | CXXScopeSpec &ScopeSpec, |
| 1015 | const DeclarationNameInfo &Id) { |
| 1016 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1017 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1018 | |
| 1019 | if (Lookup.isAmbiguous()) |
| 1020 | return ExprError(); |
| 1021 | |
| 1022 | VarDecl *VD; |
| 1023 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1024 | if (TypoCorrection Corrected = CorrectTypo( |
| 1025 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1026 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1027 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1028 | PDiag(Lookup.empty() |
| 1029 | ? diag::err_undeclared_var_use_suggest |
| 1030 | : diag::err_omp_expected_var_arg_suggest) |
| 1031 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1032 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1033 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1034 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1035 | : diag::err_omp_expected_var_arg) |
| 1036 | << Id.getName(); |
| 1037 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1038 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1039 | } else { |
| 1040 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1041 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1042 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1043 | return ExprError(); |
| 1044 | } |
| 1045 | } |
| 1046 | Lookup.suppressDiagnostics(); |
| 1047 | |
| 1048 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1049 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1050 | if (!VD->hasGlobalStorage()) { |
| 1051 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1052 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1053 | bool IsDecl = |
| 1054 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1055 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1056 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1057 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1058 | return ExprError(); |
| 1059 | } |
| 1060 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1061 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1062 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1063 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1064 | // A threadprivate directive for file-scope variables must appear outside |
| 1065 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1066 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1067 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1068 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1069 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1070 | bool IsDecl = |
| 1071 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1072 | Diag(VD->getLocation(), |
| 1073 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1074 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1075 | return ExprError(); |
| 1076 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1077 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1078 | // A threadprivate directive for static class member variables must appear |
| 1079 | // in the class definition, in the same scope in which the member |
| 1080 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1081 | if (CanonicalVD->isStaticDataMember() && |
| 1082 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1083 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1084 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1085 | bool IsDecl = |
| 1086 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1087 | Diag(VD->getLocation(), |
| 1088 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1089 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1090 | return ExprError(); |
| 1091 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1092 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1093 | // A threadprivate directive for namespace-scope variables must appear |
| 1094 | // outside any definition or declaration other than the namespace |
| 1095 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1096 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1097 | (!getCurLexicalContext()->isFileContext() || |
| 1098 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1099 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1100 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1101 | bool IsDecl = |
| 1102 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1103 | Diag(VD->getLocation(), |
| 1104 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1105 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1106 | return ExprError(); |
| 1107 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1108 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1109 | // A threadprivate directive for static block-scope variables must appear |
| 1110 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1111 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1112 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1113 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1114 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1115 | bool IsDecl = |
| 1116 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1117 | Diag(VD->getLocation(), |
| 1118 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1119 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1120 | return ExprError(); |
| 1121 | } |
| 1122 | |
| 1123 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1124 | // A threadprivate directive must lexically precede all references to any |
| 1125 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1126 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1127 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1128 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1129 | return ExprError(); |
| 1130 | } |
| 1131 | |
| 1132 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1133 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | return DE; |
| 1135 | } |
| 1136 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1137 | Sema::DeclGroupPtrTy |
| 1138 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1139 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1140 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1141 | CurContext->addDecl(D); |
| 1142 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1143 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1144 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1147 | namespace { |
| 1148 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1149 | Sema &SemaRef; |
| 1150 | |
| 1151 | public: |
| 1152 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1153 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1154 | if (VD->hasLocalStorage()) { |
| 1155 | SemaRef.Diag(E->getLocStart(), |
| 1156 | diag::err_omp_local_var_in_threadprivate_init) |
| 1157 | << E->getSourceRange(); |
| 1158 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1159 | << VD << VD->getSourceRange(); |
| 1160 | return true; |
| 1161 | } |
| 1162 | } |
| 1163 | return false; |
| 1164 | } |
| 1165 | bool VisitStmt(const Stmt *S) { |
| 1166 | for (auto Child : S->children()) { |
| 1167 | if (Child && Visit(Child)) |
| 1168 | return true; |
| 1169 | } |
| 1170 | return false; |
| 1171 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1172 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1173 | }; |
| 1174 | } // namespace |
| 1175 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1176 | OMPThreadPrivateDecl * |
| 1177 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1178 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1179 | for (auto &RefExpr : VarList) { |
| 1180 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1181 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1182 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1183 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1184 | QualType QType = VD->getType(); |
| 1185 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1186 | // It will be analyzed later. |
| 1187 | Vars.push_back(DE); |
| 1188 | continue; |
| 1189 | } |
| 1190 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1191 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1192 | // A threadprivate variable must not have an incomplete type. |
| 1193 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1194 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1195 | continue; |
| 1196 | } |
| 1197 | |
| 1198 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1199 | // A threadprivate variable must not have a reference type. |
| 1200 | if (VD->getType()->isReferenceType()) { |
| 1201 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1202 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1203 | bool IsDecl = |
| 1204 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1205 | Diag(VD->getLocation(), |
| 1206 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1207 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1208 | continue; |
| 1209 | } |
| 1210 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1211 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1212 | // the corresponding diagnostic. |
| 1213 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1214 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1215 | getLangOpts().OpenMPUseTLS && |
| 1216 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1217 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1218 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1219 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1220 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1221 | bool IsDecl = |
| 1222 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1223 | Diag(VD->getLocation(), |
| 1224 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1225 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1226 | continue; |
| 1227 | } |
| 1228 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1229 | // Check if initial value of threadprivate variable reference variable with |
| 1230 | // local storage (it is not supported by runtime). |
| 1231 | if (auto Init = VD->getAnyInitializer()) { |
| 1232 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1233 | if (Checker.Visit(Init)) |
| 1234 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1237 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1238 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1239 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1240 | Context, SourceRange(Loc, Loc))); |
| 1241 | if (auto *ML = Context.getASTMutationListener()) |
| 1242 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1243 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1244 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1245 | if (!Vars.empty()) { |
| 1246 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1247 | Vars); |
| 1248 | D->setAccess(AS_public); |
| 1249 | } |
| 1250 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1251 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1252 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1253 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1254 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1255 | bool IsLoopIterVar = false) { |
| 1256 | if (DVar.RefExpr) { |
| 1257 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1258 | << getOpenMPClauseName(DVar.CKind); |
| 1259 | return; |
| 1260 | } |
| 1261 | enum { |
| 1262 | PDSA_StaticMemberShared, |
| 1263 | PDSA_StaticLocalVarShared, |
| 1264 | PDSA_LoopIterVarPrivate, |
| 1265 | PDSA_LoopIterVarLinear, |
| 1266 | PDSA_LoopIterVarLastprivate, |
| 1267 | PDSA_ConstVarShared, |
| 1268 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1269 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1270 | PDSA_LocalVarPrivate, |
| 1271 | PDSA_Implicit |
| 1272 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1273 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1274 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1275 | if (IsLoopIterVar) { |
| 1276 | if (DVar.CKind == OMPC_private) |
| 1277 | Reason = PDSA_LoopIterVarPrivate; |
| 1278 | else if (DVar.CKind == OMPC_lastprivate) |
| 1279 | Reason = PDSA_LoopIterVarLastprivate; |
| 1280 | else |
| 1281 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1282 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1283 | Reason = PDSA_TaskVarFirstprivate; |
| 1284 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1285 | } else if (VD->isStaticLocal()) |
| 1286 | Reason = PDSA_StaticLocalVarShared; |
| 1287 | else if (VD->isStaticDataMember()) |
| 1288 | Reason = PDSA_StaticMemberShared; |
| 1289 | else if (VD->isFileVarDecl()) |
| 1290 | Reason = PDSA_GlobalVarShared; |
| 1291 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1292 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1293 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1294 | ReportHint = true; |
| 1295 | Reason = PDSA_LocalVarPrivate; |
| 1296 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1297 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1298 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1299 | << Reason << ReportHint |
| 1300 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1301 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1302 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1303 | << getOpenMPClauseName(DVar.CKind); |
| 1304 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1307 | namespace { |
| 1308 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1309 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1310 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1311 | bool ErrorFound; |
| 1312 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1313 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1314 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1315 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1316 | public: |
| 1317 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1318 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1319 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1320 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1321 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1322 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1323 | auto DVar = Stack->getTopDSA(VD, false); |
| 1324 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1325 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1326 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1327 | auto ELoc = E->getExprLoc(); |
| 1328 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1329 | // The default(none) clause requires that each variable that is referenced |
| 1330 | // in the construct, and does not have a predetermined data-sharing |
| 1331 | // attribute, must have its data-sharing attribute explicitly determined |
| 1332 | // by being listed in a data-sharing attribute clause. |
| 1333 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1334 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1335 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1336 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1341 | // A list item that appears in a reduction clause of the innermost |
| 1342 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1343 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1344 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1345 | [](OpenMPDirectiveKind K) -> bool { |
| 1346 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1347 | isOpenMPWorksharingDirective(K) || |
| 1348 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1349 | }, |
| 1350 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1351 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1352 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1353 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1354 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1355 | return; |
| 1356 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1357 | |
| 1358 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1359 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1360 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1361 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1365 | for (auto *C : S->clauses()) { |
| 1366 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1367 | // for task directives. |
| 1368 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1369 | for (auto *CC : C->children()) { |
| 1370 | if (CC) |
| 1371 | Visit(CC); |
| 1372 | } |
| 1373 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1374 | } |
| 1375 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | for (auto *C : S->children()) { |
| 1377 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1378 | Visit(C); |
| 1379 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1380 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1381 | |
| 1382 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1383 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1384 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1385 | return VarsWithInheritedDSA; |
| 1386 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1387 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1388 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1389 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1390 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1391 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1392 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1393 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1394 | switch (DKind) { |
| 1395 | case OMPD_parallel: { |
| 1396 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1397 | QualType KmpInt32PtrTy = |
| 1398 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1399 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1400 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1401 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1402 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1403 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1404 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1405 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1409 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1410 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1411 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1412 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1413 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1417 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1418 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1419 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1420 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1421 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1424 | case OMPD_for_simd: { |
| 1425 | Sema::CapturedParamNameType Params[] = { |
| 1426 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1427 | }; |
| 1428 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1429 | Params); |
| 1430 | break; |
| 1431 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1432 | case OMPD_sections: { |
| 1433 | Sema::CapturedParamNameType Params[] = { |
| 1434 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1435 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1436 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1437 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1438 | break; |
| 1439 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1440 | case OMPD_section: { |
| 1441 | Sema::CapturedParamNameType Params[] = { |
| 1442 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1443 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1444 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1445 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1448 | case OMPD_single: { |
| 1449 | Sema::CapturedParamNameType Params[] = { |
| 1450 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1451 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1452 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1453 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1454 | break; |
| 1455 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1456 | case OMPD_master: { |
| 1457 | Sema::CapturedParamNameType Params[] = { |
| 1458 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1459 | }; |
| 1460 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1461 | Params); |
| 1462 | break; |
| 1463 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1464 | case OMPD_critical: { |
| 1465 | Sema::CapturedParamNameType Params[] = { |
| 1466 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1467 | }; |
| 1468 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1469 | Params); |
| 1470 | break; |
| 1471 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1472 | case OMPD_parallel_for: { |
| 1473 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1474 | QualType KmpInt32PtrTy = |
| 1475 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1476 | Sema::CapturedParamNameType Params[] = { |
| 1477 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1478 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1479 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1480 | }; |
| 1481 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1482 | Params); |
| 1483 | break; |
| 1484 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1485 | case OMPD_parallel_for_simd: { |
| 1486 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1487 | QualType KmpInt32PtrTy = |
| 1488 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1489 | Sema::CapturedParamNameType Params[] = { |
| 1490 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1491 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1492 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1493 | }; |
| 1494 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1495 | Params); |
| 1496 | break; |
| 1497 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1498 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1499 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1500 | QualType KmpInt32PtrTy = |
| 1501 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1502 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1503 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1504 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1505 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1506 | }; |
| 1507 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1508 | Params); |
| 1509 | break; |
| 1510 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1511 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1512 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1513 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1514 | FunctionProtoType::ExtProtoInfo EPI; |
| 1515 | EPI.Variadic = true; |
| 1516 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1517 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1518 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1519 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1520 | std::make_pair(".privates.", |
| 1521 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1522 | std::make_pair( |
| 1523 | ".copy_fn.", |
| 1524 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1525 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1526 | }; |
| 1527 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1528 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1529 | // Mark this captured region as inlined, because we don't use outlined |
| 1530 | // function directly. |
| 1531 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1532 | AlwaysInlineAttr::CreateImplicit( |
| 1533 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1534 | break; |
| 1535 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1536 | case OMPD_ordered: { |
| 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 | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1544 | case OMPD_atomic: { |
| 1545 | Sema::CapturedParamNameType Params[] = { |
| 1546 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1547 | }; |
| 1548 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1549 | Params); |
| 1550 | break; |
| 1551 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1552 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1553 | case OMPD_target: { |
| 1554 | Sema::CapturedParamNameType Params[] = { |
| 1555 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1556 | }; |
| 1557 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1558 | Params); |
| 1559 | break; |
| 1560 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1561 | case OMPD_teams: { |
| 1562 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1563 | QualType KmpInt32PtrTy = |
| 1564 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1565 | Sema::CapturedParamNameType Params[] = { |
| 1566 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1567 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1568 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1569 | }; |
| 1570 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1571 | Params); |
| 1572 | break; |
| 1573 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1574 | case OMPD_taskgroup: { |
| 1575 | Sema::CapturedParamNameType Params[] = { |
| 1576 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1577 | }; |
| 1578 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1579 | Params); |
| 1580 | break; |
| 1581 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1582 | case OMPD_taskloop: { |
| 1583 | Sema::CapturedParamNameType Params[] = { |
| 1584 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1585 | }; |
| 1586 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1587 | Params); |
| 1588 | break; |
| 1589 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1590 | case OMPD_taskloop_simd: { |
| 1591 | Sema::CapturedParamNameType Params[] = { |
| 1592 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1593 | }; |
| 1594 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1595 | Params); |
| 1596 | break; |
| 1597 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1598 | case OMPD_distribute: { |
| 1599 | Sema::CapturedParamNameType Params[] = { |
| 1600 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1601 | }; |
| 1602 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1603 | Params); |
| 1604 | break; |
| 1605 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1606 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1607 | case OMPD_taskyield: |
| 1608 | case OMPD_barrier: |
| 1609 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1610 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1611 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1612 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1613 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1614 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1615 | llvm_unreachable("Unknown OpenMP directive"); |
| 1616 | } |
| 1617 | } |
| 1618 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1619 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1620 | ArrayRef<OMPClause *> Clauses) { |
| 1621 | if (!S.isUsable()) { |
| 1622 | ActOnCapturedRegionError(); |
| 1623 | return StmtError(); |
| 1624 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1625 | |
| 1626 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1627 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1628 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1629 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1630 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1631 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1632 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1633 | (getLangOpts().OpenMPUseTLS && |
| 1634 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1635 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1636 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1637 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1638 | for (auto *VarRef : Clause->children()) { |
| 1639 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1640 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1641 | } |
| 1642 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1643 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1644 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1645 | Clause->getClauseKind() == OMPC_schedule) { |
| 1646 | // Mark all variables in private list clauses as used in inner region. |
| 1647 | // Required for proper codegen of combined directives. |
| 1648 | // TODO: add processing for other clauses. |
| 1649 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1650 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1651 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1652 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1653 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1654 | SC = cast<OMPScheduleClause>(Clause); |
| 1655 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1656 | OC = cast<OMPOrderedClause>(Clause); |
| 1657 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1658 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1659 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1660 | bool ErrorFound = false; |
| 1661 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1662 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1663 | // specified. |
| 1664 | if (SC && |
| 1665 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1666 | SC->getSecondScheduleModifier() == |
| 1667 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1668 | OC) { |
| 1669 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1670 | ? SC->getFirstScheduleModifierLoc() |
| 1671 | : SC->getSecondScheduleModifierLoc(), |
| 1672 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1673 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1674 | ErrorFound = true; |
| 1675 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1676 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1677 | for (auto *C : LCs) { |
| 1678 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1679 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1680 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1681 | ErrorFound = true; |
| 1682 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1683 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1684 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1685 | OC->getNumForLoops()) { |
| 1686 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1687 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1688 | ErrorFound = true; |
| 1689 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1690 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1691 | ActOnCapturedRegionError(); |
| 1692 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1693 | } |
| 1694 | return ActOnCapturedRegionEnd(S.get()); |
| 1695 | } |
| 1696 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1697 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1698 | OpenMPDirectiveKind CurrentRegion, |
| 1699 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1700 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1701 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1702 | // Allowed nesting of constructs |
| 1703 | // +------------------+-----------------+------------------------------------+ |
| 1704 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1705 | // +------------------+-----------------+------------------------------------+ |
| 1706 | // | parallel | parallel | * | |
| 1707 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1708 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1709 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1710 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1711 | // | parallel | simd | * | |
| 1712 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1713 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1714 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1715 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1716 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1717 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1718 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1719 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1720 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1721 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1722 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1723 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1724 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1725 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1726 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1727 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1728 | // | parallel | cancellation | | |
| 1729 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1730 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1731 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1732 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1733 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1734 | // +------------------+-----------------+------------------------------------+ |
| 1735 | // | for | parallel | * | |
| 1736 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1737 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1738 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1739 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1740 | // | for | simd | * | |
| 1741 | // | for | sections | + | |
| 1742 | // | for | section | + | |
| 1743 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1744 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1745 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1746 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1747 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1748 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1749 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1750 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1751 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1752 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1753 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1754 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1755 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1756 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1757 | // | for | cancellation | | |
| 1758 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1759 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1760 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1761 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1762 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1763 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1764 | // | master | parallel | * | |
| 1765 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1766 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1767 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1768 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1769 | // | master | simd | * | |
| 1770 | // | master | sections | + | |
| 1771 | // | master | section | + | |
| 1772 | // | master | single | + | |
| 1773 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1774 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1775 | // | master |parallel sections| * | |
| 1776 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1777 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1778 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1779 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1780 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1781 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1782 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1783 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1784 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1785 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1786 | // | master | cancellation | | |
| 1787 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1788 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1789 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1790 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1791 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1792 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1793 | // | critical | parallel | * | |
| 1794 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1795 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1796 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1797 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1798 | // | critical | simd | * | |
| 1799 | // | critical | sections | + | |
| 1800 | // | critical | section | + | |
| 1801 | // | critical | single | + | |
| 1802 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1803 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1804 | // | critical |parallel sections| * | |
| 1805 | // | critical | task | * | |
| 1806 | // | critical | taskyield | * | |
| 1807 | // | critical | barrier | + | |
| 1808 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1809 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1810 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1811 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1812 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1813 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1814 | // | critical | cancellation | | |
| 1815 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1816 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1817 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1818 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1819 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1820 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1821 | // | simd | parallel | | |
| 1822 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1823 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1824 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1825 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1826 | // | simd | simd | | |
| 1827 | // | simd | sections | | |
| 1828 | // | simd | section | | |
| 1829 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1830 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1831 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1832 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1833 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1834 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1835 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1836 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1837 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1838 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1839 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1840 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1841 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1842 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1843 | // | simd | cancellation | | |
| 1844 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1845 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1846 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1847 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1848 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1849 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1850 | // | for simd | parallel | | |
| 1851 | // | for simd | for | | |
| 1852 | // | for simd | for simd | | |
| 1853 | // | for simd | master | | |
| 1854 | // | for simd | critical | | |
| 1855 | // | for simd | simd | | |
| 1856 | // | for simd | sections | | |
| 1857 | // | for simd | section | | |
| 1858 | // | for simd | single | | |
| 1859 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1860 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1861 | // | for simd |parallel sections| | |
| 1862 | // | for simd | task | | |
| 1863 | // | for simd | taskyield | | |
| 1864 | // | for simd | barrier | | |
| 1865 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1866 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1867 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1868 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1869 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1870 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1871 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1872 | // | for simd | cancellation | | |
| 1873 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1874 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1875 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1876 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1877 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1878 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1879 | // | parallel for simd| parallel | | |
| 1880 | // | parallel for simd| for | | |
| 1881 | // | parallel for simd| for simd | | |
| 1882 | // | parallel for simd| master | | |
| 1883 | // | parallel for simd| critical | | |
| 1884 | // | parallel for simd| simd | | |
| 1885 | // | parallel for simd| sections | | |
| 1886 | // | parallel for simd| section | | |
| 1887 | // | parallel for simd| single | | |
| 1888 | // | parallel for simd| parallel for | | |
| 1889 | // | parallel for simd|parallel for simd| | |
| 1890 | // | parallel for simd|parallel sections| | |
| 1891 | // | parallel for simd| task | | |
| 1892 | // | parallel for simd| taskyield | | |
| 1893 | // | parallel for simd| barrier | | |
| 1894 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1895 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1896 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1897 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1898 | // | parallel for simd| atomic | | |
| 1899 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1900 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1901 | // | parallel for simd| cancellation | | |
| 1902 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1903 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1904 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1905 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1906 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1907 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1908 | // | sections | parallel | * | |
| 1909 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1910 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1911 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1912 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1913 | // | sections | simd | * | |
| 1914 | // | sections | sections | + | |
| 1915 | // | sections | section | * | |
| 1916 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1917 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1918 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1919 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1920 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1921 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1922 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1923 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1924 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1925 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1926 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1927 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1928 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1929 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1930 | // | sections | cancellation | | |
| 1931 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1932 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1933 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1934 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1935 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1936 | // +------------------+-----------------+------------------------------------+ |
| 1937 | // | section | parallel | * | |
| 1938 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1939 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1940 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1941 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1942 | // | section | simd | * | |
| 1943 | // | section | sections | + | |
| 1944 | // | section | section | + | |
| 1945 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1946 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1947 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1948 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1949 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1950 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1951 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1952 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1953 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1954 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1955 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1956 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1957 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1958 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1959 | // | section | cancellation | | |
| 1960 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1961 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1962 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1963 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1964 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1965 | // +------------------+-----------------+------------------------------------+ |
| 1966 | // | single | parallel | * | |
| 1967 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1968 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1969 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1970 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1971 | // | single | simd | * | |
| 1972 | // | single | sections | + | |
| 1973 | // | single | section | + | |
| 1974 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1975 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1976 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1977 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1978 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1979 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1980 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1981 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1982 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1983 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1984 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1985 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1986 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1987 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1988 | // | single | cancellation | | |
| 1989 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1990 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1991 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1992 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1993 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1994 | // +------------------+-----------------+------------------------------------+ |
| 1995 | // | parallel for | parallel | * | |
| 1996 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1997 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1998 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1999 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2000 | // | parallel for | simd | * | |
| 2001 | // | parallel for | sections | + | |
| 2002 | // | parallel for | section | + | |
| 2003 | // | parallel for | single | + | |
| 2004 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2005 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2006 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2007 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2008 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2009 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2010 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2011 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2012 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2013 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2014 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2015 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2016 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2017 | // | parallel for | cancellation | | |
| 2018 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2019 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2020 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2021 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2022 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2023 | // +------------------+-----------------+------------------------------------+ |
| 2024 | // | parallel sections| parallel | * | |
| 2025 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2026 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2027 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2028 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2029 | // | parallel sections| simd | * | |
| 2030 | // | parallel sections| sections | + | |
| 2031 | // | parallel sections| section | * | |
| 2032 | // | parallel sections| single | + | |
| 2033 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2034 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2035 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2036 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2037 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2038 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2039 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2040 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2041 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2042 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2043 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2044 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2045 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2046 | // | parallel sections| cancellation | | |
| 2047 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2048 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2049 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2050 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2051 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2052 | // +------------------+-----------------+------------------------------------+ |
| 2053 | // | task | parallel | * | |
| 2054 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2055 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2056 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2057 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2058 | // | task | simd | * | |
| 2059 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2060 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2061 | // | task | single | + | |
| 2062 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2063 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2064 | // | task |parallel sections| * | |
| 2065 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2066 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2067 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2068 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2069 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2070 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2071 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2072 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2073 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2074 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2075 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2076 | // | | point | ! | |
| 2077 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2078 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2079 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2080 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2081 | // +------------------+-----------------+------------------------------------+ |
| 2082 | // | ordered | parallel | * | |
| 2083 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2084 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2085 | // | ordered | master | * | |
| 2086 | // | ordered | critical | * | |
| 2087 | // | ordered | simd | * | |
| 2088 | // | ordered | sections | + | |
| 2089 | // | ordered | section | + | |
| 2090 | // | ordered | single | + | |
| 2091 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2092 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2093 | // | ordered |parallel sections| * | |
| 2094 | // | ordered | task | * | |
| 2095 | // | ordered | taskyield | * | |
| 2096 | // | ordered | barrier | + | |
| 2097 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2098 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2099 | // | ordered | flush | * | |
| 2100 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2101 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2102 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2103 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2104 | // | ordered | cancellation | | |
| 2105 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2106 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2107 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2108 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2109 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2110 | // +------------------+-----------------+------------------------------------+ |
| 2111 | // | atomic | parallel | | |
| 2112 | // | atomic | for | | |
| 2113 | // | atomic | for simd | | |
| 2114 | // | atomic | master | | |
| 2115 | // | atomic | critical | | |
| 2116 | // | atomic | simd | | |
| 2117 | // | atomic | sections | | |
| 2118 | // | atomic | section | | |
| 2119 | // | atomic | single | | |
| 2120 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2121 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2122 | // | atomic |parallel sections| | |
| 2123 | // | atomic | task | | |
| 2124 | // | atomic | taskyield | | |
| 2125 | // | atomic | barrier | | |
| 2126 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2127 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2128 | // | atomic | flush | | |
| 2129 | // | atomic | ordered | | |
| 2130 | // | atomic | atomic | | |
| 2131 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2132 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2133 | // | atomic | cancellation | | |
| 2134 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2135 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2136 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2137 | // | atomic | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2138 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2139 | // +------------------+-----------------+------------------------------------+ |
| 2140 | // | target | parallel | * | |
| 2141 | // | target | for | * | |
| 2142 | // | target | for simd | * | |
| 2143 | // | target | master | * | |
| 2144 | // | target | critical | * | |
| 2145 | // | target | simd | * | |
| 2146 | // | target | sections | * | |
| 2147 | // | target | section | * | |
| 2148 | // | target | single | * | |
| 2149 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2150 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2151 | // | target |parallel sections| * | |
| 2152 | // | target | task | * | |
| 2153 | // | target | taskyield | * | |
| 2154 | // | target | barrier | * | |
| 2155 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2156 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2157 | // | target | flush | * | |
| 2158 | // | target | ordered | * | |
| 2159 | // | target | atomic | * | |
| 2160 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2161 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2162 | // | target | cancellation | | |
| 2163 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2164 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2165 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2166 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2167 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2168 | // +------------------+-----------------+------------------------------------+ |
| 2169 | // | teams | parallel | * | |
| 2170 | // | teams | for | + | |
| 2171 | // | teams | for simd | + | |
| 2172 | // | teams | master | + | |
| 2173 | // | teams | critical | + | |
| 2174 | // | teams | simd | + | |
| 2175 | // | teams | sections | + | |
| 2176 | // | teams | section | + | |
| 2177 | // | teams | single | + | |
| 2178 | // | teams | parallel for | * | |
| 2179 | // | teams |parallel for simd| * | |
| 2180 | // | teams |parallel sections| * | |
| 2181 | // | teams | task | + | |
| 2182 | // | teams | taskyield | + | |
| 2183 | // | teams | barrier | + | |
| 2184 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2185 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2186 | // | teams | flush | + | |
| 2187 | // | teams | ordered | + | |
| 2188 | // | teams | atomic | + | |
| 2189 | // | teams | target | + | |
| 2190 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2191 | // | teams | cancellation | | |
| 2192 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2193 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2194 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2195 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2196 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2197 | // +------------------+-----------------+------------------------------------+ |
| 2198 | // | taskloop | parallel | * | |
| 2199 | // | taskloop | for | + | |
| 2200 | // | taskloop | for simd | + | |
| 2201 | // | taskloop | master | + | |
| 2202 | // | taskloop | critical | * | |
| 2203 | // | taskloop | simd | * | |
| 2204 | // | taskloop | sections | + | |
| 2205 | // | taskloop | section | + | |
| 2206 | // | taskloop | single | + | |
| 2207 | // | taskloop | parallel for | * | |
| 2208 | // | taskloop |parallel for simd| * | |
| 2209 | // | taskloop |parallel sections| * | |
| 2210 | // | taskloop | task | * | |
| 2211 | // | taskloop | taskyield | * | |
| 2212 | // | taskloop | barrier | + | |
| 2213 | // | taskloop | taskwait | * | |
| 2214 | // | taskloop | taskgroup | * | |
| 2215 | // | taskloop | flush | * | |
| 2216 | // | taskloop | ordered | + | |
| 2217 | // | taskloop | atomic | * | |
| 2218 | // | taskloop | target | * | |
| 2219 | // | taskloop | teams | + | |
| 2220 | // | taskloop | cancellation | | |
| 2221 | // | | point | | |
| 2222 | // | taskloop | cancel | | |
| 2223 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2224 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2225 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2226 | // | taskloop simd | parallel | | |
| 2227 | // | taskloop simd | for | | |
| 2228 | // | taskloop simd | for simd | | |
| 2229 | // | taskloop simd | master | | |
| 2230 | // | taskloop simd | critical | | |
| 2231 | // | taskloop simd | simd | | |
| 2232 | // | taskloop simd | sections | | |
| 2233 | // | taskloop simd | section | | |
| 2234 | // | taskloop simd | single | | |
| 2235 | // | taskloop simd | parallel for | | |
| 2236 | // | taskloop simd |parallel for simd| | |
| 2237 | // | taskloop simd |parallel sections| | |
| 2238 | // | taskloop simd | task | | |
| 2239 | // | taskloop simd | taskyield | | |
| 2240 | // | taskloop simd | barrier | | |
| 2241 | // | taskloop simd | taskwait | | |
| 2242 | // | taskloop simd | taskgroup | | |
| 2243 | // | taskloop simd | flush | | |
| 2244 | // | taskloop simd | ordered | + (with simd clause) | |
| 2245 | // | taskloop simd | atomic | | |
| 2246 | // | taskloop simd | target | | |
| 2247 | // | taskloop simd | teams | | |
| 2248 | // | taskloop simd | cancellation | | |
| 2249 | // | | point | | |
| 2250 | // | taskloop simd | cancel | | |
| 2251 | // | taskloop simd | taskloop | | |
| 2252 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2253 | // | taskloop simd | distribute | | |
| 2254 | // +------------------+-----------------+------------------------------------+ |
| 2255 | // | distribute | parallel | * | |
| 2256 | // | distribute | for | * | |
| 2257 | // | distribute | for simd | * | |
| 2258 | // | distribute | master | * | |
| 2259 | // | distribute | critical | * | |
| 2260 | // | distribute | simd | * | |
| 2261 | // | distribute | sections | * | |
| 2262 | // | distribute | section | * | |
| 2263 | // | distribute | single | * | |
| 2264 | // | distribute | parallel for | * | |
| 2265 | // | distribute |parallel for simd| * | |
| 2266 | // | distribute |parallel sections| * | |
| 2267 | // | distribute | task | * | |
| 2268 | // | distribute | taskyield | * | |
| 2269 | // | distribute | barrier | * | |
| 2270 | // | distribute | taskwait | * | |
| 2271 | // | distribute | taskgroup | * | |
| 2272 | // | distribute | flush | * | |
| 2273 | // | distribute | ordered | + | |
| 2274 | // | distribute | atomic | * | |
| 2275 | // | distribute | target | | |
| 2276 | // | distribute | teams | | |
| 2277 | // | distribute | cancellation | + | |
| 2278 | // | | point | | |
| 2279 | // | distribute | cancel | + | |
| 2280 | // | distribute | taskloop | * | |
| 2281 | // | distribute | taskloop simd | * | |
| 2282 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2283 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2284 | if (Stack->getCurScope()) { |
| 2285 | auto ParentRegion = Stack->getParentDirective(); |
| 2286 | bool NestingProhibited = false; |
| 2287 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2288 | enum { |
| 2289 | NoRecommend, |
| 2290 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2291 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2292 | ShouldBeInTargetRegion, |
| 2293 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2294 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2295 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2296 | // OpenMP [2.16, Nesting of Regions] |
| 2297 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2298 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2299 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2300 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2301 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2302 | return true; |
| 2303 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2304 | if (ParentRegion == OMPD_atomic) { |
| 2305 | // OpenMP [2.16, Nesting of Regions] |
| 2306 | // OpenMP constructs may not be nested inside an atomic region. |
| 2307 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2308 | return true; |
| 2309 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2310 | if (CurrentRegion == OMPD_section) { |
| 2311 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2312 | // Orphaned section directives are prohibited. That is, the section |
| 2313 | // directives must appear within the sections construct and must not be |
| 2314 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2315 | if (ParentRegion != OMPD_sections && |
| 2316 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2317 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2318 | << (ParentRegion != OMPD_unknown) |
| 2319 | << getOpenMPDirectiveName(ParentRegion); |
| 2320 | return true; |
| 2321 | } |
| 2322 | return false; |
| 2323 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2324 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2325 | // called from OpenMP regions with the required preconditions). |
| 2326 | if (ParentRegion == OMPD_unknown) |
| 2327 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2328 | if (CurrentRegion == OMPD_cancellation_point || |
| 2329 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2330 | // OpenMP [2.16, Nesting of Regions] |
| 2331 | // A cancellation point construct for which construct-type-clause is |
| 2332 | // taskgroup must be nested inside a task construct. A cancellation |
| 2333 | // point construct for which construct-type-clause is not taskgroup must |
| 2334 | // be closely nested inside an OpenMP construct that matches the type |
| 2335 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2336 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2337 | // nested inside a task construct. A cancel construct for which |
| 2338 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2339 | // OpenMP construct that matches the type specified in |
| 2340 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2341 | NestingProhibited = |
| 2342 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2343 | (CancelRegion == OMPD_for && |
| 2344 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2345 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2346 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2347 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2348 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2349 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2350 | // OpenMP [2.16, Nesting of Regions] |
| 2351 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2352 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2353 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2354 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2355 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2356 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2357 | // OpenMP [2.16, Nesting of Regions] |
| 2358 | // A critical region may not be nested (closely or otherwise) inside a |
| 2359 | // critical region with the same name. Note that this restriction is not |
| 2360 | // sufficient to prevent deadlock. |
| 2361 | SourceLocation PreviousCriticalLoc; |
| 2362 | bool DeadLock = |
| 2363 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2364 | OpenMPDirectiveKind K, |
| 2365 | const DeclarationNameInfo &DNI, |
| 2366 | SourceLocation Loc) |
| 2367 | ->bool { |
| 2368 | if (K == OMPD_critical && |
| 2369 | DNI.getName() == CurrentName.getName()) { |
| 2370 | PreviousCriticalLoc = Loc; |
| 2371 | return true; |
| 2372 | } else |
| 2373 | return false; |
| 2374 | }, |
| 2375 | false /* skip top directive */); |
| 2376 | if (DeadLock) { |
| 2377 | SemaRef.Diag(StartLoc, |
| 2378 | diag::err_omp_prohibited_region_critical_same_name) |
| 2379 | << CurrentName.getName(); |
| 2380 | if (PreviousCriticalLoc.isValid()) |
| 2381 | SemaRef.Diag(PreviousCriticalLoc, |
| 2382 | diag::note_omp_previous_critical_region); |
| 2383 | return true; |
| 2384 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2385 | } else if (CurrentRegion == OMPD_barrier) { |
| 2386 | // OpenMP [2.16, Nesting of Regions] |
| 2387 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2388 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2389 | NestingProhibited = |
| 2390 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2391 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2392 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2393 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2394 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2395 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2396 | // OpenMP [2.16, Nesting of Regions] |
| 2397 | // A worksharing region may not be closely nested inside a worksharing, |
| 2398 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2399 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2400 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2401 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2402 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2403 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2404 | Recommend = ShouldBeInParallelRegion; |
| 2405 | } else if (CurrentRegion == OMPD_ordered) { |
| 2406 | // OpenMP [2.16, Nesting of Regions] |
| 2407 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2408 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2409 | // An ordered region must be closely nested inside a loop region (or |
| 2410 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2411 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2412 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2413 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2414 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2415 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2416 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2417 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2418 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2419 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2420 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2421 | // OpenMP [2.16, Nesting of Regions] |
| 2422 | // If specified, a teams construct must be contained within a target |
| 2423 | // construct. |
| 2424 | NestingProhibited = ParentRegion != OMPD_target; |
| 2425 | Recommend = ShouldBeInTargetRegion; |
| 2426 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2427 | } |
| 2428 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2429 | // OpenMP [2.16, Nesting of Regions] |
| 2430 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2431 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2432 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2433 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2434 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2435 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2436 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2437 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2438 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2439 | // The region associated with the distribute construct must be strictly |
| 2440 | // nested inside a teams region |
| 2441 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2442 | Recommend = ShouldBeInTeamsRegion; |
| 2443 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2444 | if (NestingProhibited) { |
| 2445 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2446 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2447 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2448 | return true; |
| 2449 | } |
| 2450 | } |
| 2451 | return false; |
| 2452 | } |
| 2453 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2454 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2455 | ArrayRef<OMPClause *> Clauses, |
| 2456 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2457 | bool ErrorFound = false; |
| 2458 | unsigned NamedModifiersNumber = 0; |
| 2459 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2460 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2461 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2462 | for (const auto *C : Clauses) { |
| 2463 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2464 | // At most one if clause without a directive-name-modifier can appear on |
| 2465 | // the directive. |
| 2466 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2467 | if (FoundNameModifiers[CurNM]) { |
| 2468 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2469 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2470 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2471 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2472 | } else if (CurNM != OMPD_unknown) { |
| 2473 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2474 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2475 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2476 | FoundNameModifiers[CurNM] = IC; |
| 2477 | if (CurNM == OMPD_unknown) |
| 2478 | continue; |
| 2479 | // Check if the specified name modifier is allowed for the current |
| 2480 | // directive. |
| 2481 | // At most one if clause with the particular directive-name-modifier can |
| 2482 | // appear on the directive. |
| 2483 | bool MatchFound = false; |
| 2484 | for (auto NM : AllowedNameModifiers) { |
| 2485 | if (CurNM == NM) { |
| 2486 | MatchFound = true; |
| 2487 | break; |
| 2488 | } |
| 2489 | } |
| 2490 | if (!MatchFound) { |
| 2491 | S.Diag(IC->getNameModifierLoc(), |
| 2492 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2493 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2494 | ErrorFound = true; |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | // If any if clause on the directive includes a directive-name-modifier then |
| 2499 | // all if clauses on the directive must include a directive-name-modifier. |
| 2500 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2501 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2502 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2503 | diag::err_omp_no_more_if_clause); |
| 2504 | } else { |
| 2505 | std::string Values; |
| 2506 | std::string Sep(", "); |
| 2507 | unsigned AllowedCnt = 0; |
| 2508 | unsigned TotalAllowedNum = |
| 2509 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2510 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2511 | ++Cnt) { |
| 2512 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2513 | if (!FoundNameModifiers[NM]) { |
| 2514 | Values += "'"; |
| 2515 | Values += getOpenMPDirectiveName(NM); |
| 2516 | Values += "'"; |
| 2517 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2518 | Values += " or "; |
| 2519 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2520 | Values += Sep; |
| 2521 | ++AllowedCnt; |
| 2522 | } |
| 2523 | } |
| 2524 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2525 | diag::err_omp_unnamed_if_clause) |
| 2526 | << (TotalAllowedNum > 1) << Values; |
| 2527 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2528 | for (auto Loc : NameModifierLoc) { |
| 2529 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2530 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2531 | ErrorFound = true; |
| 2532 | } |
| 2533 | return ErrorFound; |
| 2534 | } |
| 2535 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2536 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2537 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2538 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2539 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2540 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2541 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2542 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2543 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2544 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2545 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2546 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2547 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2548 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2549 | if (AStmt) { |
| 2550 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2551 | |
| 2552 | // Check default data sharing attributes for referenced variables. |
| 2553 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2554 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2555 | if (DSAChecker.isErrorFound()) |
| 2556 | return StmtError(); |
| 2557 | // Generate list of implicitly defined firstprivate variables. |
| 2558 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2559 | |
| 2560 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2561 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2562 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2563 | SourceLocation(), SourceLocation())) { |
| 2564 | ClausesWithImplicit.push_back(Implicit); |
| 2565 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2566 | DSAChecker.getImplicitFirstprivate().size(); |
| 2567 | } else |
| 2568 | ErrorFound = true; |
| 2569 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2570 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2571 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2572 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2573 | switch (Kind) { |
| 2574 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2575 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2576 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2577 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2578 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2579 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2580 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2581 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2582 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2583 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2584 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2585 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2586 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2587 | case OMPD_for_simd: |
| 2588 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2589 | EndLoc, VarsWithInheritedDSA); |
| 2590 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2591 | case OMPD_sections: |
| 2592 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2593 | EndLoc); |
| 2594 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2595 | case OMPD_section: |
| 2596 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2597 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2598 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2599 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2600 | case OMPD_single: |
| 2601 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2602 | EndLoc); |
| 2603 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2604 | case OMPD_master: |
| 2605 | assert(ClausesWithImplicit.empty() && |
| 2606 | "No clauses are allowed for 'omp master' directive"); |
| 2607 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2608 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2609 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2610 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2611 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2612 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2613 | case OMPD_parallel_for: |
| 2614 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2615 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2616 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2617 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2618 | case OMPD_parallel_for_simd: |
| 2619 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2620 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2621 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2622 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2623 | case OMPD_parallel_sections: |
| 2624 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2625 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2626 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2627 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2628 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2629 | Res = |
| 2630 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2631 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2632 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2633 | case OMPD_taskyield: |
| 2634 | assert(ClausesWithImplicit.empty() && |
| 2635 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2636 | assert(AStmt == nullptr && |
| 2637 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2638 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2639 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2640 | case OMPD_barrier: |
| 2641 | assert(ClausesWithImplicit.empty() && |
| 2642 | "No clauses are allowed for 'omp barrier' directive"); |
| 2643 | assert(AStmt == nullptr && |
| 2644 | "No associated statement allowed for 'omp barrier' directive"); |
| 2645 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2646 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2647 | case OMPD_taskwait: |
| 2648 | assert(ClausesWithImplicit.empty() && |
| 2649 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2650 | assert(AStmt == nullptr && |
| 2651 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2652 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2653 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2654 | case OMPD_taskgroup: |
| 2655 | assert(ClausesWithImplicit.empty() && |
| 2656 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2657 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2658 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2659 | case OMPD_flush: |
| 2660 | assert(AStmt == nullptr && |
| 2661 | "No associated statement allowed for 'omp flush' directive"); |
| 2662 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2663 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2664 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2665 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2666 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2667 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2668 | case OMPD_atomic: |
| 2669 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2670 | EndLoc); |
| 2671 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2672 | case OMPD_teams: |
| 2673 | Res = |
| 2674 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2675 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2676 | case OMPD_target: |
| 2677 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2678 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2679 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2680 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2681 | case OMPD_cancellation_point: |
| 2682 | assert(ClausesWithImplicit.empty() && |
| 2683 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2684 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2685 | "cancellation point' directive"); |
| 2686 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2687 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2688 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2689 | assert(AStmt == nullptr && |
| 2690 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2691 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2692 | CancelRegion); |
| 2693 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2694 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2695 | case OMPD_target_data: |
| 2696 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2697 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2698 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2699 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2700 | case OMPD_taskloop: |
| 2701 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2702 | EndLoc, VarsWithInheritedDSA); |
| 2703 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2704 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2705 | case OMPD_taskloop_simd: |
| 2706 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2707 | EndLoc, VarsWithInheritedDSA); |
| 2708 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2709 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2710 | case OMPD_distribute: |
| 2711 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2712 | EndLoc, VarsWithInheritedDSA); |
| 2713 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2714 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2715 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2716 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2717 | llvm_unreachable("Unknown OpenMP directive"); |
| 2718 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2719 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2720 | for (auto P : VarsWithInheritedDSA) { |
| 2721 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2722 | << P.first << P.second->getSourceRange(); |
| 2723 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2724 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2725 | |
| 2726 | if (!AllowedNameModifiers.empty()) |
| 2727 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2728 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2729 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2730 | if (ErrorFound) |
| 2731 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2732 | return Res; |
| 2733 | } |
| 2734 | |
| 2735 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2736 | Stmt *AStmt, |
| 2737 | SourceLocation StartLoc, |
| 2738 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2739 | if (!AStmt) |
| 2740 | return StmtError(); |
| 2741 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2742 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2743 | // 1.2.2 OpenMP Language Terminology |
| 2744 | // Structured block - An executable statement with a single entry at the |
| 2745 | // top and a single exit at the bottom. |
| 2746 | // The point of exit cannot be a branch out of the structured block. |
| 2747 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2748 | CS->getCapturedDecl()->setNothrow(); |
| 2749 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2750 | getCurFunction()->setHasBranchProtectedScope(); |
| 2751 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2752 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2753 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2756 | namespace { |
| 2757 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2758 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2759 | /// for IR generation. |
| 2760 | class OpenMPIterationSpaceChecker { |
| 2761 | /// \brief Reference to Sema. |
| 2762 | Sema &SemaRef; |
| 2763 | /// \brief A location for diagnostics (when there is no some better location). |
| 2764 | SourceLocation DefaultLoc; |
| 2765 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2766 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2767 | /// \brief A source location for referring to loop init later. |
| 2768 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2769 | /// \brief A source location for referring to condition later. |
| 2770 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2771 | /// \brief A source location for referring to increment later. |
| 2772 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2773 | /// \brief Loop variable. |
| 2774 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2775 | /// \brief Reference to loop variable. |
| 2776 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2777 | /// \brief Lower bound (initializer for the var). |
| 2778 | Expr *LB; |
| 2779 | /// \brief Upper bound. |
| 2780 | Expr *UB; |
| 2781 | /// \brief Loop step (increment). |
| 2782 | Expr *Step; |
| 2783 | /// \brief This flag is true when condition is one of: |
| 2784 | /// Var < UB |
| 2785 | /// Var <= UB |
| 2786 | /// UB > Var |
| 2787 | /// UB >= Var |
| 2788 | bool TestIsLessOp; |
| 2789 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2790 | bool TestIsStrictOp; |
| 2791 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2792 | bool SubtractStep; |
| 2793 | |
| 2794 | public: |
| 2795 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2796 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2797 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2798 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2799 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2800 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2801 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2802 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2803 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2804 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2805 | /// for less/greater and for strict/non-strict comparison. |
| 2806 | bool CheckCond(Expr *S); |
| 2807 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2808 | /// does not conform, otherwise save loop step (#Step). |
| 2809 | bool CheckInc(Expr *S); |
| 2810 | /// \brief Return the loop counter variable. |
| 2811 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2812 | /// \brief Return the reference expression to loop counter variable. |
| 2813 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2814 | /// \brief Source range of the loop init. |
| 2815 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2816 | /// \brief Source range of the loop condition. |
| 2817 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2818 | /// \brief Source range of the loop increment. |
| 2819 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2820 | /// \brief True if the step should be subtracted. |
| 2821 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2822 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2823 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2824 | /// \brief Build the precondition expression for the loops. |
| 2825 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2826 | /// \brief Build reference expression to the counter be used for codegen. |
| 2827 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2828 | /// \brief Build reference expression to the private counter be used for |
| 2829 | /// codegen. |
| 2830 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2831 | /// \brief Build initization of the counter be used for codegen. |
| 2832 | Expr *BuildCounterInit() const; |
| 2833 | /// \brief Build step of the counter be used for codegen. |
| 2834 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2835 | /// \brief Return true if any expression is dependent. |
| 2836 | bool Dependent() const; |
| 2837 | |
| 2838 | private: |
| 2839 | /// \brief Check the right-hand side of an assignment in the increment |
| 2840 | /// expression. |
| 2841 | bool CheckIncRHS(Expr *RHS); |
| 2842 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2843 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2844 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2845 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2846 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2847 | /// \brief Helper to set loop increment. |
| 2848 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2849 | }; |
| 2850 | |
| 2851 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2852 | if (!Var) { |
| 2853 | assert(!LB && !UB && !Step); |
| 2854 | return false; |
| 2855 | } |
| 2856 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2857 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2858 | } |
| 2859 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2860 | template <typename T> |
| 2861 | static T *getExprAsWritten(T *E) { |
| 2862 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2863 | E = ExprTemp->getSubExpr(); |
| 2864 | |
| 2865 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2866 | E = MTE->GetTemporaryExpr(); |
| 2867 | |
| 2868 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2869 | E = Binder->getSubExpr(); |
| 2870 | |
| 2871 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2872 | E = ICE->getSubExprAsWritten(); |
| 2873 | return E->IgnoreParens(); |
| 2874 | } |
| 2875 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2876 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2877 | DeclRefExpr *NewVarRefExpr, |
| 2878 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2879 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2880 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2881 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2882 | if (!NewVar || !NewLB) |
| 2883 | return true; |
| 2884 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2885 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2886 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2887 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2888 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2889 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2890 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2891 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2892 | LB = NewLB; |
| 2893 | return false; |
| 2894 | } |
| 2895 | |
| 2896 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2897 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2898 | // State consistency checking to ensure correct usage. |
| 2899 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2900 | !TestIsLessOp && !TestIsStrictOp); |
| 2901 | if (!NewUB) |
| 2902 | return true; |
| 2903 | UB = NewUB; |
| 2904 | TestIsLessOp = LessOp; |
| 2905 | TestIsStrictOp = StrictOp; |
| 2906 | ConditionSrcRange = SR; |
| 2907 | ConditionLoc = SL; |
| 2908 | return false; |
| 2909 | } |
| 2910 | |
| 2911 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2912 | // State consistency checking to ensure correct usage. |
| 2913 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2914 | if (!NewStep) |
| 2915 | return true; |
| 2916 | if (!NewStep->isValueDependent()) { |
| 2917 | // Check that the step is integer expression. |
| 2918 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2919 | ExprResult Val = |
| 2920 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2921 | if (Val.isInvalid()) |
| 2922 | return true; |
| 2923 | NewStep = Val.get(); |
| 2924 | |
| 2925 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2926 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2927 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2928 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2929 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2930 | // the loop. |
| 2931 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2932 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2933 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2934 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2935 | // the loop. |
| 2936 | llvm::APSInt Result; |
| 2937 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2938 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2939 | bool IsConstNeg = |
| 2940 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2941 | bool IsConstPos = |
| 2942 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2943 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2944 | if (UB && (IsConstZero || |
| 2945 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2946 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2947 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2948 | diag::err_omp_loop_incr_not_compatible) |
| 2949 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2950 | SemaRef.Diag(ConditionLoc, |
| 2951 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2952 | << TestIsLessOp << ConditionSrcRange; |
| 2953 | return true; |
| 2954 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2955 | if (TestIsLessOp == Subtract) { |
| 2956 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2957 | NewStep).get(); |
| 2958 | Subtract = !Subtract; |
| 2959 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2960 | } |
| 2961 | |
| 2962 | Step = NewStep; |
| 2963 | SubtractStep = Subtract; |
| 2964 | return false; |
| 2965 | } |
| 2966 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2967 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2968 | // Check init-expr for canonical loop form and save loop counter |
| 2969 | // variable - #Var and its initialization value - #LB. |
| 2970 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2971 | // var = lb |
| 2972 | // integer-type var = lb |
| 2973 | // random-access-iterator-type var = lb |
| 2974 | // pointer-type var = lb |
| 2975 | // |
| 2976 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2977 | if (EmitDiags) { |
| 2978 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2979 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2980 | return true; |
| 2981 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2982 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2983 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2984 | S = E->IgnoreParens(); |
| 2985 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2986 | if (BO->getOpcode() == BO_Assign) |
| 2987 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2988 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2989 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2990 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2991 | if (DS->isSingleDecl()) { |
| 2992 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2993 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2994 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2995 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2996 | SemaRef.Diag(S->getLocStart(), |
| 2997 | diag::ext_omp_loop_not_canonical_init) |
| 2998 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2999 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | } |
| 3003 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3004 | if (CE->getOperator() == OO_Equal) |
| 3005 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3006 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3007 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3008 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3009 | if (EmitDiags) { |
| 3010 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3011 | << S->getSourceRange(); |
| 3012 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3013 | return true; |
| 3014 | } |
| 3015 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3016 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3017 | /// variable (which may be the loop variable) if possible. |
| 3018 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3019 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3020 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3021 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3022 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3023 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3024 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3025 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3026 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3027 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3028 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3029 | if (!DRE) |
| 3030 | return nullptr; |
| 3031 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3032 | } |
| 3033 | |
| 3034 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3035 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3036 | // less/greater and for strict/non-strict comparison. |
| 3037 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3038 | // var relational-op b |
| 3039 | // b relational-op var |
| 3040 | // |
| 3041 | if (!S) { |
| 3042 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3043 | return true; |
| 3044 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3045 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3046 | SourceLocation CondLoc = S->getLocStart(); |
| 3047 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3048 | if (BO->isRelationalOp()) { |
| 3049 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3050 | return SetUB(BO->getRHS(), |
| 3051 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3052 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3053 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3054 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3055 | return SetUB(BO->getLHS(), |
| 3056 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3057 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3058 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3059 | } |
| 3060 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3061 | if (CE->getNumArgs() == 2) { |
| 3062 | auto Op = CE->getOperator(); |
| 3063 | switch (Op) { |
| 3064 | case OO_Greater: |
| 3065 | case OO_GreaterEqual: |
| 3066 | case OO_Less: |
| 3067 | case OO_LessEqual: |
| 3068 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3069 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3070 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3071 | CE->getOperatorLoc()); |
| 3072 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3073 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3074 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3075 | CE->getOperatorLoc()); |
| 3076 | break; |
| 3077 | default: |
| 3078 | break; |
| 3079 | } |
| 3080 | } |
| 3081 | } |
| 3082 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3083 | << S->getSourceRange() << Var; |
| 3084 | return true; |
| 3085 | } |
| 3086 | |
| 3087 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3088 | // RHS of canonical loop form increment can be: |
| 3089 | // var + incr |
| 3090 | // incr + var |
| 3091 | // var - incr |
| 3092 | // |
| 3093 | RHS = RHS->IgnoreParenImpCasts(); |
| 3094 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3095 | if (BO->isAdditiveOp()) { |
| 3096 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3097 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3098 | return SetStep(BO->getRHS(), !IsAdd); |
| 3099 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3100 | return SetStep(BO->getLHS(), false); |
| 3101 | } |
| 3102 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3103 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3104 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3105 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3106 | return SetStep(CE->getArg(1), !IsAdd); |
| 3107 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3108 | return SetStep(CE->getArg(0), false); |
| 3109 | } |
| 3110 | } |
| 3111 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3112 | << RHS->getSourceRange() << Var; |
| 3113 | return true; |
| 3114 | } |
| 3115 | |
| 3116 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3117 | // Check incr-expr for canonical loop form and return true if it |
| 3118 | // does not conform. |
| 3119 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3120 | // ++var |
| 3121 | // var++ |
| 3122 | // --var |
| 3123 | // var-- |
| 3124 | // var += incr |
| 3125 | // var -= incr |
| 3126 | // var = var + incr |
| 3127 | // var = incr + var |
| 3128 | // var = var - incr |
| 3129 | // |
| 3130 | if (!S) { |
| 3131 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3132 | return true; |
| 3133 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3134 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3135 | S = S->IgnoreParens(); |
| 3136 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3137 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3138 | return SetStep( |
| 3139 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3140 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3141 | false); |
| 3142 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3143 | switch (BO->getOpcode()) { |
| 3144 | case BO_AddAssign: |
| 3145 | case BO_SubAssign: |
| 3146 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3147 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3148 | break; |
| 3149 | case BO_Assign: |
| 3150 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3151 | return CheckIncRHS(BO->getRHS()); |
| 3152 | break; |
| 3153 | default: |
| 3154 | break; |
| 3155 | } |
| 3156 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3157 | switch (CE->getOperator()) { |
| 3158 | case OO_PlusPlus: |
| 3159 | case OO_MinusMinus: |
| 3160 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3161 | return SetStep( |
| 3162 | SemaRef.ActOnIntegerConstant( |
| 3163 | CE->getLocStart(), |
| 3164 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3165 | false); |
| 3166 | break; |
| 3167 | case OO_PlusEqual: |
| 3168 | case OO_MinusEqual: |
| 3169 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3170 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3171 | break; |
| 3172 | case OO_Equal: |
| 3173 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3174 | return CheckIncRHS(CE->getArg(1)); |
| 3175 | break; |
| 3176 | default: |
| 3177 | break; |
| 3178 | } |
| 3179 | } |
| 3180 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3181 | << S->getSourceRange() << Var; |
| 3182 | return true; |
| 3183 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3184 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3185 | namespace { |
| 3186 | // Transform variables declared in GNU statement expressions to new ones to |
| 3187 | // avoid crash on codegen. |
| 3188 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3189 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3190 | |
| 3191 | public: |
| 3192 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3193 | |
| 3194 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3195 | if (auto *VD = cast<VarDecl>(D)) |
| 3196 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3197 | !isa<ImplicitParamDecl>(D)) { |
| 3198 | auto *NewVD = VarDecl::Create( |
| 3199 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3200 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3201 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3202 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3203 | NewVD->setInit(VD->getInit()); |
| 3204 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3205 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3206 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3207 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3208 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3209 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3210 | NewVD->setPreviousDeclInSameBlockScope( |
| 3211 | VD->isPreviousDeclInSameBlockScope()); |
| 3212 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3213 | if (VD->hasAttrs()) |
| 3214 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3215 | transformedLocalDecl(VD, NewVD); |
| 3216 | return NewVD; |
| 3217 | } |
| 3218 | return BaseTransform::TransformDefinition(Loc, D); |
| 3219 | } |
| 3220 | |
| 3221 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3222 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3223 | if (E->getDecl() != NewD) { |
| 3224 | NewD->setReferenced(); |
| 3225 | NewD->markUsed(SemaRef.Context); |
| 3226 | return DeclRefExpr::Create( |
| 3227 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3228 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3229 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3230 | } |
| 3231 | return BaseTransform::TransformDeclRefExpr(E); |
| 3232 | } |
| 3233 | }; |
| 3234 | } |
| 3235 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3236 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3237 | Expr * |
| 3238 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3239 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3240 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3241 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3242 | auto VarType = Var->getType().getNonReferenceType(); |
| 3243 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3244 | SemaRef.getLangOpts().CPlusPlus) { |
| 3245 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3246 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3247 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3248 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3249 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3250 | if (!Upper || !Lower) |
| 3251 | return nullptr; |
| 3252 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3253 | Sema::AA_Converting, |
| 3254 | /*AllowExplicit=*/true) |
| 3255 | .get(); |
| 3256 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3257 | Sema::AA_Converting, |
| 3258 | /*AllowExplicit=*/true) |
| 3259 | .get(); |
| 3260 | if (!Upper || !Lower) |
| 3261 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3262 | |
| 3263 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3264 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3265 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3266 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3267 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3268 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3269 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3270 | return nullptr; |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | if (!Diff.isUsable()) |
| 3275 | return nullptr; |
| 3276 | |
| 3277 | // Upper - Lower [- 1] |
| 3278 | if (TestIsStrictOp) |
| 3279 | Diff = SemaRef.BuildBinOp( |
| 3280 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3281 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3282 | if (!Diff.isUsable()) |
| 3283 | return nullptr; |
| 3284 | |
| 3285 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3286 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3287 | if (NewStep.isInvalid()) |
| 3288 | return nullptr; |
| 3289 | NewStep = SemaRef.PerformImplicitConversion( |
| 3290 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3291 | /*AllowExplicit=*/true); |
| 3292 | if (NewStep.isInvalid()) |
| 3293 | return nullptr; |
| 3294 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3295 | if (!Diff.isUsable()) |
| 3296 | return nullptr; |
| 3297 | |
| 3298 | // Parentheses (for dumping/debugging purposes only). |
| 3299 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3300 | if (!Diff.isUsable()) |
| 3301 | return nullptr; |
| 3302 | |
| 3303 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3304 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3305 | if (NewStep.isInvalid()) |
| 3306 | return nullptr; |
| 3307 | NewStep = SemaRef.PerformImplicitConversion( |
| 3308 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3309 | /*AllowExplicit=*/true); |
| 3310 | if (NewStep.isInvalid()) |
| 3311 | return nullptr; |
| 3312 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3313 | if (!Diff.isUsable()) |
| 3314 | return nullptr; |
| 3315 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3316 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3317 | QualType Type = Diff.get()->getType(); |
| 3318 | auto &C = SemaRef.Context; |
| 3319 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3320 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3321 | if (!Type->isIntegerType() || UseVarType) { |
| 3322 | unsigned NewSize = |
| 3323 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3324 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3325 | : Type->hasSignedIntegerRepresentation(); |
| 3326 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3327 | Diff = SemaRef.PerformImplicitConversion( |
| 3328 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3329 | if (!Diff.isUsable()) |
| 3330 | return nullptr; |
| 3331 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3332 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3333 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3334 | if (NewSize != C.getTypeSize(Type)) { |
| 3335 | if (NewSize < C.getTypeSize(Type)) { |
| 3336 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3337 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3338 | << InitSrcRange << ConditionSrcRange; |
| 3339 | } |
| 3340 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3341 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3342 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3343 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3344 | Sema::AA_Converting, true); |
| 3345 | if (!Diff.isUsable()) |
| 3346 | return nullptr; |
| 3347 | } |
| 3348 | } |
| 3349 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3350 | return Diff.get(); |
| 3351 | } |
| 3352 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3353 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3354 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3355 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3356 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3357 | TransformToNewDefs Transform(SemaRef); |
| 3358 | |
| 3359 | auto NewLB = Transform.TransformExpr(LB); |
| 3360 | auto NewUB = Transform.TransformExpr(UB); |
| 3361 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3362 | return Cond; |
| 3363 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3364 | Sema::AA_Converting, |
| 3365 | /*AllowExplicit=*/true); |
| 3366 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3367 | Sema::AA_Converting, |
| 3368 | /*AllowExplicit=*/true); |
| 3369 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3370 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3371 | auto CondExpr = SemaRef.BuildBinOp( |
| 3372 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3373 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3374 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3375 | if (CondExpr.isUsable()) { |
| 3376 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3377 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3378 | /*AllowExplicit=*/true); |
| 3379 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3380 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3381 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3382 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3383 | } |
| 3384 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3385 | /// \brief Build reference expression to the counter be used for codegen. |
| 3386 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3387 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3388 | DefaultLoc); |
| 3389 | } |
| 3390 | |
| 3391 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3392 | if (Var && !Var->isInvalidDecl()) { |
| 3393 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3394 | auto *PrivateVar = |
| 3395 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3396 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3397 | if (PrivateVar->isInvalidDecl()) |
| 3398 | return nullptr; |
| 3399 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3400 | } |
| 3401 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | /// \brief Build initization of the counter be used for codegen. |
| 3405 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3406 | |
| 3407 | /// \brief Build step of the counter be used for codegen. |
| 3408 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3409 | |
| 3410 | /// \brief Iteration space of a single for loop. |
| 3411 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3412 | /// \brief Condition of the loop. |
| 3413 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3414 | /// \brief This expression calculates the number of iterations in the loop. |
| 3415 | /// It is always possible to calculate it before starting the loop. |
| 3416 | Expr *NumIterations; |
| 3417 | /// \brief The loop counter variable. |
| 3418 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3419 | /// \brief Private loop counter variable. |
| 3420 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3421 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3422 | Expr *CounterInit; |
| 3423 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3424 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3425 | Expr *CounterStep; |
| 3426 | /// \brief Should step be subtracted? |
| 3427 | bool Subtract; |
| 3428 | /// \brief Source range of the loop init. |
| 3429 | SourceRange InitSrcRange; |
| 3430 | /// \brief Source range of the loop condition. |
| 3431 | SourceRange CondSrcRange; |
| 3432 | /// \brief Source range of the loop increment. |
| 3433 | SourceRange IncSrcRange; |
| 3434 | }; |
| 3435 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3436 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3437 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3438 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3439 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3440 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3441 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3442 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3443 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3444 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3445 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3446 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3447 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3448 | } |
| 3449 | } |
| 3450 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3451 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3452 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3453 | static bool CheckOpenMPIterationSpace( |
| 3454 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3455 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3456 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3457 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3458 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3459 | // OpenMP [2.6, Canonical Loop Form] |
| 3460 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3461 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3462 | if (!For) { |
| 3463 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3464 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3465 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3466 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3467 | if (NestedLoopCount > 1) { |
| 3468 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3469 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3470 | diag::note_omp_collapse_ordered_expr) |
| 3471 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3472 | << OrderedLoopCountExpr->getSourceRange(); |
| 3473 | else if (CollapseLoopCountExpr) |
| 3474 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3475 | diag::note_omp_collapse_ordered_expr) |
| 3476 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3477 | else |
| 3478 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3479 | diag::note_omp_collapse_ordered_expr) |
| 3480 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3481 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3482 | return true; |
| 3483 | } |
| 3484 | assert(For->getBody()); |
| 3485 | |
| 3486 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3487 | |
| 3488 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3489 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3490 | if (ISC.CheckInit(Init)) { |
| 3491 | return true; |
| 3492 | } |
| 3493 | |
| 3494 | bool HasErrors = false; |
| 3495 | |
| 3496 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3497 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3498 | |
| 3499 | // OpenMP [2.6, Canonical Loop Form] |
| 3500 | // Var is one of the following: |
| 3501 | // A variable of signed or unsigned integer type. |
| 3502 | // For C++, a variable of a random access iterator type. |
| 3503 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3504 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3505 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3506 | !VarType->isPointerType() && |
| 3507 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3508 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3509 | << SemaRef.getLangOpts().CPlusPlus; |
| 3510 | HasErrors = true; |
| 3511 | } |
| 3512 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3513 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3514 | // Construct |
| 3515 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3516 | // parallel for construct is (are) private. |
| 3517 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3518 | // with just one associated for-loop is linear with a constant-linear-step |
| 3519 | // that is the increment of the associated for-loop. |
| 3520 | // Exclude loop var from the list of variables with implicitly defined data |
| 3521 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3522 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3523 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3524 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3525 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3526 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3527 | // with just one associated for-loop may be listed in a linear clause with a |
| 3528 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3529 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3530 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3531 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3532 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3533 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3534 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3535 | auto PredeterminedCKind = |
| 3536 | isOpenMPSimdDirective(DKind) |
| 3537 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3538 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3539 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3540 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3541 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3542 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3543 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3544 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3545 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3546 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3547 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3548 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3549 | if (DVar.RefExpr == nullptr) |
| 3550 | DVar.CKind = PredeterminedCKind; |
| 3551 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3552 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3553 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3554 | // Make the loop iteration variable private (for worksharing constructs), |
| 3555 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3556 | // lastprivate (for simd directives with several collapsed or ordered |
| 3557 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3558 | if (DVar.CKind == OMPC_unknown) |
| 3559 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3560 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3561 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3564 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3565 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3566 | // Check test-expr. |
| 3567 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3568 | |
| 3569 | // Check incr-expr. |
| 3570 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3571 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3572 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3573 | return HasErrors; |
| 3574 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3575 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3576 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3577 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3578 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3579 | isOpenMPTaskLoopDirective(DKind) || |
| 3580 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3581 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3582 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3583 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3584 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3585 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3586 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3587 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3588 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3589 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3590 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3591 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3592 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3593 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3594 | ResultIterSpace.CounterInit == nullptr || |
| 3595 | ResultIterSpace.CounterStep == nullptr); |
| 3596 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3597 | return HasErrors; |
| 3598 | } |
| 3599 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3600 | /// \brief Build 'VarRef = Start. |
| 3601 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3602 | ExprResult VarRef, ExprResult Start) { |
| 3603 | TransformToNewDefs Transform(SemaRef); |
| 3604 | // Build 'VarRef = Start. |
| 3605 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3606 | if (NewStart.isInvalid()) |
| 3607 | return ExprError(); |
| 3608 | NewStart = SemaRef.PerformImplicitConversion( |
| 3609 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3610 | Sema::AA_Converting, |
| 3611 | /*AllowExplicit=*/true); |
| 3612 | if (NewStart.isInvalid()) |
| 3613 | return ExprError(); |
| 3614 | NewStart = SemaRef.PerformImplicitConversion( |
| 3615 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3616 | /*AllowExplicit=*/true); |
| 3617 | if (!NewStart.isUsable()) |
| 3618 | return ExprError(); |
| 3619 | |
| 3620 | auto Init = |
| 3621 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3622 | return Init; |
| 3623 | } |
| 3624 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3625 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3626 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3627 | SourceLocation Loc, ExprResult VarRef, |
| 3628 | ExprResult Start, ExprResult Iter, |
| 3629 | ExprResult Step, bool Subtract) { |
| 3630 | // Add parentheses (for debugging purposes only). |
| 3631 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3632 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3633 | !Step.isUsable()) |
| 3634 | return ExprError(); |
| 3635 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3636 | TransformToNewDefs Transform(SemaRef); |
| 3637 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3638 | if (NewStep.isInvalid()) |
| 3639 | return ExprError(); |
| 3640 | NewStep = SemaRef.PerformImplicitConversion( |
| 3641 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3642 | Sema::AA_Converting, |
| 3643 | /*AllowExplicit=*/true); |
| 3644 | if (NewStep.isInvalid()) |
| 3645 | return ExprError(); |
| 3646 | ExprResult Update = |
| 3647 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3648 | if (!Update.isUsable()) |
| 3649 | return ExprError(); |
| 3650 | |
| 3651 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3652 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3653 | if (NewStart.isInvalid()) |
| 3654 | return ExprError(); |
| 3655 | NewStart = SemaRef.PerformImplicitConversion( |
| 3656 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3657 | Sema::AA_Converting, |
| 3658 | /*AllowExplicit=*/true); |
| 3659 | if (NewStart.isInvalid()) |
| 3660 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3661 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3662 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3663 | if (!Update.isUsable()) |
| 3664 | return ExprError(); |
| 3665 | |
| 3666 | Update = SemaRef.PerformImplicitConversion( |
| 3667 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3668 | if (!Update.isUsable()) |
| 3669 | return ExprError(); |
| 3670 | |
| 3671 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3672 | return Update; |
| 3673 | } |
| 3674 | |
| 3675 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3676 | /// bits. |
| 3677 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3678 | Sema &SemaRef) { |
| 3679 | if (E == nullptr) |
| 3680 | return ExprError(); |
| 3681 | auto &C = SemaRef.Context; |
| 3682 | QualType OldType = E->getType(); |
| 3683 | unsigned HasBits = C.getTypeSize(OldType); |
| 3684 | if (HasBits >= Bits) |
| 3685 | return ExprResult(E); |
| 3686 | // OK to convert to signed, because new type has more bits than old. |
| 3687 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3688 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3689 | true); |
| 3690 | } |
| 3691 | |
| 3692 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3693 | /// into \a Bits bits. |
| 3694 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3695 | if (E == nullptr) |
| 3696 | return false; |
| 3697 | llvm::APSInt Result; |
| 3698 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3699 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3700 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /// \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] | 3704 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3705 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3706 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3707 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3708 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3709 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3710 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3711 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3712 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3713 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3714 | // Found 'collapse' clause - calculate collapse number. |
| 3715 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3716 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3717 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3718 | } |
| 3719 | if (OrderedLoopCountExpr) { |
| 3720 | // Found 'ordered' clause - calculate collapse number. |
| 3721 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3722 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3723 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3724 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3725 | diag::err_omp_wrong_ordered_loop_count) |
| 3726 | << OrderedLoopCountExpr->getSourceRange(); |
| 3727 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3728 | diag::note_collapse_loop_count) |
| 3729 | << CollapseLoopCountExpr->getSourceRange(); |
| 3730 | } |
| 3731 | NestedLoopCount = Result.getLimitedValue(); |
| 3732 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3733 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3734 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3735 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3736 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3737 | IterSpaces.resize(NestedLoopCount); |
| 3738 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3739 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3740 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3741 | NestedLoopCount, CollapseLoopCountExpr, |
| 3742 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3743 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3744 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3745 | // 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] | 3746 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3747 | // All loops associated with the construct must be perfectly nested; that |
| 3748 | // is, there must be no intervening code nor any OpenMP directive between |
| 3749 | // any two loops. |
| 3750 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3751 | } |
| 3752 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3753 | Built.clear(/* size */ NestedLoopCount); |
| 3754 | |
| 3755 | if (SemaRef.CurContext->isDependentContext()) |
| 3756 | return NestedLoopCount; |
| 3757 | |
| 3758 | // An example of what is generated for the following code: |
| 3759 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3760 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3761 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3762 | // for (k = 0; k < NK; ++k) |
| 3763 | // for (j = J0; j < NJ; j+=2) { |
| 3764 | // <loop body> |
| 3765 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3766 | // |
| 3767 | // We generate the code below. |
| 3768 | // Note: the loop body may be outlined in CodeGen. |
| 3769 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3770 | // iterations and operator+= to calculate counter value. |
| 3771 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3772 | // or i64 is currently supported). |
| 3773 | // |
| 3774 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3775 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3776 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3777 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3778 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3779 | // <loop body (using local i and j)> |
| 3780 | // } |
| 3781 | // i = NI; // assign final values of counters |
| 3782 | // j = NJ; |
| 3783 | // |
| 3784 | |
| 3785 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3786 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3787 | // Precondition tests if there is at least one iteration (all conditions are |
| 3788 | // true). |
| 3789 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3790 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3791 | ExprResult LastIteration32 = WidenIterationCount( |
| 3792 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3793 | N0->IgnoreImpCasts(), N0->getType(), |
| 3794 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3795 | .get(), |
| 3796 | SemaRef); |
| 3797 | ExprResult LastIteration64 = WidenIterationCount( |
| 3798 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3799 | N0->IgnoreImpCasts(), N0->getType(), |
| 3800 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3801 | .get(), |
| 3802 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3803 | |
| 3804 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3805 | return NestedLoopCount; |
| 3806 | |
| 3807 | auto &C = SemaRef.Context; |
| 3808 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3809 | |
| 3810 | Scope *CurScope = DSA.getCurScope(); |
| 3811 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3812 | if (PreCond.isUsable()) { |
| 3813 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3814 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3815 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3816 | auto N = IterSpaces[Cnt].NumIterations; |
| 3817 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3818 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3819 | LastIteration32 = SemaRef.BuildBinOp( |
| 3820 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3821 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3822 | Sema::AA_Converting, |
| 3823 | /*AllowExplicit=*/true) |
| 3824 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3825 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3826 | LastIteration64 = SemaRef.BuildBinOp( |
| 3827 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3828 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3829 | Sema::AA_Converting, |
| 3830 | /*AllowExplicit=*/true) |
| 3831 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | // Choose either the 32-bit or 64-bit version. |
| 3835 | ExprResult LastIteration = LastIteration64; |
| 3836 | if (LastIteration32.isUsable() && |
| 3837 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3838 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3839 | FitsInto( |
| 3840 | 32 /* Bits */, |
| 3841 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3842 | LastIteration64.get(), SemaRef))) |
| 3843 | LastIteration = LastIteration32; |
| 3844 | |
| 3845 | if (!LastIteration.isUsable()) |
| 3846 | return 0; |
| 3847 | |
| 3848 | // Save the number of iterations. |
| 3849 | ExprResult NumIterations = LastIteration; |
| 3850 | { |
| 3851 | LastIteration = SemaRef.BuildBinOp( |
| 3852 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3853 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3854 | if (!LastIteration.isUsable()) |
| 3855 | return 0; |
| 3856 | } |
| 3857 | |
| 3858 | // Calculate the last iteration number beforehand instead of doing this on |
| 3859 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3860 | llvm::APSInt Result; |
| 3861 | bool IsConstant = |
| 3862 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3863 | ExprResult CalcLastIteration; |
| 3864 | if (!IsConstant) { |
| 3865 | SourceLocation SaveLoc; |
| 3866 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3867 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3868 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3869 | ExprResult SaveRef = buildDeclRefExpr( |
| 3870 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3871 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3872 | SaveRef.get(), LastIteration.get()); |
| 3873 | LastIteration = SaveRef; |
| 3874 | |
| 3875 | // Prepare SaveRef + 1. |
| 3876 | NumIterations = SemaRef.BuildBinOp( |
| 3877 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3878 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3879 | if (!NumIterations.isUsable()) |
| 3880 | return 0; |
| 3881 | } |
| 3882 | |
| 3883 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3884 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3885 | QualType VType = LastIteration.get()->getType(); |
| 3886 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3887 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3888 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3889 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3890 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3891 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3892 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3893 | SemaRef.AddInitializerToDecl( |
| 3894 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3895 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3896 | |
| 3897 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3898 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3899 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3900 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3901 | /*DirectInit*/ false, |
| 3902 | /*TypeMayContainAuto*/ false); |
| 3903 | |
| 3904 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3905 | // This will be used to implement clause 'lastprivate'. |
| 3906 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3907 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3908 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3909 | SemaRef.AddInitializerToDecl( |
| 3910 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3911 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3912 | |
| 3913 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3914 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3915 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3916 | SemaRef.AddInitializerToDecl( |
| 3917 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3918 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3919 | |
| 3920 | // Build expression: UB = min(UB, LastIteration) |
| 3921 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3922 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3923 | UB.get(), LastIteration.get()); |
| 3924 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3925 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3926 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3927 | CondOp.get()); |
| 3928 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3929 | } |
| 3930 | |
| 3931 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3932 | ExprResult IV; |
| 3933 | ExprResult Init; |
| 3934 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3935 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3936 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3937 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3938 | isOpenMPTaskLoopDirective(DKind) || |
| 3939 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3940 | ? LB.get() |
| 3941 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3942 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3943 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3946 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3947 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3948 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3949 | (isOpenMPWorksharingDirective(DKind) || |
| 3950 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3951 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3952 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3953 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3954 | |
| 3955 | // Loop increment (IV = IV + 1) |
| 3956 | SourceLocation IncLoc; |
| 3957 | ExprResult Inc = |
| 3958 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3959 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3960 | if (!Inc.isUsable()) |
| 3961 | return 0; |
| 3962 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3963 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3964 | if (!Inc.isUsable()) |
| 3965 | return 0; |
| 3966 | |
| 3967 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3968 | // Used for directives with static scheduling. |
| 3969 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3970 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3971 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3972 | // LB + ST |
| 3973 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3974 | if (!NextLB.isUsable()) |
| 3975 | return 0; |
| 3976 | // LB = LB + ST |
| 3977 | NextLB = |
| 3978 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3979 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3980 | if (!NextLB.isUsable()) |
| 3981 | return 0; |
| 3982 | // UB + ST |
| 3983 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3984 | if (!NextUB.isUsable()) |
| 3985 | return 0; |
| 3986 | // UB = UB + ST |
| 3987 | NextUB = |
| 3988 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3989 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3990 | if (!NextUB.isUsable()) |
| 3991 | return 0; |
| 3992 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3993 | |
| 3994 | // Build updates and final values of the loop counters. |
| 3995 | bool HasErrors = false; |
| 3996 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3997 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3998 | Built.Updates.resize(NestedLoopCount); |
| 3999 | Built.Finals.resize(NestedLoopCount); |
| 4000 | { |
| 4001 | ExprResult Div; |
| 4002 | // Go from inner nested loop to outer. |
| 4003 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4004 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4005 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4006 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4007 | // where Div is product of previous iterations' IS.NumIters. |
| 4008 | ExprResult Iter; |
| 4009 | if (Div.isUsable()) { |
| 4010 | Iter = |
| 4011 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4012 | } else { |
| 4013 | Iter = IV; |
| 4014 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4015 | "unusable div expected on first iteration only"); |
| 4016 | } |
| 4017 | |
| 4018 | if (Cnt != 0 && Iter.isUsable()) |
| 4019 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4020 | IS.NumIterations); |
| 4021 | if (!Iter.isUsable()) { |
| 4022 | HasErrors = true; |
| 4023 | break; |
| 4024 | } |
| 4025 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4026 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4027 | auto *CounterVar = buildDeclRefExpr( |
| 4028 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4029 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4030 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4031 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4032 | IS.CounterInit); |
| 4033 | if (!Init.isUsable()) { |
| 4034 | HasErrors = true; |
| 4035 | break; |
| 4036 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4037 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4038 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4039 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4040 | if (!Update.isUsable()) { |
| 4041 | HasErrors = true; |
| 4042 | break; |
| 4043 | } |
| 4044 | |
| 4045 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4046 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4047 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4048 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4049 | if (!Final.isUsable()) { |
| 4050 | HasErrors = true; |
| 4051 | break; |
| 4052 | } |
| 4053 | |
| 4054 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4055 | if (Cnt != 0) { |
| 4056 | if (Div.isUnset()) |
| 4057 | Div = IS.NumIterations; |
| 4058 | else |
| 4059 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4060 | IS.NumIterations); |
| 4061 | |
| 4062 | // Add parentheses (for debugging purposes only). |
| 4063 | if (Div.isUsable()) |
| 4064 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4065 | if (!Div.isUsable()) { |
| 4066 | HasErrors = true; |
| 4067 | break; |
| 4068 | } |
| 4069 | } |
| 4070 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4071 | HasErrors = true; |
| 4072 | break; |
| 4073 | } |
| 4074 | // Save results |
| 4075 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4076 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4077 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4078 | Built.Updates[Cnt] = Update.get(); |
| 4079 | Built.Finals[Cnt] = Final.get(); |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | if (HasErrors) |
| 4084 | return 0; |
| 4085 | |
| 4086 | // Save results |
| 4087 | Built.IterationVarRef = IV.get(); |
| 4088 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4089 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4090 | Built.CalcLastIteration = |
| 4091 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4092 | Built.PreCond = PreCond.get(); |
| 4093 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4094 | Built.Init = Init.get(); |
| 4095 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4096 | Built.LB = LB.get(); |
| 4097 | Built.UB = UB.get(); |
| 4098 | Built.IL = IL.get(); |
| 4099 | Built.ST = ST.get(); |
| 4100 | Built.EUB = EUB.get(); |
| 4101 | Built.NLB = NextLB.get(); |
| 4102 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4103 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4104 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4107 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4108 | auto CollapseClauses = |
| 4109 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4110 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4111 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4112 | return nullptr; |
| 4113 | } |
| 4114 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4115 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4116 | auto OrderedClauses = |
| 4117 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4118 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4119 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4120 | return nullptr; |
| 4121 | } |
| 4122 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4123 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4124 | const Expr *Safelen) { |
| 4125 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4126 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4127 | Simdlen->isInstantiationDependent() || |
| 4128 | Simdlen->containsUnexpandedParameterPack()) |
| 4129 | return false; |
| 4130 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4131 | Safelen->isInstantiationDependent() || |
| 4132 | Safelen->containsUnexpandedParameterPack()) |
| 4133 | return false; |
| 4134 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4135 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4136 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4137 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4138 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4139 | if (SimdlenRes > SafelenRes) { |
| 4140 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4141 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4142 | return true; |
| 4143 | } |
| 4144 | return false; |
| 4145 | } |
| 4146 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4147 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4148 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4149 | SourceLocation EndLoc, |
| 4150 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4151 | if (!AStmt) |
| 4152 | return StmtError(); |
| 4153 | |
| 4154 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4155 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4156 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4157 | // define the nested loops number. |
| 4158 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4159 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4160 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4161 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4162 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4163 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4164 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4165 | "omp simd loop exprs were not built"); |
| 4166 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4167 | if (!CurContext->isDependentContext()) { |
| 4168 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4169 | for (auto C : Clauses) { |
| 4170 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4171 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4172 | B.NumIterations, *this, CurScope)) |
| 4173 | return StmtError(); |
| 4174 | } |
| 4175 | } |
| 4176 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4177 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4178 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4179 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4180 | OMPSafelenClause *Safelen = nullptr; |
| 4181 | OMPSimdlenClause *Simdlen = nullptr; |
| 4182 | for (auto *Clause : Clauses) { |
| 4183 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4184 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4185 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4186 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4187 | if (Safelen && Simdlen) |
| 4188 | break; |
| 4189 | } |
| 4190 | if (Simdlen && Safelen && |
| 4191 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4192 | Safelen->getSafelen())) |
| 4193 | return StmtError(); |
| 4194 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4195 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4196 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4197 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4200 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4201 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4202 | SourceLocation EndLoc, |
| 4203 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4204 | if (!AStmt) |
| 4205 | return StmtError(); |
| 4206 | |
| 4207 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4208 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4209 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4210 | // define the nested loops number. |
| 4211 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4212 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4213 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4214 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4215 | return StmtError(); |
| 4216 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4217 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4218 | "omp for loop exprs were not built"); |
| 4219 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4220 | if (!CurContext->isDependentContext()) { |
| 4221 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4222 | for (auto C : Clauses) { |
| 4223 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4224 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4225 | B.NumIterations, *this, CurScope)) |
| 4226 | return StmtError(); |
| 4227 | } |
| 4228 | } |
| 4229 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4230 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4231 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4232 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4235 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4236 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4237 | SourceLocation EndLoc, |
| 4238 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4239 | if (!AStmt) |
| 4240 | return StmtError(); |
| 4241 | |
| 4242 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4243 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4244 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4245 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4246 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4247 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4248 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4249 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4250 | if (NestedLoopCount == 0) |
| 4251 | return StmtError(); |
| 4252 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4253 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4254 | "omp for simd loop exprs were not built"); |
| 4255 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4256 | if (!CurContext->isDependentContext()) { |
| 4257 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4258 | for (auto C : Clauses) { |
| 4259 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4260 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4261 | B.NumIterations, *this, CurScope)) |
| 4262 | return StmtError(); |
| 4263 | } |
| 4264 | } |
| 4265 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4266 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4267 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4268 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4269 | OMPSafelenClause *Safelen = nullptr; |
| 4270 | OMPSimdlenClause *Simdlen = nullptr; |
| 4271 | for (auto *Clause : Clauses) { |
| 4272 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4273 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4274 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4275 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4276 | if (Safelen && Simdlen) |
| 4277 | break; |
| 4278 | } |
| 4279 | if (Simdlen && Safelen && |
| 4280 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4281 | Safelen->getSafelen())) |
| 4282 | return StmtError(); |
| 4283 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4284 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4285 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4286 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4287 | } |
| 4288 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4289 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4290 | Stmt *AStmt, |
| 4291 | SourceLocation StartLoc, |
| 4292 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4293 | if (!AStmt) |
| 4294 | return StmtError(); |
| 4295 | |
| 4296 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4297 | auto BaseStmt = AStmt; |
| 4298 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4299 | BaseStmt = CS->getCapturedStmt(); |
| 4300 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4301 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4302 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4303 | return StmtError(); |
| 4304 | // All associated statements must be '#pragma omp section' except for |
| 4305 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4306 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4307 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4308 | if (SectionStmt) |
| 4309 | Diag(SectionStmt->getLocStart(), |
| 4310 | diag::err_omp_sections_substmt_not_section); |
| 4311 | return StmtError(); |
| 4312 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4313 | cast<OMPSectionDirective>(SectionStmt) |
| 4314 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4315 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4316 | } else { |
| 4317 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4318 | return StmtError(); |
| 4319 | } |
| 4320 | |
| 4321 | getCurFunction()->setHasBranchProtectedScope(); |
| 4322 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4323 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4324 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4327 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4328 | SourceLocation StartLoc, |
| 4329 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4330 | if (!AStmt) |
| 4331 | return StmtError(); |
| 4332 | |
| 4333 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4334 | |
| 4335 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4336 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4337 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4338 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4339 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4342 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4343 | Stmt *AStmt, |
| 4344 | SourceLocation StartLoc, |
| 4345 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4346 | if (!AStmt) |
| 4347 | return StmtError(); |
| 4348 | |
| 4349 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4350 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4351 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4352 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4353 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4354 | // The copyprivate clause must not be used with the nowait clause. |
| 4355 | OMPClause *Nowait = nullptr; |
| 4356 | OMPClause *Copyprivate = nullptr; |
| 4357 | for (auto *Clause : Clauses) { |
| 4358 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4359 | Nowait = Clause; |
| 4360 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4361 | Copyprivate = Clause; |
| 4362 | if (Copyprivate && Nowait) { |
| 4363 | Diag(Copyprivate->getLocStart(), |
| 4364 | diag::err_omp_single_copyprivate_with_nowait); |
| 4365 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4366 | return StmtError(); |
| 4367 | } |
| 4368 | } |
| 4369 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4370 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4371 | } |
| 4372 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4373 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4374 | SourceLocation StartLoc, |
| 4375 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4376 | if (!AStmt) |
| 4377 | return StmtError(); |
| 4378 | |
| 4379 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4380 | |
| 4381 | getCurFunction()->setHasBranchProtectedScope(); |
| 4382 | |
| 4383 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4384 | } |
| 4385 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4386 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4387 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4388 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4389 | if (!AStmt) |
| 4390 | return StmtError(); |
| 4391 | |
| 4392 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4393 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4394 | bool ErrorFound = false; |
| 4395 | llvm::APSInt Hint; |
| 4396 | SourceLocation HintLoc; |
| 4397 | bool DependentHint = false; |
| 4398 | for (auto *C : Clauses) { |
| 4399 | if (C->getClauseKind() == OMPC_hint) { |
| 4400 | if (!DirName.getName()) { |
| 4401 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4402 | ErrorFound = true; |
| 4403 | } |
| 4404 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4405 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4406 | E->isInstantiationDependent()) |
| 4407 | DependentHint = true; |
| 4408 | else { |
| 4409 | Hint = E->EvaluateKnownConstInt(Context); |
| 4410 | HintLoc = C->getLocStart(); |
| 4411 | } |
| 4412 | } |
| 4413 | } |
| 4414 | if (ErrorFound) |
| 4415 | return StmtError(); |
| 4416 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4417 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4418 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4419 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4420 | if (HintLoc.isValid()) { |
| 4421 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4422 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4423 | } else |
| 4424 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4425 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4426 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4427 | << 1 |
| 4428 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4429 | /*Radix=*/10, /*Signed=*/false); |
| 4430 | } else |
| 4431 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4432 | } |
| 4433 | } |
| 4434 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4435 | getCurFunction()->setHasBranchProtectedScope(); |
| 4436 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4437 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4438 | Clauses, AStmt); |
| 4439 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4440 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4441 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4444 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4445 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4446 | SourceLocation EndLoc, |
| 4447 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4448 | if (!AStmt) |
| 4449 | return StmtError(); |
| 4450 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4451 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4452 | // 1.2.2 OpenMP Language Terminology |
| 4453 | // Structured block - An executable statement with a single entry at the |
| 4454 | // top and a single exit at the bottom. |
| 4455 | // The point of exit cannot be a branch out of the structured block. |
| 4456 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4457 | CS->getCapturedDecl()->setNothrow(); |
| 4458 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4459 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4460 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4461 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4462 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4463 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4464 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4465 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4466 | if (NestedLoopCount == 0) |
| 4467 | return StmtError(); |
| 4468 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4469 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4470 | "omp parallel for loop exprs were not built"); |
| 4471 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4472 | if (!CurContext->isDependentContext()) { |
| 4473 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4474 | for (auto C : Clauses) { |
| 4475 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4476 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4477 | B.NumIterations, *this, CurScope)) |
| 4478 | return StmtError(); |
| 4479 | } |
| 4480 | } |
| 4481 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4482 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4483 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4484 | NestedLoopCount, Clauses, AStmt, B, |
| 4485 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4488 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4489 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4490 | SourceLocation EndLoc, |
| 4491 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4492 | if (!AStmt) |
| 4493 | return StmtError(); |
| 4494 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4495 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4496 | // 1.2.2 OpenMP Language Terminology |
| 4497 | // Structured block - An executable statement with a single entry at the |
| 4498 | // top and a single exit at the bottom. |
| 4499 | // The point of exit cannot be a branch out of the structured block. |
| 4500 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4501 | CS->getCapturedDecl()->setNothrow(); |
| 4502 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4503 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4504 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4505 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4506 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4507 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4508 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4509 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4510 | if (NestedLoopCount == 0) |
| 4511 | return StmtError(); |
| 4512 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4513 | if (!CurContext->isDependentContext()) { |
| 4514 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4515 | for (auto C : Clauses) { |
| 4516 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4517 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4518 | B.NumIterations, *this, CurScope)) |
| 4519 | return StmtError(); |
| 4520 | } |
| 4521 | } |
| 4522 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4523 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4524 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4525 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4526 | OMPSafelenClause *Safelen = nullptr; |
| 4527 | OMPSimdlenClause *Simdlen = nullptr; |
| 4528 | for (auto *Clause : Clauses) { |
| 4529 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4530 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4531 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4532 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4533 | if (Safelen && Simdlen) |
| 4534 | break; |
| 4535 | } |
| 4536 | if (Simdlen && Safelen && |
| 4537 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4538 | Safelen->getSafelen())) |
| 4539 | return StmtError(); |
| 4540 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4541 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4542 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4543 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4544 | } |
| 4545 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4546 | StmtResult |
| 4547 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4548 | Stmt *AStmt, SourceLocation StartLoc, |
| 4549 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4550 | if (!AStmt) |
| 4551 | return StmtError(); |
| 4552 | |
| 4553 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4554 | auto BaseStmt = AStmt; |
| 4555 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4556 | BaseStmt = CS->getCapturedStmt(); |
| 4557 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4558 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4559 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4560 | return StmtError(); |
| 4561 | // All associated statements must be '#pragma omp section' except for |
| 4562 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4563 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4564 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4565 | if (SectionStmt) |
| 4566 | Diag(SectionStmt->getLocStart(), |
| 4567 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4568 | return StmtError(); |
| 4569 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4570 | cast<OMPSectionDirective>(SectionStmt) |
| 4571 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4572 | } |
| 4573 | } else { |
| 4574 | Diag(AStmt->getLocStart(), |
| 4575 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4576 | return StmtError(); |
| 4577 | } |
| 4578 | |
| 4579 | getCurFunction()->setHasBranchProtectedScope(); |
| 4580 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4581 | return OMPParallelSectionsDirective::Create( |
| 4582 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4585 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4586 | Stmt *AStmt, SourceLocation StartLoc, |
| 4587 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4588 | if (!AStmt) |
| 4589 | return StmtError(); |
| 4590 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4591 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4592 | // 1.2.2 OpenMP Language Terminology |
| 4593 | // Structured block - An executable statement with a single entry at the |
| 4594 | // top and a single exit at the bottom. |
| 4595 | // The point of exit cannot be a branch out of the structured block. |
| 4596 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4597 | CS->getCapturedDecl()->setNothrow(); |
| 4598 | |
| 4599 | getCurFunction()->setHasBranchProtectedScope(); |
| 4600 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4601 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4602 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4603 | } |
| 4604 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4605 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4606 | SourceLocation EndLoc) { |
| 4607 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4608 | } |
| 4609 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4610 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4611 | SourceLocation EndLoc) { |
| 4612 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4613 | } |
| 4614 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4615 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4616 | SourceLocation EndLoc) { |
| 4617 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4618 | } |
| 4619 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4620 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4621 | SourceLocation StartLoc, |
| 4622 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4623 | if (!AStmt) |
| 4624 | return StmtError(); |
| 4625 | |
| 4626 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4627 | |
| 4628 | getCurFunction()->setHasBranchProtectedScope(); |
| 4629 | |
| 4630 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4631 | } |
| 4632 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4633 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4634 | SourceLocation StartLoc, |
| 4635 | SourceLocation EndLoc) { |
| 4636 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4637 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4638 | } |
| 4639 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4640 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4641 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4642 | SourceLocation StartLoc, |
| 4643 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4644 | OMPClause *DependFound = nullptr; |
| 4645 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4646 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4647 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4648 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4649 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4650 | for (auto *C : Clauses) { |
| 4651 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4652 | DependFound = C; |
| 4653 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4654 | if (DependSourceClause) { |
| 4655 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4656 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4657 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4658 | ErrorFound = true; |
| 4659 | } else |
| 4660 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4661 | if (DependSinkClause) { |
| 4662 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4663 | << 0; |
| 4664 | ErrorFound = true; |
| 4665 | } |
| 4666 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4667 | if (DependSourceClause) { |
| 4668 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4669 | << 1; |
| 4670 | ErrorFound = true; |
| 4671 | } |
| 4672 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4673 | } |
| 4674 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4675 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4676 | else if (C->getClauseKind() == OMPC_simd) |
| 4677 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4678 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4679 | if (!ErrorFound && !SC && |
| 4680 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4681 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4682 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4683 | // that can appear in the simd region. |
| 4684 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4685 | ErrorFound = true; |
| 4686 | } else if (DependFound && (TC || SC)) { |
| 4687 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4688 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4689 | ErrorFound = true; |
| 4690 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4691 | Diag(DependFound->getLocStart(), |
| 4692 | diag::err_omp_ordered_directive_without_param); |
| 4693 | ErrorFound = true; |
| 4694 | } else if (TC || Clauses.empty()) { |
| 4695 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4696 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4697 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4698 | << (TC != nullptr); |
| 4699 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4700 | ErrorFound = true; |
| 4701 | } |
| 4702 | } |
| 4703 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4704 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4705 | |
| 4706 | if (AStmt) { |
| 4707 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4708 | |
| 4709 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4710 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4711 | |
| 4712 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4713 | } |
| 4714 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4715 | namespace { |
| 4716 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4717 | /// construct. |
| 4718 | class OpenMPAtomicUpdateChecker { |
| 4719 | /// \brief Error results for atomic update expressions. |
| 4720 | enum ExprAnalysisErrorCode { |
| 4721 | /// \brief A statement is not an expression statement. |
| 4722 | NotAnExpression, |
| 4723 | /// \brief Expression is not builtin binary or unary operation. |
| 4724 | NotABinaryOrUnaryExpression, |
| 4725 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4726 | NotAnUnaryIncDecExpression, |
| 4727 | /// \brief An expression is not of scalar type. |
| 4728 | NotAScalarType, |
| 4729 | /// \brief A binary operation is not an assignment operation. |
| 4730 | NotAnAssignmentOp, |
| 4731 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4732 | NotABinaryExpression, |
| 4733 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4734 | /// expression. |
| 4735 | NotABinaryOperator, |
| 4736 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4737 | /// part. |
| 4738 | NotAnUpdateExpression, |
| 4739 | /// \brief No errors is found. |
| 4740 | NoError |
| 4741 | }; |
| 4742 | /// \brief Reference to Sema. |
| 4743 | Sema &SemaRef; |
| 4744 | /// \brief A location for note diagnostics (when error is found). |
| 4745 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4746 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4747 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4748 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4749 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4750 | /// \brief Helper expression of the form |
| 4751 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4752 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4753 | Expr *UpdateExpr; |
| 4754 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4755 | /// important for non-associative operations. |
| 4756 | bool IsXLHSInRHSPart; |
| 4757 | BinaryOperatorKind Op; |
| 4758 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4759 | /// \brief true if the source expression is a postfix unary operation, false |
| 4760 | /// if it is a prefix unary operation. |
| 4761 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4762 | |
| 4763 | public: |
| 4764 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4765 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4766 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4767 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4768 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4769 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4770 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4771 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4772 | /// \param NoteId Diagnostic note for the main error message. |
| 4773 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4774 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4775 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4776 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4777 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4778 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4779 | /// \brief Return the update expression used in calculation of the updated |
| 4780 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4781 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4782 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4783 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4784 | /// false otherwise. |
| 4785 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4786 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4787 | /// \brief true if the source expression is a postfix unary operation, false |
| 4788 | /// if it is a prefix unary operation. |
| 4789 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4790 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4791 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4792 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4793 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4794 | }; |
| 4795 | } // namespace |
| 4796 | |
| 4797 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4798 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4799 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4800 | SourceLocation ErrorLoc, NoteLoc; |
| 4801 | SourceRange ErrorRange, NoteRange; |
| 4802 | // Allowed constructs are: |
| 4803 | // x = x binop expr; |
| 4804 | // x = expr binop x; |
| 4805 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4806 | X = AtomicBinOp->getLHS(); |
| 4807 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4808 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4809 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4810 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4811 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4812 | Op = AtomicInnerBinOp->getOpcode(); |
| 4813 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4814 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4815 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4816 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4817 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4818 | /*Canonical=*/true); |
| 4819 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4820 | /*Canonical=*/true); |
| 4821 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4822 | /*Canonical=*/true); |
| 4823 | if (XId == LHSId) { |
| 4824 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4825 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4826 | } else if (XId == RHSId) { |
| 4827 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4828 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4829 | } else { |
| 4830 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4831 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4832 | NoteLoc = X->getExprLoc(); |
| 4833 | NoteRange = X->getSourceRange(); |
| 4834 | ErrorFound = NotAnUpdateExpression; |
| 4835 | } |
| 4836 | } else { |
| 4837 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4838 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4839 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4840 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4841 | ErrorFound = NotABinaryOperator; |
| 4842 | } |
| 4843 | } else { |
| 4844 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4845 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4846 | ErrorFound = NotABinaryExpression; |
| 4847 | } |
| 4848 | } else { |
| 4849 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4850 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4851 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4852 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4853 | ErrorFound = NotAnAssignmentOp; |
| 4854 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4855 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4856 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4857 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4858 | return true; |
| 4859 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4860 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4861 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4865 | unsigned NoteId) { |
| 4866 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4867 | SourceLocation ErrorLoc, NoteLoc; |
| 4868 | SourceRange ErrorRange, NoteRange; |
| 4869 | // Allowed constructs are: |
| 4870 | // x++; |
| 4871 | // x--; |
| 4872 | // ++x; |
| 4873 | // --x; |
| 4874 | // x binop= expr; |
| 4875 | // x = x binop expr; |
| 4876 | // x = expr binop x; |
| 4877 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4878 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4879 | if (AtomicBody->getType()->isScalarType() || |
| 4880 | AtomicBody->isInstantiationDependent()) { |
| 4881 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4882 | AtomicBody->IgnoreParenImpCasts())) { |
| 4883 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4884 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4885 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4886 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4887 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4888 | X = AtomicCompAssignOp->getLHS(); |
| 4889 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4890 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4891 | AtomicBody->IgnoreParenImpCasts())) { |
| 4892 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4893 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4894 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4895 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4896 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4897 | // Check for Unary Operation |
| 4898 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4899 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4900 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4901 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4902 | X = AtomicUnaryOp->getSubExpr(); |
| 4903 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4904 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4905 | } else { |
| 4906 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4907 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4908 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4909 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4910 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4911 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4912 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4913 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4914 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4915 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4916 | } |
| 4917 | } else { |
| 4918 | ErrorFound = NotAScalarType; |
| 4919 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4920 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4921 | } |
| 4922 | } else { |
| 4923 | ErrorFound = NotAnExpression; |
| 4924 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4925 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4926 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4927 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4928 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4929 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4930 | return true; |
| 4931 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4932 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4933 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4934 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4935 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4936 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4937 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4938 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4939 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4940 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4941 | auto Update = |
| 4942 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4943 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4944 | if (Update.isInvalid()) |
| 4945 | return true; |
| 4946 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4947 | Sema::AA_Casting); |
| 4948 | if (Update.isInvalid()) |
| 4949 | return true; |
| 4950 | UpdateExpr = Update.get(); |
| 4951 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4952 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4955 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4956 | Stmt *AStmt, |
| 4957 | SourceLocation StartLoc, |
| 4958 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4959 | if (!AStmt) |
| 4960 | return StmtError(); |
| 4961 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4962 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4963 | // 1.2.2 OpenMP Language Terminology |
| 4964 | // Structured block - An executable statement with a single entry at the |
| 4965 | // top and a single exit at the bottom. |
| 4966 | // The point of exit cannot be a branch out of the structured block. |
| 4967 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4968 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4969 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4970 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4971 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4972 | C->getClauseKind() == OMPC_update || |
| 4973 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4974 | if (AtomicKind != OMPC_unknown) { |
| 4975 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4976 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4977 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4978 | << getOpenMPClauseName(AtomicKind); |
| 4979 | } else { |
| 4980 | AtomicKind = C->getClauseKind(); |
| 4981 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4985 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4986 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4987 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4988 | Body = EWC->getSubExpr(); |
| 4989 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4990 | Expr *X = nullptr; |
| 4991 | Expr *V = nullptr; |
| 4992 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4993 | Expr *UE = nullptr; |
| 4994 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4995 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4996 | // OpenMP [2.12.6, atomic Construct] |
| 4997 | // In the next expressions: |
| 4998 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4999 | // * During the execution of an atomic region, multiple syntactic |
| 5000 | // occurrences of x must designate the same storage location. |
| 5001 | // * Neither of v and expr (as applicable) may access the storage location |
| 5002 | // designated by x. |
| 5003 | // * Neither of x and expr (as applicable) may access the storage location |
| 5004 | // designated by v. |
| 5005 | // * expr is an expression with scalar type. |
| 5006 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5007 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5008 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5009 | // (expr). This requirement is satisfied if the operators in expr have |
| 5010 | // precedence greater than binop, or by using parentheses around expr or |
| 5011 | // subexpressions of expr. |
| 5012 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5013 | // binop x. This requirement is satisfied if the operators in expr have |
| 5014 | // precedence equal to or greater than binop, or by using parentheses around |
| 5015 | // expr or subexpressions of expr. |
| 5016 | // * For forms that allow multiple occurrences of x, the number of times |
| 5017 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5018 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5019 | enum { |
| 5020 | NotAnExpression, |
| 5021 | NotAnAssignmentOp, |
| 5022 | NotAScalarType, |
| 5023 | NotAnLValue, |
| 5024 | NoError |
| 5025 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5026 | SourceLocation ErrorLoc, NoteLoc; |
| 5027 | SourceRange ErrorRange, NoteRange; |
| 5028 | // If clause is read: |
| 5029 | // v = x; |
| 5030 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5031 | auto AtomicBinOp = |
| 5032 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5033 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5034 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5035 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5036 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5037 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5038 | if (!X->isLValue() || !V->isLValue()) { |
| 5039 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5040 | ErrorFound = NotAnLValue; |
| 5041 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5042 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5043 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5044 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5045 | } |
| 5046 | } else if (!X->isInstantiationDependent() || |
| 5047 | !V->isInstantiationDependent()) { |
| 5048 | auto NotScalarExpr = |
| 5049 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5050 | ? V |
| 5051 | : X; |
| 5052 | ErrorFound = NotAScalarType; |
| 5053 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5054 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5055 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5056 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5057 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5058 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5059 | ErrorFound = NotAnAssignmentOp; |
| 5060 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5061 | ErrorRange = AtomicBody->getSourceRange(); |
| 5062 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5063 | : AtomicBody->getExprLoc(); |
| 5064 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5065 | : AtomicBody->getSourceRange(); |
| 5066 | } |
| 5067 | } else { |
| 5068 | ErrorFound = NotAnExpression; |
| 5069 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5070 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5071 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5072 | if (ErrorFound != NoError) { |
| 5073 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5074 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5075 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5076 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5077 | return StmtError(); |
| 5078 | } else if (CurContext->isDependentContext()) |
| 5079 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5080 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5081 | enum { |
| 5082 | NotAnExpression, |
| 5083 | NotAnAssignmentOp, |
| 5084 | NotAScalarType, |
| 5085 | NotAnLValue, |
| 5086 | NoError |
| 5087 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5088 | SourceLocation ErrorLoc, NoteLoc; |
| 5089 | SourceRange ErrorRange, NoteRange; |
| 5090 | // If clause is write: |
| 5091 | // x = expr; |
| 5092 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5093 | auto AtomicBinOp = |
| 5094 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5095 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5096 | X = AtomicBinOp->getLHS(); |
| 5097 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5098 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5099 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5100 | if (!X->isLValue()) { |
| 5101 | ErrorFound = NotAnLValue; |
| 5102 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5103 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5104 | NoteLoc = X->getExprLoc(); |
| 5105 | NoteRange = X->getSourceRange(); |
| 5106 | } |
| 5107 | } else if (!X->isInstantiationDependent() || |
| 5108 | !E->isInstantiationDependent()) { |
| 5109 | auto NotScalarExpr = |
| 5110 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5111 | ? E |
| 5112 | : X; |
| 5113 | ErrorFound = NotAScalarType; |
| 5114 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5115 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5116 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5117 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5118 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5119 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5120 | ErrorFound = NotAnAssignmentOp; |
| 5121 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5122 | ErrorRange = AtomicBody->getSourceRange(); |
| 5123 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5124 | : AtomicBody->getExprLoc(); |
| 5125 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5126 | : AtomicBody->getSourceRange(); |
| 5127 | } |
| 5128 | } else { |
| 5129 | ErrorFound = NotAnExpression; |
| 5130 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5131 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5132 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5133 | if (ErrorFound != NoError) { |
| 5134 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5135 | << ErrorRange; |
| 5136 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5137 | << NoteRange; |
| 5138 | return StmtError(); |
| 5139 | } else if (CurContext->isDependentContext()) |
| 5140 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5141 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5142 | // If clause is update: |
| 5143 | // x++; |
| 5144 | // x--; |
| 5145 | // ++x; |
| 5146 | // --x; |
| 5147 | // x binop= expr; |
| 5148 | // x = x binop expr; |
| 5149 | // x = expr binop x; |
| 5150 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5151 | if (Checker.checkStatement( |
| 5152 | Body, (AtomicKind == OMPC_update) |
| 5153 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5154 | : diag::err_omp_atomic_not_expression_statement, |
| 5155 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5156 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5157 | if (!CurContext->isDependentContext()) { |
| 5158 | E = Checker.getExpr(); |
| 5159 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5160 | UE = Checker.getUpdateExpr(); |
| 5161 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5162 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5163 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5164 | enum { |
| 5165 | NotAnAssignmentOp, |
| 5166 | NotACompoundStatement, |
| 5167 | NotTwoSubstatements, |
| 5168 | NotASpecificExpression, |
| 5169 | NoError |
| 5170 | } ErrorFound = NoError; |
| 5171 | SourceLocation ErrorLoc, NoteLoc; |
| 5172 | SourceRange ErrorRange, NoteRange; |
| 5173 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5174 | // If clause is a capture: |
| 5175 | // v = x++; |
| 5176 | // v = x--; |
| 5177 | // v = ++x; |
| 5178 | // v = --x; |
| 5179 | // v = x binop= expr; |
| 5180 | // v = x = x binop expr; |
| 5181 | // v = x = expr binop x; |
| 5182 | auto *AtomicBinOp = |
| 5183 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5184 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5185 | V = AtomicBinOp->getLHS(); |
| 5186 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5187 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5188 | if (Checker.checkStatement( |
| 5189 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5190 | diag::note_omp_atomic_update)) |
| 5191 | return StmtError(); |
| 5192 | E = Checker.getExpr(); |
| 5193 | X = Checker.getX(); |
| 5194 | UE = Checker.getUpdateExpr(); |
| 5195 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5196 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5197 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5198 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5199 | ErrorRange = AtomicBody->getSourceRange(); |
| 5200 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5201 | : AtomicBody->getExprLoc(); |
| 5202 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5203 | : AtomicBody->getSourceRange(); |
| 5204 | ErrorFound = NotAnAssignmentOp; |
| 5205 | } |
| 5206 | if (ErrorFound != NoError) { |
| 5207 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5208 | << ErrorRange; |
| 5209 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5210 | return StmtError(); |
| 5211 | } else if (CurContext->isDependentContext()) { |
| 5212 | UE = V = E = X = nullptr; |
| 5213 | } |
| 5214 | } else { |
| 5215 | // If clause is a capture: |
| 5216 | // { v = x; x = expr; } |
| 5217 | // { v = x; x++; } |
| 5218 | // { v = x; x--; } |
| 5219 | // { v = x; ++x; } |
| 5220 | // { v = x; --x; } |
| 5221 | // { v = x; x binop= expr; } |
| 5222 | // { v = x; x = x binop expr; } |
| 5223 | // { v = x; x = expr binop x; } |
| 5224 | // { x++; v = x; } |
| 5225 | // { x--; v = x; } |
| 5226 | // { ++x; v = x; } |
| 5227 | // { --x; v = x; } |
| 5228 | // { x binop= expr; v = x; } |
| 5229 | // { x = x binop expr; v = x; } |
| 5230 | // { x = expr binop x; v = x; } |
| 5231 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5232 | // Check that this is { expr1; expr2; } |
| 5233 | if (CS->size() == 2) { |
| 5234 | auto *First = CS->body_front(); |
| 5235 | auto *Second = CS->body_back(); |
| 5236 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5237 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5238 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5239 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5240 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5241 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5242 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5243 | BinaryOperator *BinOp = nullptr; |
| 5244 | if (IsUpdateExprFound) { |
| 5245 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5246 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5247 | } |
| 5248 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5249 | // { v = x; x++; } |
| 5250 | // { v = x; x--; } |
| 5251 | // { v = x; ++x; } |
| 5252 | // { v = x; --x; } |
| 5253 | // { v = x; x binop= expr; } |
| 5254 | // { v = x; x = x binop expr; } |
| 5255 | // { v = x; x = expr binop x; } |
| 5256 | // Check that the first expression has form v = x. |
| 5257 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5258 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5259 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5260 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5261 | IsUpdateExprFound = XId == PossibleXId; |
| 5262 | if (IsUpdateExprFound) { |
| 5263 | V = BinOp->getLHS(); |
| 5264 | X = Checker.getX(); |
| 5265 | E = Checker.getExpr(); |
| 5266 | UE = Checker.getUpdateExpr(); |
| 5267 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5268 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5269 | } |
| 5270 | } |
| 5271 | if (!IsUpdateExprFound) { |
| 5272 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5273 | BinOp = nullptr; |
| 5274 | if (IsUpdateExprFound) { |
| 5275 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5276 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5277 | } |
| 5278 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5279 | // { x++; v = x; } |
| 5280 | // { x--; v = x; } |
| 5281 | // { ++x; v = x; } |
| 5282 | // { --x; v = x; } |
| 5283 | // { x binop= expr; v = x; } |
| 5284 | // { x = x binop expr; v = x; } |
| 5285 | // { x = expr binop x; v = x; } |
| 5286 | // Check that the second expression has form v = x. |
| 5287 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5288 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5289 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5290 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5291 | IsUpdateExprFound = XId == PossibleXId; |
| 5292 | if (IsUpdateExprFound) { |
| 5293 | V = BinOp->getLHS(); |
| 5294 | X = Checker.getX(); |
| 5295 | E = Checker.getExpr(); |
| 5296 | UE = Checker.getUpdateExpr(); |
| 5297 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5298 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5299 | } |
| 5300 | } |
| 5301 | } |
| 5302 | if (!IsUpdateExprFound) { |
| 5303 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5304 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5305 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5306 | if (!FirstExpr || !SecondExpr || |
| 5307 | !(FirstExpr->isInstantiationDependent() || |
| 5308 | SecondExpr->isInstantiationDependent())) { |
| 5309 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5310 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5311 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5312 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5313 | : First->getLocStart(); |
| 5314 | NoteRange = ErrorRange = FirstBinOp |
| 5315 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5316 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5317 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5318 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5319 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5320 | ErrorFound = NotAnAssignmentOp; |
| 5321 | NoteLoc = ErrorLoc = SecondBinOp |
| 5322 | ? SecondBinOp->getOperatorLoc() |
| 5323 | : Second->getLocStart(); |
| 5324 | NoteRange = ErrorRange = |
| 5325 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5326 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5327 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5328 | auto *PossibleXRHSInFirst = |
| 5329 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5330 | auto *PossibleXLHSInSecond = |
| 5331 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5332 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5333 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5334 | /*Canonical=*/true); |
| 5335 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5336 | /*Canonical=*/true); |
| 5337 | IsUpdateExprFound = X1Id == X2Id; |
| 5338 | if (IsUpdateExprFound) { |
| 5339 | V = FirstBinOp->getLHS(); |
| 5340 | X = SecondBinOp->getLHS(); |
| 5341 | E = SecondBinOp->getRHS(); |
| 5342 | UE = nullptr; |
| 5343 | IsXLHSInRHSPart = false; |
| 5344 | IsPostfixUpdate = true; |
| 5345 | } else { |
| 5346 | ErrorFound = NotASpecificExpression; |
| 5347 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5348 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5349 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5350 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5351 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | } |
| 5355 | } |
| 5356 | } else { |
| 5357 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5358 | NoteRange = ErrorRange = |
| 5359 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5360 | ErrorFound = NotTwoSubstatements; |
| 5361 | } |
| 5362 | } else { |
| 5363 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5364 | NoteRange = ErrorRange = |
| 5365 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5366 | ErrorFound = NotACompoundStatement; |
| 5367 | } |
| 5368 | if (ErrorFound != NoError) { |
| 5369 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5370 | << ErrorRange; |
| 5371 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5372 | return StmtError(); |
| 5373 | } else if (CurContext->isDependentContext()) { |
| 5374 | UE = V = E = X = nullptr; |
| 5375 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5376 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5377 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5378 | |
| 5379 | getCurFunction()->setHasBranchProtectedScope(); |
| 5380 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5381 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5382 | X, V, E, UE, IsXLHSInRHSPart, |
| 5383 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5384 | } |
| 5385 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5386 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5387 | Stmt *AStmt, |
| 5388 | SourceLocation StartLoc, |
| 5389 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5390 | if (!AStmt) |
| 5391 | return StmtError(); |
| 5392 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5393 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5394 | // 1.2.2 OpenMP Language Terminology |
| 5395 | // Structured block - An executable statement with a single entry at the |
| 5396 | // top and a single exit at the bottom. |
| 5397 | // The point of exit cannot be a branch out of the structured block. |
| 5398 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5399 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5400 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5401 | // OpenMP [2.16, Nesting of Regions] |
| 5402 | // If specified, a teams construct must be contained within a target |
| 5403 | // construct. That target construct must contain no statements or directives |
| 5404 | // outside of the teams construct. |
| 5405 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5406 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5407 | bool OMPTeamsFound = true; |
| 5408 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5409 | auto I = CS->body_begin(); |
| 5410 | while (I != CS->body_end()) { |
| 5411 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5412 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5413 | OMPTeamsFound = false; |
| 5414 | break; |
| 5415 | } |
| 5416 | ++I; |
| 5417 | } |
| 5418 | assert(I != CS->body_end() && "Not found statement"); |
| 5419 | S = *I; |
| 5420 | } |
| 5421 | if (!OMPTeamsFound) { |
| 5422 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5423 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5424 | diag::note_omp_nested_teams_construct_here); |
| 5425 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5426 | << isa<OMPExecutableDirective>(S); |
| 5427 | return StmtError(); |
| 5428 | } |
| 5429 | } |
| 5430 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5431 | getCurFunction()->setHasBranchProtectedScope(); |
| 5432 | |
| 5433 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5434 | } |
| 5435 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5436 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5437 | Stmt *AStmt, |
| 5438 | SourceLocation StartLoc, |
| 5439 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5440 | if (!AStmt) |
| 5441 | return StmtError(); |
| 5442 | |
| 5443 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5444 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5445 | getCurFunction()->setHasBranchProtectedScope(); |
| 5446 | |
| 5447 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5448 | AStmt); |
| 5449 | } |
| 5450 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5451 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5452 | Stmt *AStmt, SourceLocation StartLoc, |
| 5453 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5454 | if (!AStmt) |
| 5455 | return StmtError(); |
| 5456 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5457 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5458 | // 1.2.2 OpenMP Language Terminology |
| 5459 | // Structured block - An executable statement with a single entry at the |
| 5460 | // top and a single exit at the bottom. |
| 5461 | // The point of exit cannot be a branch out of the structured block. |
| 5462 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5463 | CS->getCapturedDecl()->setNothrow(); |
| 5464 | |
| 5465 | getCurFunction()->setHasBranchProtectedScope(); |
| 5466 | |
| 5467 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5468 | } |
| 5469 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5470 | StmtResult |
| 5471 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5472 | SourceLocation EndLoc, |
| 5473 | OpenMPDirectiveKind CancelRegion) { |
| 5474 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5475 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5476 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5477 | << getOpenMPDirectiveName(CancelRegion); |
| 5478 | return StmtError(); |
| 5479 | } |
| 5480 | if (DSAStack->isParentNowaitRegion()) { |
| 5481 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5482 | return StmtError(); |
| 5483 | } |
| 5484 | if (DSAStack->isParentOrderedRegion()) { |
| 5485 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5486 | return StmtError(); |
| 5487 | } |
| 5488 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5489 | CancelRegion); |
| 5490 | } |
| 5491 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5492 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5493 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5494 | SourceLocation EndLoc, |
| 5495 | OpenMPDirectiveKind CancelRegion) { |
| 5496 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5497 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5498 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5499 | << getOpenMPDirectiveName(CancelRegion); |
| 5500 | return StmtError(); |
| 5501 | } |
| 5502 | if (DSAStack->isParentNowaitRegion()) { |
| 5503 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5504 | return StmtError(); |
| 5505 | } |
| 5506 | if (DSAStack->isParentOrderedRegion()) { |
| 5507 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5508 | return StmtError(); |
| 5509 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5510 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5511 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5512 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5515 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5516 | ArrayRef<OMPClause *> Clauses) { |
| 5517 | OMPClause *PrevClause = nullptr; |
| 5518 | bool ErrorFound = false; |
| 5519 | for (auto *C : Clauses) { |
| 5520 | if (C->getClauseKind() == OMPC_grainsize || |
| 5521 | C->getClauseKind() == OMPC_num_tasks) { |
| 5522 | if (!PrevClause) |
| 5523 | PrevClause = C; |
| 5524 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5525 | S.Diag(C->getLocStart(), |
| 5526 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5527 | << getOpenMPClauseName(C->getClauseKind()) |
| 5528 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5529 | S.Diag(PrevClause->getLocStart(), |
| 5530 | diag::note_omp_previous_grainsize_num_tasks) |
| 5531 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5532 | ErrorFound = true; |
| 5533 | } |
| 5534 | } |
| 5535 | } |
| 5536 | return ErrorFound; |
| 5537 | } |
| 5538 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5539 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5540 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5541 | SourceLocation EndLoc, |
| 5542 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5543 | if (!AStmt) |
| 5544 | return StmtError(); |
| 5545 | |
| 5546 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5547 | OMPLoopDirective::HelperExprs B; |
| 5548 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5549 | // define the nested loops number. |
| 5550 | unsigned NestedLoopCount = |
| 5551 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5552 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5553 | VarsWithImplicitDSA, B); |
| 5554 | if (NestedLoopCount == 0) |
| 5555 | return StmtError(); |
| 5556 | |
| 5557 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5558 | "omp for loop exprs were not built"); |
| 5559 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5560 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5561 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5562 | // not appear on the same taskloop directive. |
| 5563 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5564 | return StmtError(); |
| 5565 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5566 | getCurFunction()->setHasBranchProtectedScope(); |
| 5567 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5568 | NestedLoopCount, Clauses, AStmt, B); |
| 5569 | } |
| 5570 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5571 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5572 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5573 | SourceLocation EndLoc, |
| 5574 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5575 | if (!AStmt) |
| 5576 | return StmtError(); |
| 5577 | |
| 5578 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5579 | OMPLoopDirective::HelperExprs B; |
| 5580 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5581 | // define the nested loops number. |
| 5582 | unsigned NestedLoopCount = |
| 5583 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5584 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5585 | VarsWithImplicitDSA, B); |
| 5586 | if (NestedLoopCount == 0) |
| 5587 | return StmtError(); |
| 5588 | |
| 5589 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5590 | "omp for loop exprs were not built"); |
| 5591 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5592 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5593 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5594 | // not appear on the same taskloop directive. |
| 5595 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5596 | return StmtError(); |
| 5597 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5598 | getCurFunction()->setHasBranchProtectedScope(); |
| 5599 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5600 | NestedLoopCount, Clauses, AStmt, B); |
| 5601 | } |
| 5602 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5603 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5604 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5605 | SourceLocation EndLoc, |
| 5606 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5607 | if (!AStmt) |
| 5608 | return StmtError(); |
| 5609 | |
| 5610 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5611 | OMPLoopDirective::HelperExprs B; |
| 5612 | // In presence of clause 'collapse' with number of loops, it will |
| 5613 | // define the nested loops number. |
| 5614 | unsigned NestedLoopCount = |
| 5615 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5616 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5617 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5618 | if (NestedLoopCount == 0) |
| 5619 | return StmtError(); |
| 5620 | |
| 5621 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5622 | "omp for loop exprs were not built"); |
| 5623 | |
| 5624 | getCurFunction()->setHasBranchProtectedScope(); |
| 5625 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5626 | NestedLoopCount, Clauses, AStmt, B); |
| 5627 | } |
| 5628 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5629 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5630 | SourceLocation StartLoc, |
| 5631 | SourceLocation LParenLoc, |
| 5632 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5633 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5634 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5635 | case OMPC_final: |
| 5636 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5637 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5638 | case OMPC_num_threads: |
| 5639 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5640 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5641 | case OMPC_safelen: |
| 5642 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5643 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5644 | case OMPC_simdlen: |
| 5645 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5646 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5647 | case OMPC_collapse: |
| 5648 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5649 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5650 | case OMPC_ordered: |
| 5651 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5652 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5653 | case OMPC_device: |
| 5654 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5655 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5656 | case OMPC_num_teams: |
| 5657 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5658 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5659 | case OMPC_thread_limit: |
| 5660 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5661 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5662 | case OMPC_priority: |
| 5663 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5664 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5665 | case OMPC_grainsize: |
| 5666 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5667 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5668 | case OMPC_num_tasks: |
| 5669 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5670 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5671 | case OMPC_hint: |
| 5672 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5673 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5674 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5675 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5676 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5677 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5678 | case OMPC_private: |
| 5679 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5680 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5681 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5682 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5683 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5684 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5685 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5686 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5687 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5688 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5689 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5690 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5691 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5692 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5693 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5694 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5695 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5696 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5697 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5698 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5699 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5700 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5701 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 5702 | case OMPC_dist_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5703 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5704 | llvm_unreachable("Clause is not allowed."); |
| 5705 | } |
| 5706 | return Res; |
| 5707 | } |
| 5708 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5709 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5710 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5711 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5712 | SourceLocation NameModifierLoc, |
| 5713 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5714 | SourceLocation EndLoc) { |
| 5715 | Expr *ValExpr = Condition; |
| 5716 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5717 | !Condition->isInstantiationDependent() && |
| 5718 | !Condition->containsUnexpandedParameterPack()) { |
| 5719 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5720 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5721 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5722 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5723 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5724 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5727 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5728 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5731 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5732 | SourceLocation StartLoc, |
| 5733 | SourceLocation LParenLoc, |
| 5734 | SourceLocation EndLoc) { |
| 5735 | Expr *ValExpr = Condition; |
| 5736 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5737 | !Condition->isInstantiationDependent() && |
| 5738 | !Condition->containsUnexpandedParameterPack()) { |
| 5739 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5740 | Condition->getExprLoc(), Condition); |
| 5741 | if (Val.isInvalid()) |
| 5742 | return nullptr; |
| 5743 | |
| 5744 | ValExpr = Val.get(); |
| 5745 | } |
| 5746 | |
| 5747 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5748 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5749 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5750 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5751 | if (!Op) |
| 5752 | return ExprError(); |
| 5753 | |
| 5754 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5755 | public: |
| 5756 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5757 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5758 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5759 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5760 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5761 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5762 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5763 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5764 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5765 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5766 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5767 | QualType T, |
| 5768 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5769 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5770 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5771 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5772 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5773 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5774 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5775 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5776 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5777 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5778 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5779 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5780 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5781 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5782 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5783 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5784 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5785 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5786 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5787 | llvm_unreachable("conversion functions are permitted"); |
| 5788 | } |
| 5789 | } ConvertDiagnoser; |
| 5790 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5791 | } |
| 5792 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5793 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5794 | OpenMPClauseKind CKind, |
| 5795 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5796 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5797 | !ValExpr->isInstantiationDependent()) { |
| 5798 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5799 | ExprResult Value = |
| 5800 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5801 | if (Value.isInvalid()) |
| 5802 | return false; |
| 5803 | |
| 5804 | ValExpr = Value.get(); |
| 5805 | // The expression must evaluate to a non-negative integer value. |
| 5806 | llvm::APSInt Result; |
| 5807 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5808 | Result.isSigned() && |
| 5809 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5810 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5811 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5812 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5813 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5814 | return false; |
| 5815 | } |
| 5816 | } |
| 5817 | return true; |
| 5818 | } |
| 5819 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5820 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5821 | SourceLocation StartLoc, |
| 5822 | SourceLocation LParenLoc, |
| 5823 | SourceLocation EndLoc) { |
| 5824 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5825 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5826 | // OpenMP [2.5, Restrictions] |
| 5827 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5828 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5829 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5830 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5831 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5832 | return new (Context) |
| 5833 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5836 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5837 | OpenMPClauseKind CKind, |
| 5838 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5839 | if (!E) |
| 5840 | return ExprError(); |
| 5841 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5842 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5843 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5844 | llvm::APSInt Result; |
| 5845 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5846 | if (ICE.isInvalid()) |
| 5847 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5848 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 5849 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5850 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5851 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5852 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5853 | return ExprError(); |
| 5854 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5855 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5856 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5857 | << E->getSourceRange(); |
| 5858 | return ExprError(); |
| 5859 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5860 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 5861 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5862 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5863 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5864 | return ICE; |
| 5865 | } |
| 5866 | |
| 5867 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5868 | SourceLocation LParenLoc, |
| 5869 | SourceLocation EndLoc) { |
| 5870 | // OpenMP [2.8.1, simd construct, Description] |
| 5871 | // The parameter of the safelen clause must be a constant |
| 5872 | // positive integer expression. |
| 5873 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5874 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5875 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5876 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5877 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5880 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5881 | SourceLocation LParenLoc, |
| 5882 | SourceLocation EndLoc) { |
| 5883 | // OpenMP [2.8.1, simd construct, Description] |
| 5884 | // The parameter of the simdlen clause must be a constant |
| 5885 | // positive integer expression. |
| 5886 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5887 | if (Simdlen.isInvalid()) |
| 5888 | return nullptr; |
| 5889 | return new (Context) |
| 5890 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5891 | } |
| 5892 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5893 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5894 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5895 | SourceLocation LParenLoc, |
| 5896 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5897 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5898 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5899 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5900 | // The parameter of the collapse clause must be a constant |
| 5901 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5902 | ExprResult NumForLoopsResult = |
| 5903 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5904 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5905 | return nullptr; |
| 5906 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5907 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5908 | } |
| 5909 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5910 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5911 | SourceLocation EndLoc, |
| 5912 | SourceLocation LParenLoc, |
| 5913 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5914 | // OpenMP [2.7.1, loop construct, Description] |
| 5915 | // OpenMP [2.8.1, simd construct, Description] |
| 5916 | // OpenMP [2.9.6, distribute construct, Description] |
| 5917 | // The parameter of the ordered clause must be a constant |
| 5918 | // positive integer expression if any. |
| 5919 | if (NumForLoops && LParenLoc.isValid()) { |
| 5920 | ExprResult NumForLoopsResult = |
| 5921 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5922 | if (NumForLoopsResult.isInvalid()) |
| 5923 | return nullptr; |
| 5924 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5925 | } else |
| 5926 | NumForLoops = nullptr; |
| 5927 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5928 | return new (Context) |
| 5929 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5930 | } |
| 5931 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5932 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5933 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5934 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5935 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5936 | switch (Kind) { |
| 5937 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5938 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5939 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5940 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5941 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5942 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5943 | Res = ActOnOpenMPProcBindClause( |
| 5944 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5945 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5946 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5947 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5948 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5949 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5950 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5951 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5952 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5953 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5954 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5955 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5956 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5957 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5958 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5959 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5960 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5961 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5962 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5963 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5964 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5965 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5966 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5967 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5968 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5969 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5970 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5971 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5972 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5973 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5974 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5975 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5976 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5977 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5978 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5979 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5980 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5981 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5982 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5983 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5984 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5985 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 5986 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5987 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5988 | llvm_unreachable("Clause is not allowed."); |
| 5989 | } |
| 5990 | return Res; |
| 5991 | } |
| 5992 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 5993 | static std::string |
| 5994 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 5995 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 5996 | std::string Values; |
| 5997 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 5998 | unsigned Skipped = Exclude.size(); |
| 5999 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6000 | for (unsigned i = First; i < Last; ++i) { |
| 6001 | if (std::find(S, E, i) != E) { |
| 6002 | --Skipped; |
| 6003 | continue; |
| 6004 | } |
| 6005 | Values += "'"; |
| 6006 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6007 | Values += "'"; |
| 6008 | if (i == Bound - Skipped) |
| 6009 | Values += " or "; |
| 6010 | else if (i != Bound + 1 - Skipped) |
| 6011 | Values += ", "; |
| 6012 | } |
| 6013 | return Values; |
| 6014 | } |
| 6015 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6016 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6017 | SourceLocation KindKwLoc, |
| 6018 | SourceLocation StartLoc, |
| 6019 | SourceLocation LParenLoc, |
| 6020 | SourceLocation EndLoc) { |
| 6021 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6022 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6023 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6024 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6025 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6026 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6027 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6028 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6029 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6030 | switch (Kind) { |
| 6031 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6032 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6033 | break; |
| 6034 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6035 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6036 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6037 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6038 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6039 | break; |
| 6040 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6041 | return new (Context) |
| 6042 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6043 | } |
| 6044 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6045 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6046 | SourceLocation KindKwLoc, |
| 6047 | SourceLocation StartLoc, |
| 6048 | SourceLocation LParenLoc, |
| 6049 | SourceLocation EndLoc) { |
| 6050 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6051 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6052 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6053 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6054 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6055 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6056 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6057 | return new (Context) |
| 6058 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6059 | } |
| 6060 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6061 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6062 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6063 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6064 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6065 | SourceLocation EndLoc) { |
| 6066 | OMPClause *Res = nullptr; |
| 6067 | switch (Kind) { |
| 6068 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6069 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6070 | assert(Argument.size() == NumberOfElements && |
| 6071 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6072 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6073 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6074 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6075 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6076 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6077 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6078 | break; |
| 6079 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6080 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6081 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6082 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6083 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6084 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6085 | case OMPC_dist_schedule: |
| 6086 | Res = ActOnOpenMPDistScheduleClause( |
| 6087 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6088 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6089 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6090 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6091 | case OMPC_num_threads: |
| 6092 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6093 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6094 | case OMPC_collapse: |
| 6095 | case OMPC_default: |
| 6096 | case OMPC_proc_bind: |
| 6097 | case OMPC_private: |
| 6098 | case OMPC_firstprivate: |
| 6099 | case OMPC_lastprivate: |
| 6100 | case OMPC_shared: |
| 6101 | case OMPC_reduction: |
| 6102 | case OMPC_linear: |
| 6103 | case OMPC_aligned: |
| 6104 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6105 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6106 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6107 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6108 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6109 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6110 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6111 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6112 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6113 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6114 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6115 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6116 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6117 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6118 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6119 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6120 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6121 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6122 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6123 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6124 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6125 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6126 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6127 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6128 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6129 | case OMPC_unknown: |
| 6130 | llvm_unreachable("Clause is not allowed."); |
| 6131 | } |
| 6132 | return Res; |
| 6133 | } |
| 6134 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6135 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6136 | OpenMPScheduleClauseModifier M2, |
| 6137 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6138 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6139 | SmallVector<unsigned, 2> Excluded; |
| 6140 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6141 | Excluded.push_back(M2); |
| 6142 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6143 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6144 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6145 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6146 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6147 | << getListOfPossibleValues(OMPC_schedule, |
| 6148 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6149 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6150 | Excluded) |
| 6151 | << getOpenMPClauseName(OMPC_schedule); |
| 6152 | return true; |
| 6153 | } |
| 6154 | return false; |
| 6155 | } |
| 6156 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6157 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6158 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6159 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6160 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6161 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6162 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6163 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6164 | return nullptr; |
| 6165 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6166 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6167 | // but not both. |
| 6168 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6169 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6170 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6171 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6172 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6173 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6174 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6175 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6176 | return nullptr; |
| 6177 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6178 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6179 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6180 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6181 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6182 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6183 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6184 | Exclude); |
| 6185 | } else { |
| 6186 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6187 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6188 | } |
| 6189 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6190 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6191 | return nullptr; |
| 6192 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6193 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6194 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6195 | // schedule(guided). |
| 6196 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6197 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6198 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6199 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6200 | diag::err_omp_schedule_nonmonotonic_static); |
| 6201 | return nullptr; |
| 6202 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6203 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6204 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6205 | if (ChunkSize) { |
| 6206 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6207 | !ChunkSize->isInstantiationDependent() && |
| 6208 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6209 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6210 | ExprResult Val = |
| 6211 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6212 | if (Val.isInvalid()) |
| 6213 | return nullptr; |
| 6214 | |
| 6215 | ValExpr = Val.get(); |
| 6216 | |
| 6217 | // OpenMP [2.7.1, Restrictions] |
| 6218 | // chunk_size must be a loop invariant integer expression with a positive |
| 6219 | // value. |
| 6220 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6221 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6222 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6223 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6224 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6225 | return nullptr; |
| 6226 | } |
| 6227 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6228 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6229 | ChunkSize->getType(), ".chunk."); |
| 6230 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6231 | ChunkSize->getExprLoc(), |
| 6232 | /*RefersToCapture=*/true); |
| 6233 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6234 | } |
| 6235 | } |
| 6236 | } |
| 6237 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6238 | return new (Context) |
| 6239 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6240 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6243 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6244 | SourceLocation StartLoc, |
| 6245 | SourceLocation EndLoc) { |
| 6246 | OMPClause *Res = nullptr; |
| 6247 | switch (Kind) { |
| 6248 | case OMPC_ordered: |
| 6249 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6250 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6251 | case OMPC_nowait: |
| 6252 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6253 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6254 | case OMPC_untied: |
| 6255 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6256 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6257 | case OMPC_mergeable: |
| 6258 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6259 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6260 | case OMPC_read: |
| 6261 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6262 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6263 | case OMPC_write: |
| 6264 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6265 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6266 | case OMPC_update: |
| 6267 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6268 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6269 | case OMPC_capture: |
| 6270 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6271 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6272 | case OMPC_seq_cst: |
| 6273 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6274 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6275 | case OMPC_threads: |
| 6276 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6277 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6278 | case OMPC_simd: |
| 6279 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6280 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6281 | case OMPC_nogroup: |
| 6282 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6283 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6284 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6285 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6286 | case OMPC_num_threads: |
| 6287 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6288 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6289 | case OMPC_collapse: |
| 6290 | case OMPC_schedule: |
| 6291 | case OMPC_private: |
| 6292 | case OMPC_firstprivate: |
| 6293 | case OMPC_lastprivate: |
| 6294 | case OMPC_shared: |
| 6295 | case OMPC_reduction: |
| 6296 | case OMPC_linear: |
| 6297 | case OMPC_aligned: |
| 6298 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6299 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6300 | case OMPC_default: |
| 6301 | case OMPC_proc_bind: |
| 6302 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6303 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6304 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6305 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6306 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6307 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6308 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6309 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6310 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6311 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6312 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6313 | case OMPC_dist_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6314 | case OMPC_unknown: |
| 6315 | llvm_unreachable("Clause is not allowed."); |
| 6316 | } |
| 6317 | return Res; |
| 6318 | } |
| 6319 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6320 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6321 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6322 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6323 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6324 | } |
| 6325 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6326 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6327 | SourceLocation EndLoc) { |
| 6328 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6329 | } |
| 6330 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6331 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6332 | SourceLocation EndLoc) { |
| 6333 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6334 | } |
| 6335 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6336 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6337 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6338 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6339 | } |
| 6340 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6341 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6342 | SourceLocation EndLoc) { |
| 6343 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6344 | } |
| 6345 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6346 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6347 | SourceLocation EndLoc) { |
| 6348 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6349 | } |
| 6350 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6351 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6352 | SourceLocation EndLoc) { |
| 6353 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6354 | } |
| 6355 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6356 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6357 | SourceLocation EndLoc) { |
| 6358 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6359 | } |
| 6360 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6361 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6362 | SourceLocation EndLoc) { |
| 6363 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6364 | } |
| 6365 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6366 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6367 | SourceLocation EndLoc) { |
| 6368 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6369 | } |
| 6370 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6371 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6372 | SourceLocation EndLoc) { |
| 6373 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6374 | } |
| 6375 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6376 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6377 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6378 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6379 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6380 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6381 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6382 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6383 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6384 | switch (Kind) { |
| 6385 | case OMPC_private: |
| 6386 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6387 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6388 | case OMPC_firstprivate: |
| 6389 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6390 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6391 | case OMPC_lastprivate: |
| 6392 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6393 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6394 | case OMPC_shared: |
| 6395 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6396 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6397 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6398 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6399 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6400 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6401 | case OMPC_linear: |
| 6402 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6403 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6404 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6405 | case OMPC_aligned: |
| 6406 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6407 | ColonLoc, EndLoc); |
| 6408 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6409 | case OMPC_copyin: |
| 6410 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6411 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6412 | case OMPC_copyprivate: |
| 6413 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6414 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6415 | case OMPC_flush: |
| 6416 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6417 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6418 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6419 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6420 | StartLoc, LParenLoc, EndLoc); |
| 6421 | break; |
| 6422 | case OMPC_map: |
| 6423 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 6424 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6425 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6426 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6427 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6428 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6429 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6430 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6431 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6432 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6433 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6434 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6435 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6436 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6437 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6438 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6439 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6440 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6441 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6442 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6443 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6444 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6445 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6446 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6447 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6448 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6449 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6450 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6451 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6452 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6453 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6454 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6455 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6456 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6457 | llvm_unreachable("Clause is not allowed."); |
| 6458 | } |
| 6459 | return Res; |
| 6460 | } |
| 6461 | |
| 6462 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6463 | SourceLocation StartLoc, |
| 6464 | SourceLocation LParenLoc, |
| 6465 | SourceLocation EndLoc) { |
| 6466 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6467 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6468 | for (auto &RefExpr : VarList) { |
| 6469 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6470 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6471 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6472 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6473 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6474 | continue; |
| 6475 | } |
| 6476 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6477 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6478 | // OpenMP [2.1, C/C++] |
| 6479 | // A list item is a variable name. |
| 6480 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6481 | // A variable that is part of another variable (as an array or |
| 6482 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6483 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6484 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6485 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6486 | continue; |
| 6487 | } |
| 6488 | Decl *D = DE->getDecl(); |
| 6489 | VarDecl *VD = cast<VarDecl>(D); |
| 6490 | |
| 6491 | QualType Type = VD->getType(); |
| 6492 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6493 | // It will be analyzed later. |
| 6494 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6495 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6496 | continue; |
| 6497 | } |
| 6498 | |
| 6499 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6500 | // A variable that appears in a private clause must not have an incomplete |
| 6501 | // type or a reference type. |
| 6502 | if (RequireCompleteType(ELoc, Type, |
| 6503 | diag::err_omp_private_incomplete_type)) { |
| 6504 | continue; |
| 6505 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6506 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6507 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6508 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6509 | // in a Construct] |
| 6510 | // Variables with the predetermined data-sharing attributes may not be |
| 6511 | // listed in data-sharing attributes clauses, except for the cases |
| 6512 | // listed below. For these exceptions only, listing a predetermined |
| 6513 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6514 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6515 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6516 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6517 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6518 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6519 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6520 | continue; |
| 6521 | } |
| 6522 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6523 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6524 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6525 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6526 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6527 | << getOpenMPClauseName(OMPC_private) << Type |
| 6528 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6529 | bool IsDecl = |
| 6530 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6531 | Diag(VD->getLocation(), |
| 6532 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6533 | << VD; |
| 6534 | continue; |
| 6535 | } |
| 6536 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6537 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6538 | // A variable of class type (or array thereof) that appears in a private |
| 6539 | // clause requires an accessible, unambiguous default constructor for the |
| 6540 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6541 | // Generate helper private variable and initialize it with the default |
| 6542 | // value. The address of the original variable is replaced by the address of |
| 6543 | // the new private variable in CodeGen. This new variable is not added to |
| 6544 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6545 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6546 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6547 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6548 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6549 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6550 | if (VDPrivate->isInvalidDecl()) |
| 6551 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6552 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6553 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6554 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6555 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6556 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6557 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6558 | } |
| 6559 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6560 | if (Vars.empty()) |
| 6561 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6562 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6563 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6564 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6567 | namespace { |
| 6568 | class DiagsUninitializedSeveretyRAII { |
| 6569 | private: |
| 6570 | DiagnosticsEngine &Diags; |
| 6571 | SourceLocation SavedLoc; |
| 6572 | bool IsIgnored; |
| 6573 | |
| 6574 | public: |
| 6575 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6576 | bool IsIgnored) |
| 6577 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6578 | if (!IsIgnored) { |
| 6579 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6580 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6581 | } |
| 6582 | } |
| 6583 | ~DiagsUninitializedSeveretyRAII() { |
| 6584 | if (!IsIgnored) |
| 6585 | Diags.popMappings(SavedLoc); |
| 6586 | } |
| 6587 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6588 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6589 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6590 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6591 | SourceLocation StartLoc, |
| 6592 | SourceLocation LParenLoc, |
| 6593 | SourceLocation EndLoc) { |
| 6594 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6595 | SmallVector<Expr *, 8> PrivateCopies; |
| 6596 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6597 | bool IsImplicitClause = |
| 6598 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6599 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6600 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6601 | for (auto &RefExpr : VarList) { |
| 6602 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6603 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6604 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6605 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6606 | PrivateCopies.push_back(nullptr); |
| 6607 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6608 | continue; |
| 6609 | } |
| 6610 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6611 | SourceLocation ELoc = |
| 6612 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6613 | // OpenMP [2.1, C/C++] |
| 6614 | // A list item is a variable name. |
| 6615 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6616 | // A variable that is part of another variable (as an array or |
| 6617 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6618 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6619 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6620 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6621 | continue; |
| 6622 | } |
| 6623 | Decl *D = DE->getDecl(); |
| 6624 | VarDecl *VD = cast<VarDecl>(D); |
| 6625 | |
| 6626 | QualType Type = VD->getType(); |
| 6627 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6628 | // It will be analyzed later. |
| 6629 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6630 | PrivateCopies.push_back(nullptr); |
| 6631 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6632 | continue; |
| 6633 | } |
| 6634 | |
| 6635 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6636 | // A variable that appears in a private clause must not have an incomplete |
| 6637 | // type or a reference type. |
| 6638 | if (RequireCompleteType(ELoc, Type, |
| 6639 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6640 | continue; |
| 6641 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6642 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6643 | |
| 6644 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6645 | // 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] | 6646 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6647 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6648 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6649 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6650 | // If an implicit firstprivate variable found it was checked already. |
| 6651 | if (!IsImplicitClause) { |
| 6652 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6653 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6654 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6655 | // A list item that specifies a given variable may not appear in more |
| 6656 | // than one clause on the same directive, except that a variable may be |
| 6657 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6658 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6659 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6660 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6661 | << getOpenMPClauseName(DVar.CKind) |
| 6662 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6663 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6664 | continue; |
| 6665 | } |
| 6666 | |
| 6667 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6668 | // in a Construct] |
| 6669 | // Variables with the predetermined data-sharing attributes may not be |
| 6670 | // listed in data-sharing attributes clauses, except for the cases |
| 6671 | // listed below. For these exceptions only, listing a predetermined |
| 6672 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6673 | // the variable's predetermined data-sharing attributes. |
| 6674 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6675 | // in a Construct, C/C++, p.2] |
| 6676 | // Variables with const-qualified type having no mutable member may be |
| 6677 | // listed in a firstprivate clause, even if they are static data members. |
| 6678 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6679 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6680 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6681 | << getOpenMPClauseName(DVar.CKind) |
| 6682 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6683 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6684 | continue; |
| 6685 | } |
| 6686 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6687 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6688 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6689 | // A list item that is private within a parallel region must not appear |
| 6690 | // in a firstprivate clause on a worksharing construct if any of the |
| 6691 | // worksharing regions arising from the worksharing construct ever bind |
| 6692 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6693 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6694 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6695 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6696 | if (DVar.CKind != OMPC_shared && |
| 6697 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6698 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6699 | Diag(ELoc, diag::err_omp_required_access) |
| 6700 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6701 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6702 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6703 | continue; |
| 6704 | } |
| 6705 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6706 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6707 | // A list item that appears in a reduction clause of a parallel construct |
| 6708 | // must not appear in a firstprivate clause on a worksharing or task |
| 6709 | // construct if any of the worksharing or task regions arising from the |
| 6710 | // worksharing or task construct ever bind to any of the parallel regions |
| 6711 | // arising from the parallel construct. |
| 6712 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6713 | // A list item that appears in a reduction clause in worksharing |
| 6714 | // construct must not appear in a firstprivate clause in a task construct |
| 6715 | // encountered during execution of any of the worksharing regions arising |
| 6716 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6717 | if (CurrDir == OMPD_task) { |
| 6718 | DVar = |
| 6719 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6720 | [](OpenMPDirectiveKind K) -> bool { |
| 6721 | return isOpenMPParallelDirective(K) || |
| 6722 | isOpenMPWorksharingDirective(K); |
| 6723 | }, |
| 6724 | false); |
| 6725 | if (DVar.CKind == OMPC_reduction && |
| 6726 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6727 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6728 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6729 | << getOpenMPDirectiveName(DVar.DKind); |
| 6730 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6731 | continue; |
| 6732 | } |
| 6733 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6734 | |
| 6735 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6736 | // A list item that is private within a teams region must not appear in a |
| 6737 | // firstprivate clause on a distribute construct if any of the distribute |
| 6738 | // regions arising from the distribute construct ever bind to any of the |
| 6739 | // teams regions arising from the teams construct. |
| 6740 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6741 | // A list item that appears in a reduction clause of a teams construct |
| 6742 | // must not appear in a firstprivate clause on a distribute construct if |
| 6743 | // any of the distribute regions arising from the distribute construct |
| 6744 | // ever bind to any of the teams regions arising from the teams construct. |
| 6745 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6746 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6747 | // both. |
| 6748 | if (CurrDir == OMPD_distribute) { |
| 6749 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6750 | [](OpenMPDirectiveKind K) -> bool { |
| 6751 | return isOpenMPTeamsDirective(K); |
| 6752 | }, |
| 6753 | false); |
| 6754 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6755 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6756 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6757 | continue; |
| 6758 | } |
| 6759 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6760 | [](OpenMPDirectiveKind K) -> bool { |
| 6761 | return isOpenMPTeamsDirective(K); |
| 6762 | }, |
| 6763 | false); |
| 6764 | if (DVar.CKind == OMPC_reduction && |
| 6765 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6766 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6767 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6768 | continue; |
| 6769 | } |
| 6770 | DVar = DSAStack->getTopDSA(VD, false); |
| 6771 | if (DVar.CKind == OMPC_lastprivate) { |
| 6772 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6773 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6774 | continue; |
| 6775 | } |
| 6776 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6777 | } |
| 6778 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6779 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6780 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6781 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6782 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6783 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6784 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6785 | bool IsDecl = |
| 6786 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6787 | Diag(VD->getLocation(), |
| 6788 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6789 | << VD; |
| 6790 | continue; |
| 6791 | } |
| 6792 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6793 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6794 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6795 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6796 | // Generate helper private variable and initialize it with the value of the |
| 6797 | // original variable. The address of the original variable is replaced by |
| 6798 | // the address of the new private variable in the CodeGen. This new variable |
| 6799 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6800 | // original variable for proper diagnostics and variable capturing. |
| 6801 | Expr *VDInitRefExpr = nullptr; |
| 6802 | // For arrays generate initializer for single element and replace it by the |
| 6803 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6804 | if (Type->isArrayType()) { |
| 6805 | auto VDInit = |
| 6806 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6807 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6808 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6809 | ElemType = ElemType.getUnqualifiedType(); |
| 6810 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6811 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6812 | InitializedEntity Entity = |
| 6813 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6814 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6815 | |
| 6816 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6817 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6818 | if (Result.isInvalid()) |
| 6819 | VDPrivate->setInvalidDecl(); |
| 6820 | else |
| 6821 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6822 | // Remove temp variable declaration. |
| 6823 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6824 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6825 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6826 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6827 | VDInitRefExpr = |
| 6828 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6829 | AddInitializerToDecl(VDPrivate, |
| 6830 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6831 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6832 | } |
| 6833 | if (VDPrivate->isInvalidDecl()) { |
| 6834 | if (IsImplicitClause) { |
| 6835 | Diag(DE->getExprLoc(), |
| 6836 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6837 | } |
| 6838 | continue; |
| 6839 | } |
| 6840 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6841 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6842 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6843 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6844 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6845 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6846 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6847 | } |
| 6848 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6849 | if (Vars.empty()) |
| 6850 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6851 | |
| 6852 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6853 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6854 | } |
| 6855 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6856 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6857 | SourceLocation StartLoc, |
| 6858 | SourceLocation LParenLoc, |
| 6859 | SourceLocation EndLoc) { |
| 6860 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6861 | SmallVector<Expr *, 8> SrcExprs; |
| 6862 | SmallVector<Expr *, 8> DstExprs; |
| 6863 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6864 | for (auto &RefExpr : VarList) { |
| 6865 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6866 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6867 | // It will be analyzed later. |
| 6868 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6869 | SrcExprs.push_back(nullptr); |
| 6870 | DstExprs.push_back(nullptr); |
| 6871 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6872 | continue; |
| 6873 | } |
| 6874 | |
| 6875 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6876 | // OpenMP [2.1, C/C++] |
| 6877 | // A list item is a variable name. |
| 6878 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6879 | // A variable that is part of another variable (as an array or structure |
| 6880 | // element) cannot appear in a lastprivate clause. |
| 6881 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6882 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6883 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6884 | continue; |
| 6885 | } |
| 6886 | Decl *D = DE->getDecl(); |
| 6887 | VarDecl *VD = cast<VarDecl>(D); |
| 6888 | |
| 6889 | QualType Type = VD->getType(); |
| 6890 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6891 | // It will be analyzed later. |
| 6892 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6893 | SrcExprs.push_back(nullptr); |
| 6894 | DstExprs.push_back(nullptr); |
| 6895 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6896 | continue; |
| 6897 | } |
| 6898 | |
| 6899 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6900 | // A variable that appears in a lastprivate clause must not have an |
| 6901 | // incomplete type or a reference type. |
| 6902 | if (RequireCompleteType(ELoc, Type, |
| 6903 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6904 | continue; |
| 6905 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6906 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6907 | |
| 6908 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6909 | // in a Construct] |
| 6910 | // Variables with the predetermined data-sharing attributes may not be |
| 6911 | // listed in data-sharing attributes clauses, except for the cases |
| 6912 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6913 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6914 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6915 | DVar.CKind != OMPC_firstprivate && |
| 6916 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6917 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6918 | << getOpenMPClauseName(DVar.CKind) |
| 6919 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6920 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6921 | continue; |
| 6922 | } |
| 6923 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6924 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6925 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6926 | // A list item that is private within a parallel region, or that appears in |
| 6927 | // the reduction clause of a parallel construct, must not appear in a |
| 6928 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6929 | // worksharing regions ever binds to any of the corresponding parallel |
| 6930 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6931 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6932 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6933 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6934 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6935 | if (DVar.CKind != OMPC_shared) { |
| 6936 | Diag(ELoc, diag::err_omp_required_access) |
| 6937 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6938 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6939 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6940 | continue; |
| 6941 | } |
| 6942 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6943 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6944 | // A variable of class type (or array thereof) that appears in a |
| 6945 | // lastprivate clause requires an accessible, unambiguous default |
| 6946 | // constructor for the class type, unless the list item is also specified |
| 6947 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6948 | // A variable of class type (or array thereof) that appears in a |
| 6949 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6950 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6951 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6952 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6953 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6954 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6955 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6956 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6957 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6958 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6959 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6960 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6961 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6962 | // For arrays generate assignment operation for single element and replace |
| 6963 | // it by the original array element in CodeGen. |
| 6964 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6965 | PseudoDstExpr, PseudoSrcExpr); |
| 6966 | if (AssignmentOp.isInvalid()) |
| 6967 | continue; |
| 6968 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6969 | /*DiscardedValue=*/true); |
| 6970 | if (AssignmentOp.isInvalid()) |
| 6971 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6972 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6973 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6974 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6975 | // both. |
| 6976 | if (CurrDir == OMPD_distribute) { |
| 6977 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 6978 | if (DVar.CKind == OMPC_firstprivate) { |
| 6979 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6980 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6981 | continue; |
| 6982 | } |
| 6983 | } |
| 6984 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6985 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6986 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6987 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6988 | SrcExprs.push_back(PseudoSrcExpr); |
| 6989 | DstExprs.push_back(PseudoDstExpr); |
| 6990 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
| 6993 | if (Vars.empty()) |
| 6994 | return nullptr; |
| 6995 | |
| 6996 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6997 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6998 | } |
| 6999 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7000 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7001 | SourceLocation StartLoc, |
| 7002 | SourceLocation LParenLoc, |
| 7003 | SourceLocation EndLoc) { |
| 7004 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7005 | for (auto &RefExpr : VarList) { |
| 7006 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7007 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7008 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7009 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7010 | continue; |
| 7011 | } |
| 7012 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7013 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7014 | // OpenMP [2.1, C/C++] |
| 7015 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7016 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7017 | // A variable that is part of another variable (as an array or structure |
| 7018 | // element) cannot appear in a shared unless it is a static data member |
| 7019 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7020 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7021 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7022 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7023 | continue; |
| 7024 | } |
| 7025 | Decl *D = DE->getDecl(); |
| 7026 | VarDecl *VD = cast<VarDecl>(D); |
| 7027 | |
| 7028 | QualType Type = VD->getType(); |
| 7029 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7030 | // It will be analyzed later. |
| 7031 | Vars.push_back(DE); |
| 7032 | continue; |
| 7033 | } |
| 7034 | |
| 7035 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7036 | // in a Construct] |
| 7037 | // Variables with the predetermined data-sharing attributes may not be |
| 7038 | // listed in data-sharing attributes clauses, except for the cases |
| 7039 | // listed below. For these exceptions only, listing a predetermined |
| 7040 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7041 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7042 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7043 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7044 | DVar.RefExpr) { |
| 7045 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7046 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7047 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7048 | continue; |
| 7049 | } |
| 7050 | |
| 7051 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7052 | Vars.push_back(DE); |
| 7053 | } |
| 7054 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7055 | if (Vars.empty()) |
| 7056 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7057 | |
| 7058 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7059 | } |
| 7060 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7061 | namespace { |
| 7062 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7063 | DSAStackTy *Stack; |
| 7064 | |
| 7065 | public: |
| 7066 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7067 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7068 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7069 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7070 | return false; |
| 7071 | if (DVar.CKind != OMPC_unknown) |
| 7072 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7073 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7074 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7075 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7076 | return true; |
| 7077 | return false; |
| 7078 | } |
| 7079 | return false; |
| 7080 | } |
| 7081 | bool VisitStmt(Stmt *S) { |
| 7082 | for (auto Child : S->children()) { |
| 7083 | if (Child && Visit(Child)) |
| 7084 | return true; |
| 7085 | } |
| 7086 | return false; |
| 7087 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7088 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7089 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7090 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7091 | |
| 7092 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7093 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7094 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7095 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7096 | const DeclarationNameInfo &ReductionId) { |
| 7097 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7098 | // supported. |
| 7099 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7100 | "No support for scoped reduction identifiers yet."); |
| 7101 | |
| 7102 | auto DN = ReductionId.getName(); |
| 7103 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7104 | BinaryOperatorKind BOK = BO_Comma; |
| 7105 | |
| 7106 | // OpenMP [2.14.3.6, reduction clause] |
| 7107 | // C |
| 7108 | // reduction-identifier is either an identifier or one of the following |
| 7109 | // operators: +, -, *, &, |, ^, && and || |
| 7110 | // C++ |
| 7111 | // reduction-identifier is either an id-expression or one of the following |
| 7112 | // operators: +, -, *, &, |, ^, && and || |
| 7113 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7114 | switch (OOK) { |
| 7115 | case OO_Plus: |
| 7116 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7117 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7118 | break; |
| 7119 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7120 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7121 | break; |
| 7122 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7123 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7124 | break; |
| 7125 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7126 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7127 | break; |
| 7128 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7129 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7130 | break; |
| 7131 | case OO_AmpAmp: |
| 7132 | BOK = BO_LAnd; |
| 7133 | break; |
| 7134 | case OO_PipePipe: |
| 7135 | BOK = BO_LOr; |
| 7136 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7137 | case OO_New: |
| 7138 | case OO_Delete: |
| 7139 | case OO_Array_New: |
| 7140 | case OO_Array_Delete: |
| 7141 | case OO_Slash: |
| 7142 | case OO_Percent: |
| 7143 | case OO_Tilde: |
| 7144 | case OO_Exclaim: |
| 7145 | case OO_Equal: |
| 7146 | case OO_Less: |
| 7147 | case OO_Greater: |
| 7148 | case OO_LessEqual: |
| 7149 | case OO_GreaterEqual: |
| 7150 | case OO_PlusEqual: |
| 7151 | case OO_MinusEqual: |
| 7152 | case OO_StarEqual: |
| 7153 | case OO_SlashEqual: |
| 7154 | case OO_PercentEqual: |
| 7155 | case OO_CaretEqual: |
| 7156 | case OO_AmpEqual: |
| 7157 | case OO_PipeEqual: |
| 7158 | case OO_LessLess: |
| 7159 | case OO_GreaterGreater: |
| 7160 | case OO_LessLessEqual: |
| 7161 | case OO_GreaterGreaterEqual: |
| 7162 | case OO_EqualEqual: |
| 7163 | case OO_ExclaimEqual: |
| 7164 | case OO_PlusPlus: |
| 7165 | case OO_MinusMinus: |
| 7166 | case OO_Comma: |
| 7167 | case OO_ArrowStar: |
| 7168 | case OO_Arrow: |
| 7169 | case OO_Call: |
| 7170 | case OO_Subscript: |
| 7171 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7172 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7173 | case NUM_OVERLOADED_OPERATORS: |
| 7174 | llvm_unreachable("Unexpected reduction identifier"); |
| 7175 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7176 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7177 | if (II->isStr("max")) |
| 7178 | BOK = BO_GT; |
| 7179 | else if (II->isStr("min")) |
| 7180 | BOK = BO_LT; |
| 7181 | } |
| 7182 | break; |
| 7183 | } |
| 7184 | SourceRange ReductionIdRange; |
| 7185 | if (ReductionIdScopeSpec.isValid()) { |
| 7186 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7187 | } |
| 7188 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7189 | if (BOK == BO_Comma) { |
| 7190 | // Not allowed reduction identifier is found. |
| 7191 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7192 | << ReductionIdRange; |
| 7193 | return nullptr; |
| 7194 | } |
| 7195 | |
| 7196 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7197 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7198 | SmallVector<Expr *, 8> LHSs; |
| 7199 | SmallVector<Expr *, 8> RHSs; |
| 7200 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7201 | for (auto RefExpr : VarList) { |
| 7202 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7203 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7204 | // It will be analyzed later. |
| 7205 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7206 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7207 | LHSs.push_back(nullptr); |
| 7208 | RHSs.push_back(nullptr); |
| 7209 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7210 | continue; |
| 7211 | } |
| 7212 | |
| 7213 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7214 | RefExpr->isInstantiationDependent() || |
| 7215 | RefExpr->containsUnexpandedParameterPack()) { |
| 7216 | // It will be analyzed later. |
| 7217 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7218 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7219 | LHSs.push_back(nullptr); |
| 7220 | RHSs.push_back(nullptr); |
| 7221 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7222 | continue; |
| 7223 | } |
| 7224 | |
| 7225 | auto ELoc = RefExpr->getExprLoc(); |
| 7226 | auto ERange = RefExpr->getSourceRange(); |
| 7227 | // OpenMP [2.1, C/C++] |
| 7228 | // A list item is a variable or array section, subject to the restrictions |
| 7229 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7230 | // describing clauses and directives for which a list appears. |
| 7231 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7232 | // A variable that is part of another variable (as an array or |
| 7233 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7234 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7235 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7236 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7237 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 7238 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7239 | continue; |
| 7240 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7241 | QualType Type; |
| 7242 | VarDecl *VD = nullptr; |
| 7243 | if (DE) { |
| 7244 | auto D = DE->getDecl(); |
| 7245 | VD = cast<VarDecl>(D); |
| 7246 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7247 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7248 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7249 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7250 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7251 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7252 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7253 | if (DE) |
| 7254 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7255 | if (!VD) { |
| 7256 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7257 | << 0 << Base->getSourceRange(); |
| 7258 | continue; |
| 7259 | } |
| 7260 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7261 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7262 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7263 | Type = ATy->getElementType(); |
| 7264 | else |
| 7265 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7266 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7267 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7268 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7269 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7270 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7271 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7272 | if (DE) |
| 7273 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7274 | if (!VD) { |
| 7275 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7276 | << 1 << Base->getSourceRange(); |
| 7277 | continue; |
| 7278 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7279 | } |
| 7280 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7281 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7282 | // A variable that appears in a private clause must not have an incomplete |
| 7283 | // type or a reference type. |
| 7284 | if (RequireCompleteType(ELoc, Type, |
| 7285 | diag::err_omp_reduction_incomplete_type)) |
| 7286 | continue; |
| 7287 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7288 | // Arrays may not appear in a reduction clause. |
| 7289 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7290 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7291 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7292 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7293 | VarDecl::DeclarationOnly; |
| 7294 | Diag(VD->getLocation(), |
| 7295 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7296 | << VD; |
| 7297 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7298 | continue; |
| 7299 | } |
| 7300 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7301 | // A list item that appears in a reduction clause must not be |
| 7302 | // const-qualified. |
| 7303 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7304 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7305 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7306 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7307 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7308 | VarDecl::DeclarationOnly; |
| 7309 | Diag(VD->getLocation(), |
| 7310 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7311 | << VD; |
| 7312 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7313 | continue; |
| 7314 | } |
| 7315 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7316 | // If a list-item is a reference type then it must bind to the same object |
| 7317 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7318 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7319 | VarDecl *VDDef = VD->getDefinition(); |
| 7320 | if (Type->isReferenceType() && VDDef) { |
| 7321 | DSARefChecker Check(DSAStack); |
| 7322 | if (Check.Visit(VDDef->getInit())) { |
| 7323 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7324 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7325 | continue; |
| 7326 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7327 | } |
| 7328 | } |
| 7329 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7330 | // The type of a list item that appears in a reduction clause must be valid |
| 7331 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7332 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7333 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7334 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7335 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7336 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7337 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7338 | !(Type->isScalarType() || |
| 7339 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7340 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7341 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7342 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7343 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7344 | VarDecl::DeclarationOnly; |
| 7345 | Diag(VD->getLocation(), |
| 7346 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7347 | << VD; |
| 7348 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7349 | continue; |
| 7350 | } |
| 7351 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7352 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7353 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7354 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7355 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7356 | VarDecl::DeclarationOnly; |
| 7357 | Diag(VD->getLocation(), |
| 7358 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7359 | << VD; |
| 7360 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7361 | continue; |
| 7362 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7363 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7364 | // in a Construct] |
| 7365 | // Variables with the predetermined data-sharing attributes may not be |
| 7366 | // listed in data-sharing attributes clauses, except for the cases |
| 7367 | // listed below. For these exceptions only, listing a predetermined |
| 7368 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7369 | // the variable's predetermined data-sharing attributes. |
| 7370 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7371 | // Any number of reduction clauses can be specified on the directive, |
| 7372 | // but a list item can appear only once in the reduction clauses for that |
| 7373 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7374 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7375 | DVar = DSAStack->getTopDSA(VD, false); |
| 7376 | if (DVar.CKind == OMPC_reduction) { |
| 7377 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7378 | << getOpenMPClauseName(OMPC_reduction); |
| 7379 | if (DVar.RefExpr) { |
| 7380 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7381 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7382 | } else if (DVar.CKind != OMPC_unknown) { |
| 7383 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7384 | << getOpenMPClauseName(DVar.CKind) |
| 7385 | << getOpenMPClauseName(OMPC_reduction); |
| 7386 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7387 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7391 | // A list item that appears in a reduction clause of a worksharing |
| 7392 | // construct must be shared in the parallel regions to which any of the |
| 7393 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7394 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7395 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7396 | !isOpenMPParallelDirective(CurrDir)) { |
| 7397 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7398 | if (DVar.CKind != OMPC_shared) { |
| 7399 | Diag(ELoc, diag::err_omp_required_access) |
| 7400 | << getOpenMPClauseName(OMPC_reduction) |
| 7401 | << getOpenMPClauseName(OMPC_shared); |
| 7402 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7403 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7404 | } |
| 7405 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7406 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7407 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7408 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7409 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7410 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7411 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7412 | auto PrivateTy = Type; |
| 7413 | if (OASE) { |
| 7414 | // For array sections only: |
| 7415 | // Create pseudo array type for private copy. The size for this array will |
| 7416 | // be generated during codegen. |
| 7417 | // For array subscripts or single variables Private Ty is the same as Type |
| 7418 | // (type of the variable or single array element). |
| 7419 | PrivateTy = Context.getVariableArrayType( |
| 7420 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7421 | Context.getSizeType(), VK_RValue), |
| 7422 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7423 | } |
| 7424 | // Private copy. |
| 7425 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7426 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7427 | // Add initializer for private variable. |
| 7428 | Expr *Init = nullptr; |
| 7429 | switch (BOK) { |
| 7430 | case BO_Add: |
| 7431 | case BO_Xor: |
| 7432 | case BO_Or: |
| 7433 | case BO_LOr: |
| 7434 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7435 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7436 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7437 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7438 | break; |
| 7439 | case BO_Mul: |
| 7440 | case BO_LAnd: |
| 7441 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7442 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7443 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7444 | } |
| 7445 | break; |
| 7446 | case BO_And: { |
| 7447 | // '&' reduction op - initializer is '~0'. |
| 7448 | QualType OrigType = Type; |
| 7449 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7450 | Type = ComplexTy->getElementType(); |
| 7451 | } |
| 7452 | if (Type->isRealFloatingType()) { |
| 7453 | llvm::APFloat InitValue = |
| 7454 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7455 | /*isIEEE=*/true); |
| 7456 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7457 | Type, ELoc); |
| 7458 | } else if (Type->isScalarType()) { |
| 7459 | auto Size = Context.getTypeSize(Type); |
| 7460 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7461 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7462 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7463 | } |
| 7464 | if (Init && OrigType->isAnyComplexType()) { |
| 7465 | // Init = 0xFFFF + 0xFFFFi; |
| 7466 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7467 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7468 | } |
| 7469 | Type = OrigType; |
| 7470 | break; |
| 7471 | } |
| 7472 | case BO_LT: |
| 7473 | case BO_GT: { |
| 7474 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7475 | // the reduction list item type'. |
| 7476 | // 'max' reduction op - initializer is 'Least representable number in |
| 7477 | // the reduction list item type'. |
| 7478 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7479 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7480 | auto Size = Context.getTypeSize(Type); |
| 7481 | QualType IntTy = |
| 7482 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7483 | llvm::APInt InitValue = |
| 7484 | (BOK != BO_LT) |
| 7485 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7486 | : llvm::APInt::getMinValue(Size) |
| 7487 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7488 | : llvm::APInt::getMaxValue(Size); |
| 7489 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7490 | if (Type->isPointerType()) { |
| 7491 | // Cast to pointer type. |
| 7492 | auto CastExpr = BuildCStyleCastExpr( |
| 7493 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7494 | SourceLocation(), Init); |
| 7495 | if (CastExpr.isInvalid()) |
| 7496 | continue; |
| 7497 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7498 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7499 | } else if (Type->isRealFloatingType()) { |
| 7500 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7501 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7502 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7503 | Type, ELoc); |
| 7504 | } |
| 7505 | break; |
| 7506 | } |
| 7507 | case BO_PtrMemD: |
| 7508 | case BO_PtrMemI: |
| 7509 | case BO_MulAssign: |
| 7510 | case BO_Div: |
| 7511 | case BO_Rem: |
| 7512 | case BO_Sub: |
| 7513 | case BO_Shl: |
| 7514 | case BO_Shr: |
| 7515 | case BO_LE: |
| 7516 | case BO_GE: |
| 7517 | case BO_EQ: |
| 7518 | case BO_NE: |
| 7519 | case BO_AndAssign: |
| 7520 | case BO_XorAssign: |
| 7521 | case BO_OrAssign: |
| 7522 | case BO_Assign: |
| 7523 | case BO_AddAssign: |
| 7524 | case BO_SubAssign: |
| 7525 | case BO_DivAssign: |
| 7526 | case BO_RemAssign: |
| 7527 | case BO_ShlAssign: |
| 7528 | case BO_ShrAssign: |
| 7529 | case BO_Comma: |
| 7530 | llvm_unreachable("Unexpected reduction operation"); |
| 7531 | } |
| 7532 | if (Init) { |
| 7533 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7534 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7535 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7536 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7537 | if (!RHSVD->hasInit()) { |
| 7538 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7539 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7540 | if (VD) { |
| 7541 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7542 | VarDecl::DeclarationOnly; |
| 7543 | Diag(VD->getLocation(), |
| 7544 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7545 | << VD; |
| 7546 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7547 | continue; |
| 7548 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7549 | // Store initializer for single element in private copy. Will be used during |
| 7550 | // codegen. |
| 7551 | PrivateVD->setInit(RHSVD->getInit()); |
| 7552 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7553 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7554 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7555 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7556 | ExprResult ReductionOp = |
| 7557 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7558 | LHSDRE, RHSDRE); |
| 7559 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7560 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7561 | ReductionOp = |
| 7562 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7563 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7564 | } else { |
| 7565 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7566 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7567 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7568 | ReductionOp = |
| 7569 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7570 | BO_Assign, LHSDRE, ConditionalOp); |
| 7571 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7572 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7573 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7574 | if (ReductionOp.isInvalid()) |
| 7575 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7576 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7577 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7578 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7579 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7580 | LHSs.push_back(LHSDRE); |
| 7581 | RHSs.push_back(RHSDRE); |
| 7582 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | if (Vars.empty()) |
| 7586 | return nullptr; |
| 7587 | |
| 7588 | return OMPReductionClause::Create( |
| 7589 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7590 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7591 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7592 | } |
| 7593 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7594 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7595 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7596 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7597 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7598 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7599 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7600 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7601 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7602 | LinKind == OMPC_LINEAR_unknown) { |
| 7603 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7604 | LinKind = OMPC_LINEAR_val; |
| 7605 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7606 | for (auto &RefExpr : VarList) { |
| 7607 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7608 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7609 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7610 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7611 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7612 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7613 | continue; |
| 7614 | } |
| 7615 | |
| 7616 | // OpenMP [2.14.3.7, linear clause] |
| 7617 | // A list item that appears in a linear clause is subject to the private |
| 7618 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7619 | // noted. In addition, the value of the new list item on each iteration |
| 7620 | // of the associated loop(s) corresponds to the value of the original |
| 7621 | // list item before entering the construct plus the logical number of |
| 7622 | // the iteration times linear-step. |
| 7623 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7624 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7625 | // OpenMP [2.1, C/C++] |
| 7626 | // A list item is a variable name. |
| 7627 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7628 | // A variable that is part of another variable (as an array or |
| 7629 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7630 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7631 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7632 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7633 | continue; |
| 7634 | } |
| 7635 | |
| 7636 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7637 | |
| 7638 | // OpenMP [2.14.3.7, linear clause] |
| 7639 | // A list-item cannot appear in more than one linear clause. |
| 7640 | // A list-item that appears in a linear clause cannot appear in any |
| 7641 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7642 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7643 | if (DVar.RefExpr) { |
| 7644 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7645 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7646 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7647 | continue; |
| 7648 | } |
| 7649 | |
| 7650 | QualType QType = VD->getType(); |
| 7651 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7652 | // It will be analyzed later. |
| 7653 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7654 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7655 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7656 | continue; |
| 7657 | } |
| 7658 | |
| 7659 | // A variable must not have an incomplete type or a reference type. |
| 7660 | if (RequireCompleteType(ELoc, QType, |
| 7661 | diag::err_omp_linear_incomplete_type)) { |
| 7662 | continue; |
| 7663 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7664 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7665 | !QType->isReferenceType()) { |
| 7666 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7667 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7668 | continue; |
| 7669 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7670 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7671 | |
| 7672 | // A list item must not be const-qualified. |
| 7673 | if (QType.isConstant(Context)) { |
| 7674 | Diag(ELoc, diag::err_omp_const_variable) |
| 7675 | << getOpenMPClauseName(OMPC_linear); |
| 7676 | bool IsDecl = |
| 7677 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7678 | Diag(VD->getLocation(), |
| 7679 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7680 | << VD; |
| 7681 | continue; |
| 7682 | } |
| 7683 | |
| 7684 | // A list item must be of integral or pointer type. |
| 7685 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7686 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7687 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7688 | !Ty->isPointerType())) { |
| 7689 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7690 | bool IsDecl = |
| 7691 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7692 | Diag(VD->getLocation(), |
| 7693 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7694 | << VD; |
| 7695 | continue; |
| 7696 | } |
| 7697 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7698 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7699 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7700 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7701 | auto *PrivateRef = buildDeclRefExpr( |
| 7702 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7703 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7704 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7705 | Expr *InitExpr; |
| 7706 | if (LinKind == OMPC_LINEAR_uval) |
| 7707 | InitExpr = VD->getInit(); |
| 7708 | else |
| 7709 | InitExpr = DE; |
| 7710 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7711 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7712 | auto InitRef = buildDeclRefExpr( |
| 7713 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7714 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7715 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7716 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7717 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7721 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7722 | |
| 7723 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7724 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7725 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7726 | !Step->isInstantiationDependent() && |
| 7727 | !Step->containsUnexpandedParameterPack()) { |
| 7728 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7729 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7730 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7731 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7732 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7733 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7734 | // Build var to save the step value. |
| 7735 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7736 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7737 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7738 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7739 | ExprResult CalcStep = |
| 7740 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7741 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7742 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7743 | // Warn about zero linear step (it would be probably better specified as |
| 7744 | // making corresponding variables 'const'). |
| 7745 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7746 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7747 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7748 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7749 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7750 | if (!IsConstant && CalcStep.isUsable()) { |
| 7751 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7752 | // (This is not used if the number of iterations may be kfold-ed). |
| 7753 | CalcStepExpr = CalcStep.get(); |
| 7754 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7755 | } |
| 7756 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7757 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7758 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7759 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7763 | Expr *NumIterations, Sema &SemaRef, |
| 7764 | Scope *S) { |
| 7765 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7766 | SmallVector<Expr *, 8> Updates; |
| 7767 | SmallVector<Expr *, 8> Finals; |
| 7768 | Expr *Step = Clause.getStep(); |
| 7769 | Expr *CalcStep = Clause.getCalcStep(); |
| 7770 | // OpenMP [2.14.3.7, linear clause] |
| 7771 | // If linear-step is not specified it is assumed to be 1. |
| 7772 | if (Step == nullptr) |
| 7773 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7774 | else if (CalcStep) |
| 7775 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7776 | bool HasErrors = false; |
| 7777 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7778 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7779 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7780 | for (auto &RefExpr : Clause.varlists()) { |
| 7781 | Expr *InitExpr = *CurInit; |
| 7782 | |
| 7783 | // Build privatized reference to the current linear var. |
| 7784 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7785 | Expr *CapturedRef; |
| 7786 | if (LinKind == OMPC_LINEAR_uval) |
| 7787 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7788 | else |
| 7789 | CapturedRef = |
| 7790 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7791 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7792 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7793 | |
| 7794 | // Build update: Var = InitExpr + IV * Step |
| 7795 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7796 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7797 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7798 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7799 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7800 | |
| 7801 | // Build final: Var = InitExpr + NumIterations * Step |
| 7802 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7803 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7804 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7805 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7806 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7807 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7808 | Updates.push_back(nullptr); |
| 7809 | Finals.push_back(nullptr); |
| 7810 | HasErrors = true; |
| 7811 | } else { |
| 7812 | Updates.push_back(Update.get()); |
| 7813 | Finals.push_back(Final.get()); |
| 7814 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7815 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7816 | } |
| 7817 | Clause.setUpdates(Updates); |
| 7818 | Clause.setFinals(Finals); |
| 7819 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7820 | } |
| 7821 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7822 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7823 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7824 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7825 | |
| 7826 | SmallVector<Expr *, 8> Vars; |
| 7827 | for (auto &RefExpr : VarList) { |
| 7828 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7829 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7830 | // It will be analyzed later. |
| 7831 | Vars.push_back(RefExpr); |
| 7832 | continue; |
| 7833 | } |
| 7834 | |
| 7835 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7836 | // OpenMP [2.1, C/C++] |
| 7837 | // A list item is a variable name. |
| 7838 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7839 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7840 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7841 | continue; |
| 7842 | } |
| 7843 | |
| 7844 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7845 | |
| 7846 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7847 | // The type of list items appearing in the aligned clause must be |
| 7848 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7849 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7850 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7851 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7852 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7853 | !Ty->isPointerType())) { |
| 7854 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7855 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7856 | bool IsDecl = |
| 7857 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7858 | Diag(VD->getLocation(), |
| 7859 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7860 | << VD; |
| 7861 | continue; |
| 7862 | } |
| 7863 | |
| 7864 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7865 | // A list-item cannot appear in more than one aligned clause. |
| 7866 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7867 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7868 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7869 | << getOpenMPClauseName(OMPC_aligned); |
| 7870 | continue; |
| 7871 | } |
| 7872 | |
| 7873 | Vars.push_back(DE); |
| 7874 | } |
| 7875 | |
| 7876 | // OpenMP [2.8.1, simd construct, Description] |
| 7877 | // The parameter of the aligned clause, alignment, must be a constant |
| 7878 | // positive integer expression. |
| 7879 | // If no optional parameter is specified, implementation-defined default |
| 7880 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7881 | if (Alignment != nullptr) { |
| 7882 | ExprResult AlignResult = |
| 7883 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7884 | if (AlignResult.isInvalid()) |
| 7885 | return nullptr; |
| 7886 | Alignment = AlignResult.get(); |
| 7887 | } |
| 7888 | if (Vars.empty()) |
| 7889 | return nullptr; |
| 7890 | |
| 7891 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7892 | EndLoc, Vars, Alignment); |
| 7893 | } |
| 7894 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7895 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7896 | SourceLocation StartLoc, |
| 7897 | SourceLocation LParenLoc, |
| 7898 | SourceLocation EndLoc) { |
| 7899 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7900 | SmallVector<Expr *, 8> SrcExprs; |
| 7901 | SmallVector<Expr *, 8> DstExprs; |
| 7902 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7903 | for (auto &RefExpr : VarList) { |
| 7904 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7905 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7906 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7907 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7908 | SrcExprs.push_back(nullptr); |
| 7909 | DstExprs.push_back(nullptr); |
| 7910 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7911 | continue; |
| 7912 | } |
| 7913 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7914 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7915 | // OpenMP [2.1, C/C++] |
| 7916 | // A list item is a variable name. |
| 7917 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7918 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7919 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7920 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7921 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7922 | continue; |
| 7923 | } |
| 7924 | |
| 7925 | Decl *D = DE->getDecl(); |
| 7926 | VarDecl *VD = cast<VarDecl>(D); |
| 7927 | |
| 7928 | QualType Type = VD->getType(); |
| 7929 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7930 | // It will be analyzed later. |
| 7931 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7932 | SrcExprs.push_back(nullptr); |
| 7933 | DstExprs.push_back(nullptr); |
| 7934 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7935 | continue; |
| 7936 | } |
| 7937 | |
| 7938 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7939 | // A list item that appears in a copyin clause must be threadprivate. |
| 7940 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7941 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7942 | << getOpenMPClauseName(OMPC_copyin) |
| 7943 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7944 | continue; |
| 7945 | } |
| 7946 | |
| 7947 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7948 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7949 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7950 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7951 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7952 | auto *SrcVD = |
| 7953 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7954 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7955 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7956 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7957 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7958 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7959 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7960 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7961 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7962 | // For arrays generate assignment operation for single element and replace |
| 7963 | // it by the original array element in CodeGen. |
| 7964 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7965 | PseudoDstExpr, PseudoSrcExpr); |
| 7966 | if (AssignmentOp.isInvalid()) |
| 7967 | continue; |
| 7968 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7969 | /*DiscardedValue=*/true); |
| 7970 | if (AssignmentOp.isInvalid()) |
| 7971 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7972 | |
| 7973 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7974 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7975 | SrcExprs.push_back(PseudoSrcExpr); |
| 7976 | DstExprs.push_back(PseudoDstExpr); |
| 7977 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7978 | } |
| 7979 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7980 | if (Vars.empty()) |
| 7981 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7982 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7983 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7984 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7985 | } |
| 7986 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7987 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7988 | SourceLocation StartLoc, |
| 7989 | SourceLocation LParenLoc, |
| 7990 | SourceLocation EndLoc) { |
| 7991 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7992 | SmallVector<Expr *, 8> SrcExprs; |
| 7993 | SmallVector<Expr *, 8> DstExprs; |
| 7994 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7995 | for (auto &RefExpr : VarList) { |
| 7996 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7997 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7998 | // It will be analyzed later. |
| 7999 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8000 | SrcExprs.push_back(nullptr); |
| 8001 | DstExprs.push_back(nullptr); |
| 8002 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8003 | continue; |
| 8004 | } |
| 8005 | |
| 8006 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8007 | // OpenMP [2.1, C/C++] |
| 8008 | // A list item is a variable name. |
| 8009 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8010 | // A list item that appears in a copyin clause must be threadprivate. |
| 8011 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8012 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 8013 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 8014 | continue; |
| 8015 | } |
| 8016 | |
| 8017 | Decl *D = DE->getDecl(); |
| 8018 | VarDecl *VD = cast<VarDecl>(D); |
| 8019 | |
| 8020 | QualType Type = VD->getType(); |
| 8021 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8022 | // It will be analyzed later. |
| 8023 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8024 | SrcExprs.push_back(nullptr); |
| 8025 | DstExprs.push_back(nullptr); |
| 8026 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8027 | continue; |
| 8028 | } |
| 8029 | |
| 8030 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8031 | // A list item that appears in a copyprivate clause may not appear in a |
| 8032 | // private or firstprivate clause on the single construct. |
| 8033 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8034 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8035 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8036 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8037 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8038 | << getOpenMPClauseName(DVar.CKind) |
| 8039 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8040 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8041 | continue; |
| 8042 | } |
| 8043 | |
| 8044 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8045 | // All list items that appear in a copyprivate clause must be either |
| 8046 | // threadprivate or private in the enclosing context. |
| 8047 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8048 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8049 | if (DVar.CKind == OMPC_shared) { |
| 8050 | Diag(ELoc, diag::err_omp_required_access) |
| 8051 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8052 | << "threadprivate or private in the enclosing context"; |
| 8053 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8054 | continue; |
| 8055 | } |
| 8056 | } |
| 8057 | } |
| 8058 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8059 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8060 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8061 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8062 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8063 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8064 | bool IsDecl = |
| 8065 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8066 | Diag(VD->getLocation(), |
| 8067 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8068 | << VD; |
| 8069 | continue; |
| 8070 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8071 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8072 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8073 | // A variable of class type (or array thereof) that appears in a |
| 8074 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8075 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8076 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8077 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8078 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8079 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8080 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8081 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8082 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8083 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8084 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8085 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8086 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8087 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8088 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8089 | PseudoDstExpr, PseudoSrcExpr); |
| 8090 | if (AssignmentOp.isInvalid()) |
| 8091 | continue; |
| 8092 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8093 | /*DiscardedValue=*/true); |
| 8094 | if (AssignmentOp.isInvalid()) |
| 8095 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8096 | |
| 8097 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8098 | // implicitly private. |
| 8099 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8100 | SrcExprs.push_back(PseudoSrcExpr); |
| 8101 | DstExprs.push_back(PseudoDstExpr); |
| 8102 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8103 | } |
| 8104 | |
| 8105 | if (Vars.empty()) |
| 8106 | return nullptr; |
| 8107 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8108 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8109 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8110 | } |
| 8111 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8112 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8113 | SourceLocation StartLoc, |
| 8114 | SourceLocation LParenLoc, |
| 8115 | SourceLocation EndLoc) { |
| 8116 | if (VarList.empty()) |
| 8117 | return nullptr; |
| 8118 | |
| 8119 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8120 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8121 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8122 | OMPClause * |
| 8123 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8124 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8125 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8126 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8127 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8128 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8129 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8130 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8131 | return nullptr; |
| 8132 | } |
| 8133 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8134 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8135 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8136 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8137 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8138 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8139 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8140 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8141 | return nullptr; |
| 8142 | } |
| 8143 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8144 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8145 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8146 | if (DepKind == OMPC_DEPEND_sink) { |
| 8147 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8148 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8149 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8150 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8151 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8152 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8153 | DSAStack->getParentOrderedRegionParam()) { |
| 8154 | for (auto &RefExpr : VarList) { |
| 8155 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8156 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8157 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8158 | // It will be analyzed later. |
| 8159 | Vars.push_back(RefExpr); |
| 8160 | continue; |
| 8161 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8162 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8163 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8164 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8165 | if (DepKind == OMPC_DEPEND_sink) { |
| 8166 | if (DepCounter >= TotalDepCount) { |
| 8167 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8168 | continue; |
| 8169 | } |
| 8170 | ++DepCounter; |
| 8171 | // OpenMP [2.13.9, Summary] |
| 8172 | // depend(dependence-type : vec), where dependence-type is: |
| 8173 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8174 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8175 | // where n is the value specified by the ordered clause in the loop |
| 8176 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8177 | // loop associated with the loop directive, and di is a constant |
| 8178 | // non-negative integer. |
| 8179 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8180 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8181 | if (!DE) { |
| 8182 | OverloadedOperatorKind OOK = OO_None; |
| 8183 | SourceLocation OOLoc; |
| 8184 | Expr *LHS, *RHS; |
| 8185 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8186 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8187 | OOLoc = BO->getOperatorLoc(); |
| 8188 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8189 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8190 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8191 | OOK = OCE->getOperator(); |
| 8192 | OOLoc = OCE->getOperatorLoc(); |
| 8193 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8194 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8195 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8196 | OOK = MCE->getMethodDecl() |
| 8197 | ->getNameInfo() |
| 8198 | .getName() |
| 8199 | .getCXXOverloadedOperator(); |
| 8200 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8201 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8202 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8203 | } else { |
| 8204 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8205 | continue; |
| 8206 | } |
| 8207 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8208 | if (!DE) { |
| 8209 | Diag(LHS->getExprLoc(), |
| 8210 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8211 | << DSAStack->getParentLoopControlVariable( |
| 8212 | DepCounter.getZExtValue()); |
| 8213 | continue; |
| 8214 | } |
| 8215 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8216 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8217 | continue; |
| 8218 | } |
| 8219 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8220 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8221 | if (Res.isInvalid()) |
| 8222 | continue; |
| 8223 | } |
| 8224 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8225 | if (!CurContext->isDependentContext() && |
| 8226 | DSAStack->getParentOrderedRegionParam() && |
| 8227 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8228 | Diag(DE->getExprLoc(), |
| 8229 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8230 | << DSAStack->getParentLoopControlVariable( |
| 8231 | DepCounter.getZExtValue()); |
| 8232 | continue; |
| 8233 | } |
| 8234 | } else { |
| 8235 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8236 | // A variable that is part of another variable (such as a field of a |
| 8237 | // structure) but is not an array element or an array section cannot |
| 8238 | // appear in a depend clause. |
| 8239 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8240 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8241 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8242 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8243 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8244 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8245 | !ASE->getBase()->getType()->isArrayType())) { |
| 8246 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8247 | << RefExpr->getSourceRange(); |
| 8248 | continue; |
| 8249 | } |
| 8250 | } |
| 8251 | |
| 8252 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8253 | } |
| 8254 | |
| 8255 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8256 | TotalDepCount > VarList.size() && |
| 8257 | DSAStack->getParentOrderedRegionParam()) { |
| 8258 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8259 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8260 | } |
| 8261 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8262 | Vars.empty()) |
| 8263 | return nullptr; |
| 8264 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8265 | |
| 8266 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8267 | DepLoc, ColonLoc, Vars); |
| 8268 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8269 | |
| 8270 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8271 | SourceLocation LParenLoc, |
| 8272 | SourceLocation EndLoc) { |
| 8273 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8274 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8275 | // OpenMP [2.9.1, Restrictions] |
| 8276 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8277 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8278 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8279 | return nullptr; |
| 8280 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8281 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8282 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8283 | |
| 8284 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8285 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8286 | if (!RD || RD->isInvalidDecl()) |
| 8287 | return true; |
| 8288 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8289 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8290 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8291 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8292 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8293 | if (RD->isDynamicClass()) { |
| 8294 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8295 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8296 | return false; |
| 8297 | } |
| 8298 | auto *DC = RD; |
| 8299 | bool IsCorrect = true; |
| 8300 | for (auto *I : DC->decls()) { |
| 8301 | if (I) { |
| 8302 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8303 | if (MD->isStatic()) { |
| 8304 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8305 | SemaRef.Diag(MD->getLocation(), |
| 8306 | diag::note_omp_static_member_in_target); |
| 8307 | IsCorrect = false; |
| 8308 | } |
| 8309 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8310 | if (VD->isStaticDataMember()) { |
| 8311 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8312 | SemaRef.Diag(VD->getLocation(), |
| 8313 | diag::note_omp_static_member_in_target); |
| 8314 | IsCorrect = false; |
| 8315 | } |
| 8316 | } |
| 8317 | } |
| 8318 | } |
| 8319 | |
| 8320 | for (auto &I : RD->bases()) { |
| 8321 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8322 | I.getType()->getAsCXXRecordDecl())) |
| 8323 | IsCorrect = false; |
| 8324 | } |
| 8325 | return IsCorrect; |
| 8326 | } |
| 8327 | |
| 8328 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8329 | DSAStackTy *Stack, QualType QTy) { |
| 8330 | NamedDecl *ND; |
| 8331 | if (QTy->isIncompleteType(&ND)) { |
| 8332 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8333 | return false; |
| 8334 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8335 | if (!RD->isInvalidDecl() && |
| 8336 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8337 | return false; |
| 8338 | } |
| 8339 | return true; |
| 8340 | } |
| 8341 | |
| 8342 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 8343 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 8344 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 8345 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 8346 | SmallVector<Expr *, 4> Vars; |
| 8347 | |
| 8348 | for (auto &RE : VarList) { |
| 8349 | assert(RE && "Null expr in omp map"); |
| 8350 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8351 | // It will be analyzed later. |
| 8352 | Vars.push_back(RE); |
| 8353 | continue; |
| 8354 | } |
| 8355 | SourceLocation ELoc = RE->getExprLoc(); |
| 8356 | |
| 8357 | // OpenMP [2.14.5, Restrictions] |
| 8358 | // A variable that is part of another variable (such as field of a |
| 8359 | // structure) but is not an array element or an array section cannot appear |
| 8360 | // in a map clause. |
| 8361 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8362 | |
| 8363 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8364 | VE->isInstantiationDependent() || |
| 8365 | VE->containsUnexpandedParameterPack()) { |
| 8366 | // It will be analyzed later. |
| 8367 | Vars.push_back(RE); |
| 8368 | continue; |
| 8369 | } |
| 8370 | |
| 8371 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8372 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8373 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8374 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8375 | |
| 8376 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8377 | (!OASE && !ASE && !DE) || |
| 8378 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8379 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8380 | !ASE->getBase()->getType()->isArrayType())) { |
| 8381 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8382 | << RE->getSourceRange(); |
| 8383 | continue; |
| 8384 | } |
| 8385 | |
| 8386 | Decl *D = nullptr; |
| 8387 | if (DE) { |
| 8388 | D = DE->getDecl(); |
| 8389 | } else if (ASE) { |
| 8390 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8391 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8392 | } else if (OASE) { |
| 8393 | auto *B = OASE->getBase(); |
| 8394 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8395 | } |
| 8396 | assert(D && "Null decl on map clause."); |
| 8397 | auto *VD = cast<VarDecl>(D); |
| 8398 | |
| 8399 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8400 | // threadprivate variables cannot appear in a map clause. |
| 8401 | if (DSAStack->isThreadPrivate(VD)) { |
| 8402 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8403 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8404 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8405 | continue; |
| 8406 | } |
| 8407 | |
| 8408 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8409 | // At most one list item can be an array item derived from a given variable |
| 8410 | // in map clauses of the same construct. |
| 8411 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8412 | // List items of map clauses in the same construct must not share original |
| 8413 | // storage. |
| 8414 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8415 | // A variable for which the type is pointer, reference to array, or |
| 8416 | // reference to pointer and an array section derived from that variable |
| 8417 | // must not appear as list items of map clauses of the same construct. |
| 8418 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8419 | if (MI.RefExpr) { |
| 8420 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8421 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8422 | << MI.RefExpr->getSourceRange(); |
| 8423 | continue; |
| 8424 | } |
| 8425 | |
| 8426 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8427 | // A variable for which the type is pointer, reference to array, or |
| 8428 | // reference to pointer must not appear as a list item if the enclosing |
| 8429 | // device data environment already contains an array section derived from |
| 8430 | // that variable. |
| 8431 | // An array section derived from a variable for which the type is pointer, |
| 8432 | // reference to array, or reference to pointer must not appear as a list |
| 8433 | // item if the enclosing device data environment already contains that |
| 8434 | // variable. |
| 8435 | QualType Type = VD->getType(); |
| 8436 | MI = DSAStack->getMapInfoForVar(VD); |
| 8437 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8438 | isa<DeclRefExpr>(VE)) && |
| 8439 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8440 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8441 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8442 | << MI.RefExpr->getSourceRange(); |
| 8443 | continue; |
| 8444 | } |
| 8445 | |
| 8446 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8447 | // A list item must have a mappable type. |
| 8448 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8449 | DSAStack, Type)) |
| 8450 | continue; |
| 8451 | |
| 8452 | Vars.push_back(RE); |
| 8453 | MI.RefExpr = RE; |
| 8454 | DSAStack->addMapInfoForVar(VD, MI); |
| 8455 | } |
| 8456 | if (Vars.empty()) |
| 8457 | return nullptr; |
| 8458 | |
| 8459 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8460 | MapTypeModifier, MapType, MapLoc); |
| 8461 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8462 | |
| 8463 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8464 | SourceLocation StartLoc, |
| 8465 | SourceLocation LParenLoc, |
| 8466 | SourceLocation EndLoc) { |
| 8467 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8468 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8469 | // OpenMP [teams Constrcut, Restrictions] |
| 8470 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8471 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8472 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8473 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8474 | |
| 8475 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8476 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8477 | |
| 8478 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8479 | SourceLocation StartLoc, |
| 8480 | SourceLocation LParenLoc, |
| 8481 | SourceLocation EndLoc) { |
| 8482 | Expr *ValExpr = ThreadLimit; |
| 8483 | |
| 8484 | // OpenMP [teams Constrcut, Restrictions] |
| 8485 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8486 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8487 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8488 | return nullptr; |
| 8489 | |
| 8490 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8491 | EndLoc); |
| 8492 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8493 | |
| 8494 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8495 | SourceLocation StartLoc, |
| 8496 | SourceLocation LParenLoc, |
| 8497 | SourceLocation EndLoc) { |
| 8498 | Expr *ValExpr = Priority; |
| 8499 | |
| 8500 | // OpenMP [2.9.1, task Constrcut] |
| 8501 | // The priority-value is a non-negative numerical scalar expression. |
| 8502 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8503 | /*StrictlyPositive=*/false)) |
| 8504 | return nullptr; |
| 8505 | |
| 8506 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8507 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8508 | |
| 8509 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8510 | SourceLocation StartLoc, |
| 8511 | SourceLocation LParenLoc, |
| 8512 | SourceLocation EndLoc) { |
| 8513 | Expr *ValExpr = Grainsize; |
| 8514 | |
| 8515 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8516 | // The parameter of the grainsize clause must be a positive integer |
| 8517 | // expression. |
| 8518 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8519 | /*StrictlyPositive=*/true)) |
| 8520 | return nullptr; |
| 8521 | |
| 8522 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8523 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8524 | |
| 8525 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 8526 | SourceLocation StartLoc, |
| 8527 | SourceLocation LParenLoc, |
| 8528 | SourceLocation EndLoc) { |
| 8529 | Expr *ValExpr = NumTasks; |
| 8530 | |
| 8531 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8532 | // The parameter of the num_tasks clause must be a positive integer |
| 8533 | // expression. |
| 8534 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 8535 | /*StrictlyPositive=*/true)) |
| 8536 | return nullptr; |
| 8537 | |
| 8538 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8539 | } |
| 8540 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8541 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 8542 | SourceLocation LParenLoc, |
| 8543 | SourceLocation EndLoc) { |
| 8544 | // OpenMP [2.13.2, critical construct, Description] |
| 8545 | // ... where hint-expression is an integer constant expression that evaluates |
| 8546 | // to a valid lock hint. |
| 8547 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 8548 | if (HintExpr.isInvalid()) |
| 8549 | return nullptr; |
| 8550 | return new (Context) |
| 8551 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 8552 | } |
| 8553 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8554 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 8555 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 8556 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 8557 | SourceLocation EndLoc) { |
| 8558 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 8559 | std::string Values; |
| 8560 | Values += "'"; |
| 8561 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 8562 | Values += "'"; |
| 8563 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 8564 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 8565 | return nullptr; |
| 8566 | } |
| 8567 | Expr *ValExpr = ChunkSize; |
| 8568 | Expr *HelperValExpr = nullptr; |
| 8569 | if (ChunkSize) { |
| 8570 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 8571 | !ChunkSize->isInstantiationDependent() && |
| 8572 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 8573 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 8574 | ExprResult Val = |
| 8575 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 8576 | if (Val.isInvalid()) |
| 8577 | return nullptr; |
| 8578 | |
| 8579 | ValExpr = Val.get(); |
| 8580 | |
| 8581 | // OpenMP [2.7.1, Restrictions] |
| 8582 | // chunk_size must be a loop invariant integer expression with a positive |
| 8583 | // value. |
| 8584 | llvm::APSInt Result; |
| 8585 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 8586 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 8587 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 8588 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 8589 | return nullptr; |
| 8590 | } |
| 8591 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 8592 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 8593 | ChunkSize->getType(), ".chunk."); |
| 8594 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 8595 | ChunkSize->getExprLoc(), |
| 8596 | /*RefersToCapture=*/true); |
| 8597 | HelperValExpr = ImpVarRef; |
| 8598 | } |
| 8599 | } |
| 8600 | } |
| 8601 | |
| 8602 | return new (Context) |
| 8603 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 8604 | Kind, ValExpr, HelperValExpr); |
| 8605 | } |