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 | } |
| 1144 | return DeclGroupPtrTy(); |
| 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 | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1625 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1626 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1627 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1628 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1629 | (getLangOpts().OpenMPUseTLS && |
| 1630 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1631 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1632 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1633 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1634 | for (auto *VarRef : Clause->children()) { |
| 1635 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1636 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1637 | } |
| 1638 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1639 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1640 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1641 | Clause->getClauseKind() == OMPC_schedule) { |
| 1642 | // Mark all variables in private list clauses as used in inner region. |
| 1643 | // Required for proper codegen of combined directives. |
| 1644 | // TODO: add processing for other clauses. |
| 1645 | if (auto *E = cast_or_null<Expr>( |
| 1646 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1647 | MarkDeclarationsReferencedInExpr(E); |
| 1648 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | return ActOnCapturedRegionEnd(S.get()); |
| 1652 | } |
| 1653 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1654 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1655 | OpenMPDirectiveKind CurrentRegion, |
| 1656 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1657 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1658 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1659 | // Allowed nesting of constructs |
| 1660 | // +------------------+-----------------+------------------------------------+ |
| 1661 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1662 | // +------------------+-----------------+------------------------------------+ |
| 1663 | // | parallel | parallel | * | |
| 1664 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1665 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1666 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1667 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1668 | // | parallel | simd | * | |
| 1669 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1670 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1671 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1672 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1673 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1674 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1675 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1676 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1677 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1678 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1679 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1680 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1681 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1682 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1683 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1684 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1685 | // | parallel | cancellation | | |
| 1686 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1687 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1688 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1689 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1690 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1691 | // +------------------+-----------------+------------------------------------+ |
| 1692 | // | for | parallel | * | |
| 1693 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1694 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1695 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1696 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1697 | // | for | simd | * | |
| 1698 | // | for | sections | + | |
| 1699 | // | for | section | + | |
| 1700 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1701 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1702 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1703 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1704 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1705 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1706 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1707 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1708 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1709 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1710 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1711 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1712 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1713 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1714 | // | for | cancellation | | |
| 1715 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1716 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1717 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1718 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1719 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1720 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1721 | // | master | parallel | * | |
| 1722 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1723 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1724 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1725 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1726 | // | master | simd | * | |
| 1727 | // | master | sections | + | |
| 1728 | // | master | section | + | |
| 1729 | // | master | single | + | |
| 1730 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1731 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1732 | // | master |parallel sections| * | |
| 1733 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1734 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1735 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1736 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1737 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1738 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1739 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1740 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1741 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1742 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1743 | // | master | cancellation | | |
| 1744 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1745 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1746 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1747 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1748 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1749 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1750 | // | critical | parallel | * | |
| 1751 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1752 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1753 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1754 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1755 | // | critical | simd | * | |
| 1756 | // | critical | sections | + | |
| 1757 | // | critical | section | + | |
| 1758 | // | critical | single | + | |
| 1759 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1760 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1761 | // | critical |parallel sections| * | |
| 1762 | // | critical | task | * | |
| 1763 | // | critical | taskyield | * | |
| 1764 | // | critical | barrier | + | |
| 1765 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1766 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1767 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1768 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1769 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1770 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1771 | // | critical | cancellation | | |
| 1772 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1773 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1774 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1775 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1776 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1777 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1778 | // | simd | parallel | | |
| 1779 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1780 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1781 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1782 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1783 | // | simd | simd | | |
| 1784 | // | simd | sections | | |
| 1785 | // | simd | section | | |
| 1786 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1787 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1788 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1789 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1790 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1791 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1792 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1793 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1794 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1795 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1796 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1797 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1798 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1799 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1800 | // | simd | cancellation | | |
| 1801 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1802 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1803 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1804 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1805 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1806 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1807 | // | for simd | parallel | | |
| 1808 | // | for simd | for | | |
| 1809 | // | for simd | for simd | | |
| 1810 | // | for simd | master | | |
| 1811 | // | for simd | critical | | |
| 1812 | // | for simd | simd | | |
| 1813 | // | for simd | sections | | |
| 1814 | // | for simd | section | | |
| 1815 | // | for simd | single | | |
| 1816 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1817 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1818 | // | for simd |parallel sections| | |
| 1819 | // | for simd | task | | |
| 1820 | // | for simd | taskyield | | |
| 1821 | // | for simd | barrier | | |
| 1822 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1823 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1824 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1825 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1826 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1827 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1828 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1829 | // | for simd | cancellation | | |
| 1830 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1831 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1832 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1833 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1834 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1835 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1836 | // | parallel for simd| parallel | | |
| 1837 | // | parallel for simd| for | | |
| 1838 | // | parallel for simd| for simd | | |
| 1839 | // | parallel for simd| master | | |
| 1840 | // | parallel for simd| critical | | |
| 1841 | // | parallel for simd| simd | | |
| 1842 | // | parallel for simd| sections | | |
| 1843 | // | parallel for simd| section | | |
| 1844 | // | parallel for simd| single | | |
| 1845 | // | parallel for simd| parallel for | | |
| 1846 | // | parallel for simd|parallel for simd| | |
| 1847 | // | parallel for simd|parallel sections| | |
| 1848 | // | parallel for simd| task | | |
| 1849 | // | parallel for simd| taskyield | | |
| 1850 | // | parallel for simd| barrier | | |
| 1851 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1852 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1853 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1854 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1855 | // | parallel for simd| atomic | | |
| 1856 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1857 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1858 | // | parallel for simd| cancellation | | |
| 1859 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1860 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1861 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1862 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1863 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1864 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1865 | // | sections | parallel | * | |
| 1866 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1867 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1868 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1869 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1870 | // | sections | simd | * | |
| 1871 | // | sections | sections | + | |
| 1872 | // | sections | section | * | |
| 1873 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1874 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1875 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1876 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1877 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1878 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1879 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1880 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1881 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1882 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1883 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1884 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1885 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1886 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1887 | // | sections | cancellation | | |
| 1888 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1889 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1890 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1891 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1892 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1893 | // +------------------+-----------------+------------------------------------+ |
| 1894 | // | section | parallel | * | |
| 1895 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1896 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1897 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1898 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1899 | // | section | simd | * | |
| 1900 | // | section | sections | + | |
| 1901 | // | section | section | + | |
| 1902 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1903 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1904 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1905 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1906 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1907 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1908 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1909 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1910 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1911 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1912 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1913 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1914 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1915 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1916 | // | section | cancellation | | |
| 1917 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1918 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1919 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1920 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1921 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1922 | // +------------------+-----------------+------------------------------------+ |
| 1923 | // | single | parallel | * | |
| 1924 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1925 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1926 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1927 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1928 | // | single | simd | * | |
| 1929 | // | single | sections | + | |
| 1930 | // | single | section | + | |
| 1931 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1932 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1933 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1934 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1935 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1936 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1937 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1938 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1939 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1940 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1941 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1942 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1943 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1944 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1945 | // | single | cancellation | | |
| 1946 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1947 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1948 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1949 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1950 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1951 | // +------------------+-----------------+------------------------------------+ |
| 1952 | // | parallel for | parallel | * | |
| 1953 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1954 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1955 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1956 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1957 | // | parallel for | simd | * | |
| 1958 | // | parallel for | sections | + | |
| 1959 | // | parallel for | section | + | |
| 1960 | // | parallel for | single | + | |
| 1961 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1962 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1963 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1964 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1965 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1966 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1967 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1968 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1969 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1970 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1971 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1972 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1973 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1974 | // | parallel for | cancellation | | |
| 1975 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1976 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1977 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1978 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1979 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1980 | // +------------------+-----------------+------------------------------------+ |
| 1981 | // | parallel sections| parallel | * | |
| 1982 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1983 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1984 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1985 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1986 | // | parallel sections| simd | * | |
| 1987 | // | parallel sections| sections | + | |
| 1988 | // | parallel sections| section | * | |
| 1989 | // | parallel sections| single | + | |
| 1990 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1991 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1992 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1993 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1994 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1995 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1996 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1997 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1998 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1999 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2000 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2001 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2002 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2003 | // | parallel sections| cancellation | | |
| 2004 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2005 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2006 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2007 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2008 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2009 | // +------------------+-----------------+------------------------------------+ |
| 2010 | // | task | parallel | * | |
| 2011 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2012 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2013 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2014 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2015 | // | task | simd | * | |
| 2016 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2017 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2018 | // | task | single | + | |
| 2019 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2020 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2021 | // | task |parallel sections| * | |
| 2022 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2023 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2024 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2025 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2026 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2027 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2028 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2029 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2030 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2031 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2032 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2033 | // | | point | ! | |
| 2034 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2035 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2036 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2037 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2038 | // +------------------+-----------------+------------------------------------+ |
| 2039 | // | ordered | parallel | * | |
| 2040 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2041 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2042 | // | ordered | master | * | |
| 2043 | // | ordered | critical | * | |
| 2044 | // | ordered | simd | * | |
| 2045 | // | ordered | sections | + | |
| 2046 | // | ordered | section | + | |
| 2047 | // | ordered | single | + | |
| 2048 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2049 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2050 | // | ordered |parallel sections| * | |
| 2051 | // | ordered | task | * | |
| 2052 | // | ordered | taskyield | * | |
| 2053 | // | ordered | barrier | + | |
| 2054 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2055 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2056 | // | ordered | flush | * | |
| 2057 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2058 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2059 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2060 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2061 | // | ordered | cancellation | | |
| 2062 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2063 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2064 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2065 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2066 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2067 | // +------------------+-----------------+------------------------------------+ |
| 2068 | // | atomic | parallel | | |
| 2069 | // | atomic | for | | |
| 2070 | // | atomic | for simd | | |
| 2071 | // | atomic | master | | |
| 2072 | // | atomic | critical | | |
| 2073 | // | atomic | simd | | |
| 2074 | // | atomic | sections | | |
| 2075 | // | atomic | section | | |
| 2076 | // | atomic | single | | |
| 2077 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2078 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2079 | // | atomic |parallel sections| | |
| 2080 | // | atomic | task | | |
| 2081 | // | atomic | taskyield | | |
| 2082 | // | atomic | barrier | | |
| 2083 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2084 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2085 | // | atomic | flush | | |
| 2086 | // | atomic | ordered | | |
| 2087 | // | atomic | atomic | | |
| 2088 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2089 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2090 | // | atomic | cancellation | | |
| 2091 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2092 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2093 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2094 | // | atomic | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2095 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2096 | // +------------------+-----------------+------------------------------------+ |
| 2097 | // | target | parallel | * | |
| 2098 | // | target | for | * | |
| 2099 | // | target | for simd | * | |
| 2100 | // | target | master | * | |
| 2101 | // | target | critical | * | |
| 2102 | // | target | simd | * | |
| 2103 | // | target | sections | * | |
| 2104 | // | target | section | * | |
| 2105 | // | target | single | * | |
| 2106 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2107 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2108 | // | target |parallel sections| * | |
| 2109 | // | target | task | * | |
| 2110 | // | target | taskyield | * | |
| 2111 | // | target | barrier | * | |
| 2112 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2113 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2114 | // | target | flush | * | |
| 2115 | // | target | ordered | * | |
| 2116 | // | target | atomic | * | |
| 2117 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2118 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2119 | // | target | cancellation | | |
| 2120 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2121 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2122 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2123 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2124 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2125 | // +------------------+-----------------+------------------------------------+ |
| 2126 | // | teams | parallel | * | |
| 2127 | // | teams | for | + | |
| 2128 | // | teams | for simd | + | |
| 2129 | // | teams | master | + | |
| 2130 | // | teams | critical | + | |
| 2131 | // | teams | simd | + | |
| 2132 | // | teams | sections | + | |
| 2133 | // | teams | section | + | |
| 2134 | // | teams | single | + | |
| 2135 | // | teams | parallel for | * | |
| 2136 | // | teams |parallel for simd| * | |
| 2137 | // | teams |parallel sections| * | |
| 2138 | // | teams | task | + | |
| 2139 | // | teams | taskyield | + | |
| 2140 | // | teams | barrier | + | |
| 2141 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2142 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2143 | // | teams | flush | + | |
| 2144 | // | teams | ordered | + | |
| 2145 | // | teams | atomic | + | |
| 2146 | // | teams | target | + | |
| 2147 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2148 | // | teams | cancellation | | |
| 2149 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2150 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2151 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2152 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2153 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2154 | // +------------------+-----------------+------------------------------------+ |
| 2155 | // | taskloop | parallel | * | |
| 2156 | // | taskloop | for | + | |
| 2157 | // | taskloop | for simd | + | |
| 2158 | // | taskloop | master | + | |
| 2159 | // | taskloop | critical | * | |
| 2160 | // | taskloop | simd | * | |
| 2161 | // | taskloop | sections | + | |
| 2162 | // | taskloop | section | + | |
| 2163 | // | taskloop | single | + | |
| 2164 | // | taskloop | parallel for | * | |
| 2165 | // | taskloop |parallel for simd| * | |
| 2166 | // | taskloop |parallel sections| * | |
| 2167 | // | taskloop | task | * | |
| 2168 | // | taskloop | taskyield | * | |
| 2169 | // | taskloop | barrier | + | |
| 2170 | // | taskloop | taskwait | * | |
| 2171 | // | taskloop | taskgroup | * | |
| 2172 | // | taskloop | flush | * | |
| 2173 | // | taskloop | ordered | + | |
| 2174 | // | taskloop | atomic | * | |
| 2175 | // | taskloop | target | * | |
| 2176 | // | taskloop | teams | + | |
| 2177 | // | taskloop | cancellation | | |
| 2178 | // | | point | | |
| 2179 | // | taskloop | cancel | | |
| 2180 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2181 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2182 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2183 | // | taskloop simd | parallel | | |
| 2184 | // | taskloop simd | for | | |
| 2185 | // | taskloop simd | for simd | | |
| 2186 | // | taskloop simd | master | | |
| 2187 | // | taskloop simd | critical | | |
| 2188 | // | taskloop simd | simd | | |
| 2189 | // | taskloop simd | sections | | |
| 2190 | // | taskloop simd | section | | |
| 2191 | // | taskloop simd | single | | |
| 2192 | // | taskloop simd | parallel for | | |
| 2193 | // | taskloop simd |parallel for simd| | |
| 2194 | // | taskloop simd |parallel sections| | |
| 2195 | // | taskloop simd | task | | |
| 2196 | // | taskloop simd | taskyield | | |
| 2197 | // | taskloop simd | barrier | | |
| 2198 | // | taskloop simd | taskwait | | |
| 2199 | // | taskloop simd | taskgroup | | |
| 2200 | // | taskloop simd | flush | | |
| 2201 | // | taskloop simd | ordered | + (with simd clause) | |
| 2202 | // | taskloop simd | atomic | | |
| 2203 | // | taskloop simd | target | | |
| 2204 | // | taskloop simd | teams | | |
| 2205 | // | taskloop simd | cancellation | | |
| 2206 | // | | point | | |
| 2207 | // | taskloop simd | cancel | | |
| 2208 | // | taskloop simd | taskloop | | |
| 2209 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2210 | // | taskloop simd | distribute | | |
| 2211 | // +------------------+-----------------+------------------------------------+ |
| 2212 | // | distribute | parallel | * | |
| 2213 | // | distribute | for | * | |
| 2214 | // | distribute | for simd | * | |
| 2215 | // | distribute | master | * | |
| 2216 | // | distribute | critical | * | |
| 2217 | // | distribute | simd | * | |
| 2218 | // | distribute | sections | * | |
| 2219 | // | distribute | section | * | |
| 2220 | // | distribute | single | * | |
| 2221 | // | distribute | parallel for | * | |
| 2222 | // | distribute |parallel for simd| * | |
| 2223 | // | distribute |parallel sections| * | |
| 2224 | // | distribute | task | * | |
| 2225 | // | distribute | taskyield | * | |
| 2226 | // | distribute | barrier | * | |
| 2227 | // | distribute | taskwait | * | |
| 2228 | // | distribute | taskgroup | * | |
| 2229 | // | distribute | flush | * | |
| 2230 | // | distribute | ordered | + | |
| 2231 | // | distribute | atomic | * | |
| 2232 | // | distribute | target | | |
| 2233 | // | distribute | teams | | |
| 2234 | // | distribute | cancellation | + | |
| 2235 | // | | point | | |
| 2236 | // | distribute | cancel | + | |
| 2237 | // | distribute | taskloop | * | |
| 2238 | // | distribute | taskloop simd | * | |
| 2239 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2240 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2241 | if (Stack->getCurScope()) { |
| 2242 | auto ParentRegion = Stack->getParentDirective(); |
| 2243 | bool NestingProhibited = false; |
| 2244 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2245 | enum { |
| 2246 | NoRecommend, |
| 2247 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2248 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2249 | ShouldBeInTargetRegion, |
| 2250 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2251 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2252 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2253 | // OpenMP [2.16, Nesting of Regions] |
| 2254 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2255 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2256 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2257 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2258 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2259 | return true; |
| 2260 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2261 | if (ParentRegion == OMPD_atomic) { |
| 2262 | // OpenMP [2.16, Nesting of Regions] |
| 2263 | // OpenMP constructs may not be nested inside an atomic region. |
| 2264 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2265 | return true; |
| 2266 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2267 | if (CurrentRegion == OMPD_section) { |
| 2268 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2269 | // Orphaned section directives are prohibited. That is, the section |
| 2270 | // directives must appear within the sections construct and must not be |
| 2271 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2272 | if (ParentRegion != OMPD_sections && |
| 2273 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2274 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2275 | << (ParentRegion != OMPD_unknown) |
| 2276 | << getOpenMPDirectiveName(ParentRegion); |
| 2277 | return true; |
| 2278 | } |
| 2279 | return false; |
| 2280 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2281 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2282 | // called from OpenMP regions with the required preconditions). |
| 2283 | if (ParentRegion == OMPD_unknown) |
| 2284 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2285 | if (CurrentRegion == OMPD_cancellation_point || |
| 2286 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2287 | // OpenMP [2.16, Nesting of Regions] |
| 2288 | // A cancellation point construct for which construct-type-clause is |
| 2289 | // taskgroup must be nested inside a task construct. A cancellation |
| 2290 | // point construct for which construct-type-clause is not taskgroup must |
| 2291 | // be closely nested inside an OpenMP construct that matches the type |
| 2292 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2293 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2294 | // nested inside a task construct. A cancel construct for which |
| 2295 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2296 | // OpenMP construct that matches the type specified in |
| 2297 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2298 | NestingProhibited = |
| 2299 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2300 | (CancelRegion == OMPD_for && |
| 2301 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2302 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2303 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2304 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2305 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2306 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2307 | // OpenMP [2.16, Nesting of Regions] |
| 2308 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2309 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2310 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2311 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2312 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2313 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2314 | // OpenMP [2.16, Nesting of Regions] |
| 2315 | // A critical region may not be nested (closely or otherwise) inside a |
| 2316 | // critical region with the same name. Note that this restriction is not |
| 2317 | // sufficient to prevent deadlock. |
| 2318 | SourceLocation PreviousCriticalLoc; |
| 2319 | bool DeadLock = |
| 2320 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2321 | OpenMPDirectiveKind K, |
| 2322 | const DeclarationNameInfo &DNI, |
| 2323 | SourceLocation Loc) |
| 2324 | ->bool { |
| 2325 | if (K == OMPD_critical && |
| 2326 | DNI.getName() == CurrentName.getName()) { |
| 2327 | PreviousCriticalLoc = Loc; |
| 2328 | return true; |
| 2329 | } else |
| 2330 | return false; |
| 2331 | }, |
| 2332 | false /* skip top directive */); |
| 2333 | if (DeadLock) { |
| 2334 | SemaRef.Diag(StartLoc, |
| 2335 | diag::err_omp_prohibited_region_critical_same_name) |
| 2336 | << CurrentName.getName(); |
| 2337 | if (PreviousCriticalLoc.isValid()) |
| 2338 | SemaRef.Diag(PreviousCriticalLoc, |
| 2339 | diag::note_omp_previous_critical_region); |
| 2340 | return true; |
| 2341 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2342 | } else if (CurrentRegion == OMPD_barrier) { |
| 2343 | // OpenMP [2.16, Nesting of Regions] |
| 2344 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2345 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2346 | NestingProhibited = |
| 2347 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2348 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2349 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2350 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2351 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2352 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2353 | // OpenMP [2.16, Nesting of Regions] |
| 2354 | // A worksharing region may not be closely nested inside a worksharing, |
| 2355 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2356 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2357 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2358 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2359 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2360 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2361 | Recommend = ShouldBeInParallelRegion; |
| 2362 | } else if (CurrentRegion == OMPD_ordered) { |
| 2363 | // OpenMP [2.16, Nesting of Regions] |
| 2364 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2365 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2366 | // An ordered region must be closely nested inside a loop region (or |
| 2367 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2368 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2369 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2370 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2371 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2372 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2373 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2374 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2375 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2376 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2377 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2378 | // OpenMP [2.16, Nesting of Regions] |
| 2379 | // If specified, a teams construct must be contained within a target |
| 2380 | // construct. |
| 2381 | NestingProhibited = ParentRegion != OMPD_target; |
| 2382 | Recommend = ShouldBeInTargetRegion; |
| 2383 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2384 | } |
| 2385 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2386 | // OpenMP [2.16, Nesting of Regions] |
| 2387 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2388 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2389 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2390 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2391 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2392 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2393 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2394 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2395 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2396 | // The region associated with the distribute construct must be strictly |
| 2397 | // nested inside a teams region |
| 2398 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2399 | Recommend = ShouldBeInTeamsRegion; |
| 2400 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2401 | if (NestingProhibited) { |
| 2402 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2403 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2404 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2405 | return true; |
| 2406 | } |
| 2407 | } |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2411 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2412 | ArrayRef<OMPClause *> Clauses, |
| 2413 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2414 | bool ErrorFound = false; |
| 2415 | unsigned NamedModifiersNumber = 0; |
| 2416 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2417 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2418 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2419 | for (const auto *C : Clauses) { |
| 2420 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2421 | // At most one if clause without a directive-name-modifier can appear on |
| 2422 | // the directive. |
| 2423 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2424 | if (FoundNameModifiers[CurNM]) { |
| 2425 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2426 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2427 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2428 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2429 | } else if (CurNM != OMPD_unknown) { |
| 2430 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2431 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2432 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2433 | FoundNameModifiers[CurNM] = IC; |
| 2434 | if (CurNM == OMPD_unknown) |
| 2435 | continue; |
| 2436 | // Check if the specified name modifier is allowed for the current |
| 2437 | // directive. |
| 2438 | // At most one if clause with the particular directive-name-modifier can |
| 2439 | // appear on the directive. |
| 2440 | bool MatchFound = false; |
| 2441 | for (auto NM : AllowedNameModifiers) { |
| 2442 | if (CurNM == NM) { |
| 2443 | MatchFound = true; |
| 2444 | break; |
| 2445 | } |
| 2446 | } |
| 2447 | if (!MatchFound) { |
| 2448 | S.Diag(IC->getNameModifierLoc(), |
| 2449 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2450 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2451 | ErrorFound = true; |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | // If any if clause on the directive includes a directive-name-modifier then |
| 2456 | // all if clauses on the directive must include a directive-name-modifier. |
| 2457 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2458 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2459 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2460 | diag::err_omp_no_more_if_clause); |
| 2461 | } else { |
| 2462 | std::string Values; |
| 2463 | std::string Sep(", "); |
| 2464 | unsigned AllowedCnt = 0; |
| 2465 | unsigned TotalAllowedNum = |
| 2466 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2467 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2468 | ++Cnt) { |
| 2469 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2470 | if (!FoundNameModifiers[NM]) { |
| 2471 | Values += "'"; |
| 2472 | Values += getOpenMPDirectiveName(NM); |
| 2473 | Values += "'"; |
| 2474 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2475 | Values += " or "; |
| 2476 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2477 | Values += Sep; |
| 2478 | ++AllowedCnt; |
| 2479 | } |
| 2480 | } |
| 2481 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2482 | diag::err_omp_unnamed_if_clause) |
| 2483 | << (TotalAllowedNum > 1) << Values; |
| 2484 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2485 | for (auto Loc : NameModifierLoc) { |
| 2486 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2487 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2488 | ErrorFound = true; |
| 2489 | } |
| 2490 | return ErrorFound; |
| 2491 | } |
| 2492 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2493 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2494 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2495 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2496 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2497 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2498 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2499 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2500 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2501 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2502 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2503 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2504 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2505 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2506 | if (AStmt) { |
| 2507 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2508 | |
| 2509 | // Check default data sharing attributes for referenced variables. |
| 2510 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2511 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2512 | if (DSAChecker.isErrorFound()) |
| 2513 | return StmtError(); |
| 2514 | // Generate list of implicitly defined firstprivate variables. |
| 2515 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2516 | |
| 2517 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2518 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2519 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2520 | SourceLocation(), SourceLocation())) { |
| 2521 | ClausesWithImplicit.push_back(Implicit); |
| 2522 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2523 | DSAChecker.getImplicitFirstprivate().size(); |
| 2524 | } else |
| 2525 | ErrorFound = true; |
| 2526 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2527 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2528 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2529 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2530 | switch (Kind) { |
| 2531 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2532 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2533 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2534 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2535 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2536 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2537 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2538 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2539 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2540 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2541 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2542 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2543 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2544 | case OMPD_for_simd: |
| 2545 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2546 | EndLoc, VarsWithInheritedDSA); |
| 2547 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2548 | case OMPD_sections: |
| 2549 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2550 | EndLoc); |
| 2551 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2552 | case OMPD_section: |
| 2553 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2554 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2555 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2556 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2557 | case OMPD_single: |
| 2558 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2559 | EndLoc); |
| 2560 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2561 | case OMPD_master: |
| 2562 | assert(ClausesWithImplicit.empty() && |
| 2563 | "No clauses are allowed for 'omp master' directive"); |
| 2564 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2565 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2566 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2567 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2568 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2569 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2570 | case OMPD_parallel_for: |
| 2571 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2572 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2573 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2574 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2575 | case OMPD_parallel_for_simd: |
| 2576 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2577 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2578 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2579 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2580 | case OMPD_parallel_sections: |
| 2581 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2582 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2583 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2584 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2585 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2586 | Res = |
| 2587 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2588 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2589 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2590 | case OMPD_taskyield: |
| 2591 | assert(ClausesWithImplicit.empty() && |
| 2592 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2593 | assert(AStmt == nullptr && |
| 2594 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2595 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2596 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2597 | case OMPD_barrier: |
| 2598 | assert(ClausesWithImplicit.empty() && |
| 2599 | "No clauses are allowed for 'omp barrier' directive"); |
| 2600 | assert(AStmt == nullptr && |
| 2601 | "No associated statement allowed for 'omp barrier' directive"); |
| 2602 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2603 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2604 | case OMPD_taskwait: |
| 2605 | assert(ClausesWithImplicit.empty() && |
| 2606 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2607 | assert(AStmt == nullptr && |
| 2608 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2609 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2610 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2611 | case OMPD_taskgroup: |
| 2612 | assert(ClausesWithImplicit.empty() && |
| 2613 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2614 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2615 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2616 | case OMPD_flush: |
| 2617 | assert(AStmt == nullptr && |
| 2618 | "No associated statement allowed for 'omp flush' directive"); |
| 2619 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2620 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2621 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2622 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2623 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2624 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2625 | case OMPD_atomic: |
| 2626 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2627 | EndLoc); |
| 2628 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2629 | case OMPD_teams: |
| 2630 | Res = |
| 2631 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2632 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2633 | case OMPD_target: |
| 2634 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2635 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2636 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2637 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2638 | case OMPD_cancellation_point: |
| 2639 | assert(ClausesWithImplicit.empty() && |
| 2640 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2641 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2642 | "cancellation point' directive"); |
| 2643 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2644 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2645 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2646 | assert(AStmt == nullptr && |
| 2647 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2648 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2649 | CancelRegion); |
| 2650 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2651 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2652 | case OMPD_target_data: |
| 2653 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2654 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2655 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2656 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2657 | case OMPD_taskloop: |
| 2658 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2659 | EndLoc, VarsWithInheritedDSA); |
| 2660 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2661 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2662 | case OMPD_taskloop_simd: |
| 2663 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2664 | EndLoc, VarsWithInheritedDSA); |
| 2665 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2666 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2667 | case OMPD_distribute: |
| 2668 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2669 | EndLoc, VarsWithInheritedDSA); |
| 2670 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2671 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2672 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2673 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2674 | llvm_unreachable("Unknown OpenMP directive"); |
| 2675 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2676 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2677 | for (auto P : VarsWithInheritedDSA) { |
| 2678 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2679 | << P.first << P.second->getSourceRange(); |
| 2680 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2681 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2682 | |
| 2683 | if (!AllowedNameModifiers.empty()) |
| 2684 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2685 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2686 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2687 | if (ErrorFound) |
| 2688 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2689 | return Res; |
| 2690 | } |
| 2691 | |
| 2692 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2693 | Stmt *AStmt, |
| 2694 | SourceLocation StartLoc, |
| 2695 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2696 | if (!AStmt) |
| 2697 | return StmtError(); |
| 2698 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2699 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2700 | // 1.2.2 OpenMP Language Terminology |
| 2701 | // Structured block - An executable statement with a single entry at the |
| 2702 | // top and a single exit at the bottom. |
| 2703 | // The point of exit cannot be a branch out of the structured block. |
| 2704 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2705 | CS->getCapturedDecl()->setNothrow(); |
| 2706 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2707 | getCurFunction()->setHasBranchProtectedScope(); |
| 2708 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2709 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2710 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2711 | } |
| 2712 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2713 | namespace { |
| 2714 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2715 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2716 | /// for IR generation. |
| 2717 | class OpenMPIterationSpaceChecker { |
| 2718 | /// \brief Reference to Sema. |
| 2719 | Sema &SemaRef; |
| 2720 | /// \brief A location for diagnostics (when there is no some better location). |
| 2721 | SourceLocation DefaultLoc; |
| 2722 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2723 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2724 | /// \brief A source location for referring to loop init later. |
| 2725 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2726 | /// \brief A source location for referring to condition later. |
| 2727 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2728 | /// \brief A source location for referring to increment later. |
| 2729 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2730 | /// \brief Loop variable. |
| 2731 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2732 | /// \brief Reference to loop variable. |
| 2733 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2734 | /// \brief Lower bound (initializer for the var). |
| 2735 | Expr *LB; |
| 2736 | /// \brief Upper bound. |
| 2737 | Expr *UB; |
| 2738 | /// \brief Loop step (increment). |
| 2739 | Expr *Step; |
| 2740 | /// \brief This flag is true when condition is one of: |
| 2741 | /// Var < UB |
| 2742 | /// Var <= UB |
| 2743 | /// UB > Var |
| 2744 | /// UB >= Var |
| 2745 | bool TestIsLessOp; |
| 2746 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2747 | bool TestIsStrictOp; |
| 2748 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2749 | bool SubtractStep; |
| 2750 | |
| 2751 | public: |
| 2752 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2753 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2754 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2755 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2756 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2757 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2758 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2759 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2760 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2761 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2762 | /// for less/greater and for strict/non-strict comparison. |
| 2763 | bool CheckCond(Expr *S); |
| 2764 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2765 | /// does not conform, otherwise save loop step (#Step). |
| 2766 | bool CheckInc(Expr *S); |
| 2767 | /// \brief Return the loop counter variable. |
| 2768 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2769 | /// \brief Return the reference expression to loop counter variable. |
| 2770 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2771 | /// \brief Source range of the loop init. |
| 2772 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2773 | /// \brief Source range of the loop condition. |
| 2774 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2775 | /// \brief Source range of the loop increment. |
| 2776 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2777 | /// \brief True if the step should be subtracted. |
| 2778 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2779 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2780 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2781 | /// \brief Build the precondition expression for the loops. |
| 2782 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2783 | /// \brief Build reference expression to the counter be used for codegen. |
| 2784 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2785 | /// \brief Build reference expression to the private counter be used for |
| 2786 | /// codegen. |
| 2787 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2788 | /// \brief Build initization of the counter be used for codegen. |
| 2789 | Expr *BuildCounterInit() const; |
| 2790 | /// \brief Build step of the counter be used for codegen. |
| 2791 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2792 | /// \brief Return true if any expression is dependent. |
| 2793 | bool Dependent() const; |
| 2794 | |
| 2795 | private: |
| 2796 | /// \brief Check the right-hand side of an assignment in the increment |
| 2797 | /// expression. |
| 2798 | bool CheckIncRHS(Expr *RHS); |
| 2799 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2800 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2801 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2802 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2803 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2804 | /// \brief Helper to set loop increment. |
| 2805 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2806 | }; |
| 2807 | |
| 2808 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2809 | if (!Var) { |
| 2810 | assert(!LB && !UB && !Step); |
| 2811 | return false; |
| 2812 | } |
| 2813 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2814 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2815 | } |
| 2816 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2817 | template <typename T> |
| 2818 | static T *getExprAsWritten(T *E) { |
| 2819 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2820 | E = ExprTemp->getSubExpr(); |
| 2821 | |
| 2822 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2823 | E = MTE->GetTemporaryExpr(); |
| 2824 | |
| 2825 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2826 | E = Binder->getSubExpr(); |
| 2827 | |
| 2828 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2829 | E = ICE->getSubExprAsWritten(); |
| 2830 | return E->IgnoreParens(); |
| 2831 | } |
| 2832 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2833 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2834 | DeclRefExpr *NewVarRefExpr, |
| 2835 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2836 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2837 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2838 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2839 | if (!NewVar || !NewLB) |
| 2840 | return true; |
| 2841 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2842 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2843 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2844 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2845 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2846 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2847 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2848 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2849 | LB = NewLB; |
| 2850 | return false; |
| 2851 | } |
| 2852 | |
| 2853 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2854 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2855 | // State consistency checking to ensure correct usage. |
| 2856 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2857 | !TestIsLessOp && !TestIsStrictOp); |
| 2858 | if (!NewUB) |
| 2859 | return true; |
| 2860 | UB = NewUB; |
| 2861 | TestIsLessOp = LessOp; |
| 2862 | TestIsStrictOp = StrictOp; |
| 2863 | ConditionSrcRange = SR; |
| 2864 | ConditionLoc = SL; |
| 2865 | return false; |
| 2866 | } |
| 2867 | |
| 2868 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2869 | // State consistency checking to ensure correct usage. |
| 2870 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2871 | if (!NewStep) |
| 2872 | return true; |
| 2873 | if (!NewStep->isValueDependent()) { |
| 2874 | // Check that the step is integer expression. |
| 2875 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2876 | ExprResult Val = |
| 2877 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2878 | if (Val.isInvalid()) |
| 2879 | return true; |
| 2880 | NewStep = Val.get(); |
| 2881 | |
| 2882 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2883 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2884 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2885 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2886 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2887 | // the loop. |
| 2888 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2889 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2890 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2891 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2892 | // the loop. |
| 2893 | llvm::APSInt Result; |
| 2894 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2895 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2896 | bool IsConstNeg = |
| 2897 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2898 | bool IsConstPos = |
| 2899 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2900 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2901 | if (UB && (IsConstZero || |
| 2902 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2903 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2904 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2905 | diag::err_omp_loop_incr_not_compatible) |
| 2906 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2907 | SemaRef.Diag(ConditionLoc, |
| 2908 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2909 | << TestIsLessOp << ConditionSrcRange; |
| 2910 | return true; |
| 2911 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2912 | if (TestIsLessOp == Subtract) { |
| 2913 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2914 | NewStep).get(); |
| 2915 | Subtract = !Subtract; |
| 2916 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | Step = NewStep; |
| 2920 | SubtractStep = Subtract; |
| 2921 | return false; |
| 2922 | } |
| 2923 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2924 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2925 | // Check init-expr for canonical loop form and save loop counter |
| 2926 | // variable - #Var and its initialization value - #LB. |
| 2927 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2928 | // var = lb |
| 2929 | // integer-type var = lb |
| 2930 | // random-access-iterator-type var = lb |
| 2931 | // pointer-type var = lb |
| 2932 | // |
| 2933 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2934 | if (EmitDiags) { |
| 2935 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2936 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2937 | return true; |
| 2938 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2939 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2940 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2941 | S = E->IgnoreParens(); |
| 2942 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2943 | if (BO->getOpcode() == BO_Assign) |
| 2944 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2945 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2946 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2947 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2948 | if (DS->isSingleDecl()) { |
| 2949 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2950 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2951 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2952 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2953 | SemaRef.Diag(S->getLocStart(), |
| 2954 | diag::ext_omp_loop_not_canonical_init) |
| 2955 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2956 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2961 | if (CE->getOperator() == OO_Equal) |
| 2962 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2963 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2964 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2965 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2966 | if (EmitDiags) { |
| 2967 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2968 | << S->getSourceRange(); |
| 2969 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2970 | return true; |
| 2971 | } |
| 2972 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2973 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2974 | /// variable (which may be the loop variable) if possible. |
| 2975 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2976 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2977 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2978 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2979 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2980 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2981 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2982 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2983 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2984 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2985 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2986 | if (!DRE) |
| 2987 | return nullptr; |
| 2988 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2989 | } |
| 2990 | |
| 2991 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2992 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2993 | // less/greater and for strict/non-strict comparison. |
| 2994 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2995 | // var relational-op b |
| 2996 | // b relational-op var |
| 2997 | // |
| 2998 | if (!S) { |
| 2999 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3000 | return true; |
| 3001 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3002 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3003 | SourceLocation CondLoc = S->getLocStart(); |
| 3004 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3005 | if (BO->isRelationalOp()) { |
| 3006 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3007 | return SetUB(BO->getRHS(), |
| 3008 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3009 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3010 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3011 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3012 | return SetUB(BO->getLHS(), |
| 3013 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3014 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3015 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3016 | } |
| 3017 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3018 | if (CE->getNumArgs() == 2) { |
| 3019 | auto Op = CE->getOperator(); |
| 3020 | switch (Op) { |
| 3021 | case OO_Greater: |
| 3022 | case OO_GreaterEqual: |
| 3023 | case OO_Less: |
| 3024 | case OO_LessEqual: |
| 3025 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3026 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3027 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3028 | CE->getOperatorLoc()); |
| 3029 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3030 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3031 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3032 | CE->getOperatorLoc()); |
| 3033 | break; |
| 3034 | default: |
| 3035 | break; |
| 3036 | } |
| 3037 | } |
| 3038 | } |
| 3039 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3040 | << S->getSourceRange() << Var; |
| 3041 | return true; |
| 3042 | } |
| 3043 | |
| 3044 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3045 | // RHS of canonical loop form increment can be: |
| 3046 | // var + incr |
| 3047 | // incr + var |
| 3048 | // var - incr |
| 3049 | // |
| 3050 | RHS = RHS->IgnoreParenImpCasts(); |
| 3051 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3052 | if (BO->isAdditiveOp()) { |
| 3053 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3054 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3055 | return SetStep(BO->getRHS(), !IsAdd); |
| 3056 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3057 | return SetStep(BO->getLHS(), false); |
| 3058 | } |
| 3059 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3060 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3061 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3062 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3063 | return SetStep(CE->getArg(1), !IsAdd); |
| 3064 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3065 | return SetStep(CE->getArg(0), false); |
| 3066 | } |
| 3067 | } |
| 3068 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3069 | << RHS->getSourceRange() << Var; |
| 3070 | return true; |
| 3071 | } |
| 3072 | |
| 3073 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3074 | // Check incr-expr for canonical loop form and return true if it |
| 3075 | // does not conform. |
| 3076 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3077 | // ++var |
| 3078 | // var++ |
| 3079 | // --var |
| 3080 | // var-- |
| 3081 | // var += incr |
| 3082 | // var -= incr |
| 3083 | // var = var + incr |
| 3084 | // var = incr + var |
| 3085 | // var = var - incr |
| 3086 | // |
| 3087 | if (!S) { |
| 3088 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3089 | return true; |
| 3090 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3091 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3092 | S = S->IgnoreParens(); |
| 3093 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3094 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3095 | return SetStep( |
| 3096 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3097 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3098 | false); |
| 3099 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3100 | switch (BO->getOpcode()) { |
| 3101 | case BO_AddAssign: |
| 3102 | case BO_SubAssign: |
| 3103 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3104 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3105 | break; |
| 3106 | case BO_Assign: |
| 3107 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3108 | return CheckIncRHS(BO->getRHS()); |
| 3109 | break; |
| 3110 | default: |
| 3111 | break; |
| 3112 | } |
| 3113 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3114 | switch (CE->getOperator()) { |
| 3115 | case OO_PlusPlus: |
| 3116 | case OO_MinusMinus: |
| 3117 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3118 | return SetStep( |
| 3119 | SemaRef.ActOnIntegerConstant( |
| 3120 | CE->getLocStart(), |
| 3121 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3122 | false); |
| 3123 | break; |
| 3124 | case OO_PlusEqual: |
| 3125 | case OO_MinusEqual: |
| 3126 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3127 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3128 | break; |
| 3129 | case OO_Equal: |
| 3130 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3131 | return CheckIncRHS(CE->getArg(1)); |
| 3132 | break; |
| 3133 | default: |
| 3134 | break; |
| 3135 | } |
| 3136 | } |
| 3137 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3138 | << S->getSourceRange() << Var; |
| 3139 | return true; |
| 3140 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3141 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3142 | namespace { |
| 3143 | // Transform variables declared in GNU statement expressions to new ones to |
| 3144 | // avoid crash on codegen. |
| 3145 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3146 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3147 | |
| 3148 | public: |
| 3149 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3150 | |
| 3151 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3152 | if (auto *VD = cast<VarDecl>(D)) |
| 3153 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3154 | !isa<ImplicitParamDecl>(D)) { |
| 3155 | auto *NewVD = VarDecl::Create( |
| 3156 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3157 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3158 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3159 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3160 | NewVD->setInit(VD->getInit()); |
| 3161 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3162 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3163 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3164 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3165 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3166 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3167 | NewVD->setPreviousDeclInSameBlockScope( |
| 3168 | VD->isPreviousDeclInSameBlockScope()); |
| 3169 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3170 | if (VD->hasAttrs()) |
| 3171 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3172 | transformedLocalDecl(VD, NewVD); |
| 3173 | return NewVD; |
| 3174 | } |
| 3175 | return BaseTransform::TransformDefinition(Loc, D); |
| 3176 | } |
| 3177 | |
| 3178 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3179 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3180 | if (E->getDecl() != NewD) { |
| 3181 | NewD->setReferenced(); |
| 3182 | NewD->markUsed(SemaRef.Context); |
| 3183 | return DeclRefExpr::Create( |
| 3184 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3185 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3186 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3187 | } |
| 3188 | return BaseTransform::TransformDeclRefExpr(E); |
| 3189 | } |
| 3190 | }; |
| 3191 | } |
| 3192 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3193 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3194 | Expr * |
| 3195 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3196 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3197 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3198 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3199 | auto VarType = Var->getType().getNonReferenceType(); |
| 3200 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3201 | SemaRef.getLangOpts().CPlusPlus) { |
| 3202 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3203 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3204 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3205 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3206 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3207 | if (!Upper || !Lower) |
| 3208 | return nullptr; |
| 3209 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3210 | Sema::AA_Converting, |
| 3211 | /*AllowExplicit=*/true) |
| 3212 | .get(); |
| 3213 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3214 | Sema::AA_Converting, |
| 3215 | /*AllowExplicit=*/true) |
| 3216 | .get(); |
| 3217 | if (!Upper || !Lower) |
| 3218 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3219 | |
| 3220 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3221 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3222 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3223 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3224 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3225 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3226 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3227 | return nullptr; |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | if (!Diff.isUsable()) |
| 3232 | return nullptr; |
| 3233 | |
| 3234 | // Upper - Lower [- 1] |
| 3235 | if (TestIsStrictOp) |
| 3236 | Diff = SemaRef.BuildBinOp( |
| 3237 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3238 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3239 | if (!Diff.isUsable()) |
| 3240 | return nullptr; |
| 3241 | |
| 3242 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3243 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3244 | if (NewStep.isInvalid()) |
| 3245 | return nullptr; |
| 3246 | NewStep = SemaRef.PerformImplicitConversion( |
| 3247 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3248 | /*AllowExplicit=*/true); |
| 3249 | if (NewStep.isInvalid()) |
| 3250 | return nullptr; |
| 3251 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3252 | if (!Diff.isUsable()) |
| 3253 | return nullptr; |
| 3254 | |
| 3255 | // Parentheses (for dumping/debugging purposes only). |
| 3256 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3257 | if (!Diff.isUsable()) |
| 3258 | return nullptr; |
| 3259 | |
| 3260 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3261 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3262 | if (NewStep.isInvalid()) |
| 3263 | return nullptr; |
| 3264 | NewStep = SemaRef.PerformImplicitConversion( |
| 3265 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3266 | /*AllowExplicit=*/true); |
| 3267 | if (NewStep.isInvalid()) |
| 3268 | return nullptr; |
| 3269 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3270 | if (!Diff.isUsable()) |
| 3271 | return nullptr; |
| 3272 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3273 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3274 | QualType Type = Diff.get()->getType(); |
| 3275 | auto &C = SemaRef.Context; |
| 3276 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3277 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3278 | if (!Type->isIntegerType() || UseVarType) { |
| 3279 | unsigned NewSize = |
| 3280 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3281 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3282 | : Type->hasSignedIntegerRepresentation(); |
| 3283 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3284 | Diff = SemaRef.PerformImplicitConversion( |
| 3285 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3286 | if (!Diff.isUsable()) |
| 3287 | return nullptr; |
| 3288 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3289 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3290 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3291 | if (NewSize != C.getTypeSize(Type)) { |
| 3292 | if (NewSize < C.getTypeSize(Type)) { |
| 3293 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3294 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3295 | << InitSrcRange << ConditionSrcRange; |
| 3296 | } |
| 3297 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3298 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3299 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3300 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3301 | Sema::AA_Converting, true); |
| 3302 | if (!Diff.isUsable()) |
| 3303 | return nullptr; |
| 3304 | } |
| 3305 | } |
| 3306 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3307 | return Diff.get(); |
| 3308 | } |
| 3309 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3310 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3311 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3312 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3313 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3314 | TransformToNewDefs Transform(SemaRef); |
| 3315 | |
| 3316 | auto NewLB = Transform.TransformExpr(LB); |
| 3317 | auto NewUB = Transform.TransformExpr(UB); |
| 3318 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3319 | return Cond; |
| 3320 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3321 | Sema::AA_Converting, |
| 3322 | /*AllowExplicit=*/true); |
| 3323 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3324 | Sema::AA_Converting, |
| 3325 | /*AllowExplicit=*/true); |
| 3326 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3327 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3328 | auto CondExpr = SemaRef.BuildBinOp( |
| 3329 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3330 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3331 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3332 | if (CondExpr.isUsable()) { |
| 3333 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3334 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3335 | /*AllowExplicit=*/true); |
| 3336 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3337 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3338 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3339 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3340 | } |
| 3341 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3342 | /// \brief Build reference expression to the counter be used for codegen. |
| 3343 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3344 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3345 | DefaultLoc); |
| 3346 | } |
| 3347 | |
| 3348 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3349 | if (Var && !Var->isInvalidDecl()) { |
| 3350 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3351 | auto *PrivateVar = |
| 3352 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3353 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3354 | if (PrivateVar->isInvalidDecl()) |
| 3355 | return nullptr; |
| 3356 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3357 | } |
| 3358 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | /// \brief Build initization of the counter be used for codegen. |
| 3362 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3363 | |
| 3364 | /// \brief Build step of the counter be used for codegen. |
| 3365 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3366 | |
| 3367 | /// \brief Iteration space of a single for loop. |
| 3368 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3369 | /// \brief Condition of the loop. |
| 3370 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3371 | /// \brief This expression calculates the number of iterations in the loop. |
| 3372 | /// It is always possible to calculate it before starting the loop. |
| 3373 | Expr *NumIterations; |
| 3374 | /// \brief The loop counter variable. |
| 3375 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3376 | /// \brief Private loop counter variable. |
| 3377 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3378 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3379 | Expr *CounterInit; |
| 3380 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3381 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3382 | Expr *CounterStep; |
| 3383 | /// \brief Should step be subtracted? |
| 3384 | bool Subtract; |
| 3385 | /// \brief Source range of the loop init. |
| 3386 | SourceRange InitSrcRange; |
| 3387 | /// \brief Source range of the loop condition. |
| 3388 | SourceRange CondSrcRange; |
| 3389 | /// \brief Source range of the loop increment. |
| 3390 | SourceRange IncSrcRange; |
| 3391 | }; |
| 3392 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3393 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3394 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3395 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3396 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3397 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3398 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3399 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3400 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3401 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3402 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3403 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3404 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3405 | } |
| 3406 | } |
| 3407 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3408 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3409 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3410 | static bool CheckOpenMPIterationSpace( |
| 3411 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3412 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3413 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3414 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3415 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3416 | // OpenMP [2.6, Canonical Loop Form] |
| 3417 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3418 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3419 | if (!For) { |
| 3420 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3421 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3422 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3423 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3424 | if (NestedLoopCount > 1) { |
| 3425 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3426 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3427 | diag::note_omp_collapse_ordered_expr) |
| 3428 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3429 | << OrderedLoopCountExpr->getSourceRange(); |
| 3430 | else if (CollapseLoopCountExpr) |
| 3431 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3432 | diag::note_omp_collapse_ordered_expr) |
| 3433 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3434 | else |
| 3435 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3436 | diag::note_omp_collapse_ordered_expr) |
| 3437 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3438 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3439 | return true; |
| 3440 | } |
| 3441 | assert(For->getBody()); |
| 3442 | |
| 3443 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3444 | |
| 3445 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3446 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3447 | if (ISC.CheckInit(Init)) { |
| 3448 | return true; |
| 3449 | } |
| 3450 | |
| 3451 | bool HasErrors = false; |
| 3452 | |
| 3453 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3454 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3455 | |
| 3456 | // OpenMP [2.6, Canonical Loop Form] |
| 3457 | // Var is one of the following: |
| 3458 | // A variable of signed or unsigned integer type. |
| 3459 | // For C++, a variable of a random access iterator type. |
| 3460 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3461 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3462 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3463 | !VarType->isPointerType() && |
| 3464 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3465 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3466 | << SemaRef.getLangOpts().CPlusPlus; |
| 3467 | HasErrors = true; |
| 3468 | } |
| 3469 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3470 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3471 | // Construct |
| 3472 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3473 | // parallel for construct is (are) private. |
| 3474 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3475 | // with just one associated for-loop is linear with a constant-linear-step |
| 3476 | // that is the increment of the associated for-loop. |
| 3477 | // Exclude loop var from the list of variables with implicitly defined data |
| 3478 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3479 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3480 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3481 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3482 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3483 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3484 | // with just one associated for-loop may be listed in a linear clause with a |
| 3485 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3486 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3487 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3488 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3489 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3490 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3491 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3492 | auto PredeterminedCKind = |
| 3493 | isOpenMPSimdDirective(DKind) |
| 3494 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3495 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3496 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame^] | 3497 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3498 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame^] | 3499 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3500 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame^] | 3501 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3502 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3503 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3504 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3505 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3506 | if (DVar.RefExpr == nullptr) |
| 3507 | DVar.CKind = PredeterminedCKind; |
| 3508 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3509 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3510 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3511 | // Make the loop iteration variable private (for worksharing constructs), |
| 3512 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3513 | // lastprivate (for simd directives with several collapsed or ordered |
| 3514 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3515 | if (DVar.CKind == OMPC_unknown) |
| 3516 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3517 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3518 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3521 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3522 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3523 | // Check test-expr. |
| 3524 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3525 | |
| 3526 | // Check incr-expr. |
| 3527 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3528 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3529 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3530 | return HasErrors; |
| 3531 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3532 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3533 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3534 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3535 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3536 | isOpenMPTaskLoopDirective(DKind) || |
| 3537 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3538 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3539 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3540 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3541 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3542 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3543 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3544 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3545 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3546 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3547 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3548 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3549 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3550 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3551 | ResultIterSpace.CounterInit == nullptr || |
| 3552 | ResultIterSpace.CounterStep == nullptr); |
| 3553 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3554 | return HasErrors; |
| 3555 | } |
| 3556 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3557 | /// \brief Build 'VarRef = Start. |
| 3558 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3559 | ExprResult VarRef, ExprResult Start) { |
| 3560 | TransformToNewDefs Transform(SemaRef); |
| 3561 | // Build 'VarRef = Start. |
| 3562 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3563 | if (NewStart.isInvalid()) |
| 3564 | return ExprError(); |
| 3565 | NewStart = SemaRef.PerformImplicitConversion( |
| 3566 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3567 | Sema::AA_Converting, |
| 3568 | /*AllowExplicit=*/true); |
| 3569 | if (NewStart.isInvalid()) |
| 3570 | return ExprError(); |
| 3571 | NewStart = SemaRef.PerformImplicitConversion( |
| 3572 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3573 | /*AllowExplicit=*/true); |
| 3574 | if (!NewStart.isUsable()) |
| 3575 | return ExprError(); |
| 3576 | |
| 3577 | auto Init = |
| 3578 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3579 | return Init; |
| 3580 | } |
| 3581 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3582 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3583 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3584 | SourceLocation Loc, ExprResult VarRef, |
| 3585 | ExprResult Start, ExprResult Iter, |
| 3586 | ExprResult Step, bool Subtract) { |
| 3587 | // Add parentheses (for debugging purposes only). |
| 3588 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3589 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3590 | !Step.isUsable()) |
| 3591 | return ExprError(); |
| 3592 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3593 | TransformToNewDefs Transform(SemaRef); |
| 3594 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3595 | if (NewStep.isInvalid()) |
| 3596 | return ExprError(); |
| 3597 | NewStep = SemaRef.PerformImplicitConversion( |
| 3598 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3599 | Sema::AA_Converting, |
| 3600 | /*AllowExplicit=*/true); |
| 3601 | if (NewStep.isInvalid()) |
| 3602 | return ExprError(); |
| 3603 | ExprResult Update = |
| 3604 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3605 | if (!Update.isUsable()) |
| 3606 | return ExprError(); |
| 3607 | |
| 3608 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3609 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3610 | if (NewStart.isInvalid()) |
| 3611 | return ExprError(); |
| 3612 | NewStart = SemaRef.PerformImplicitConversion( |
| 3613 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3614 | Sema::AA_Converting, |
| 3615 | /*AllowExplicit=*/true); |
| 3616 | if (NewStart.isInvalid()) |
| 3617 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3618 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3619 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3620 | if (!Update.isUsable()) |
| 3621 | return ExprError(); |
| 3622 | |
| 3623 | Update = SemaRef.PerformImplicitConversion( |
| 3624 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3625 | if (!Update.isUsable()) |
| 3626 | return ExprError(); |
| 3627 | |
| 3628 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3629 | return Update; |
| 3630 | } |
| 3631 | |
| 3632 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3633 | /// bits. |
| 3634 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3635 | Sema &SemaRef) { |
| 3636 | if (E == nullptr) |
| 3637 | return ExprError(); |
| 3638 | auto &C = SemaRef.Context; |
| 3639 | QualType OldType = E->getType(); |
| 3640 | unsigned HasBits = C.getTypeSize(OldType); |
| 3641 | if (HasBits >= Bits) |
| 3642 | return ExprResult(E); |
| 3643 | // OK to convert to signed, because new type has more bits than old. |
| 3644 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3645 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3646 | true); |
| 3647 | } |
| 3648 | |
| 3649 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3650 | /// into \a Bits bits. |
| 3651 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3652 | if (E == nullptr) |
| 3653 | return false; |
| 3654 | llvm::APSInt Result; |
| 3655 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3656 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3657 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /// \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] | 3661 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3662 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3663 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3664 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3665 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3666 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3667 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3668 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3669 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3670 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3671 | // Found 'collapse' clause - calculate collapse number. |
| 3672 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3673 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3674 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3675 | } |
| 3676 | if (OrderedLoopCountExpr) { |
| 3677 | // Found 'ordered' clause - calculate collapse number. |
| 3678 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3679 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3680 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3681 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3682 | diag::err_omp_wrong_ordered_loop_count) |
| 3683 | << OrderedLoopCountExpr->getSourceRange(); |
| 3684 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3685 | diag::note_collapse_loop_count) |
| 3686 | << CollapseLoopCountExpr->getSourceRange(); |
| 3687 | } |
| 3688 | NestedLoopCount = Result.getLimitedValue(); |
| 3689 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3690 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3691 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3692 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3693 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3694 | IterSpaces.resize(NestedLoopCount); |
| 3695 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3696 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3697 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3698 | NestedLoopCount, CollapseLoopCountExpr, |
| 3699 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3700 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3701 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3702 | // 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] | 3703 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3704 | // All loops associated with the construct must be perfectly nested; that |
| 3705 | // is, there must be no intervening code nor any OpenMP directive between |
| 3706 | // any two loops. |
| 3707 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3708 | } |
| 3709 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3710 | Built.clear(/* size */ NestedLoopCount); |
| 3711 | |
| 3712 | if (SemaRef.CurContext->isDependentContext()) |
| 3713 | return NestedLoopCount; |
| 3714 | |
| 3715 | // An example of what is generated for the following code: |
| 3716 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3717 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3718 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3719 | // for (k = 0; k < NK; ++k) |
| 3720 | // for (j = J0; j < NJ; j+=2) { |
| 3721 | // <loop body> |
| 3722 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3723 | // |
| 3724 | // We generate the code below. |
| 3725 | // Note: the loop body may be outlined in CodeGen. |
| 3726 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3727 | // iterations and operator+= to calculate counter value. |
| 3728 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3729 | // or i64 is currently supported). |
| 3730 | // |
| 3731 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3732 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3733 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3734 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3735 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3736 | // <loop body (using local i and j)> |
| 3737 | // } |
| 3738 | // i = NI; // assign final values of counters |
| 3739 | // j = NJ; |
| 3740 | // |
| 3741 | |
| 3742 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3743 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3744 | // Precondition tests if there is at least one iteration (all conditions are |
| 3745 | // true). |
| 3746 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3747 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3748 | ExprResult LastIteration32 = WidenIterationCount( |
| 3749 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3750 | N0->IgnoreImpCasts(), N0->getType(), |
| 3751 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3752 | .get(), |
| 3753 | SemaRef); |
| 3754 | ExprResult LastIteration64 = WidenIterationCount( |
| 3755 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3756 | N0->IgnoreImpCasts(), N0->getType(), |
| 3757 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3758 | .get(), |
| 3759 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3760 | |
| 3761 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3762 | return NestedLoopCount; |
| 3763 | |
| 3764 | auto &C = SemaRef.Context; |
| 3765 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3766 | |
| 3767 | Scope *CurScope = DSA.getCurScope(); |
| 3768 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3769 | if (PreCond.isUsable()) { |
| 3770 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3771 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3772 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3773 | auto N = IterSpaces[Cnt].NumIterations; |
| 3774 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3775 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3776 | LastIteration32 = SemaRef.BuildBinOp( |
| 3777 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3778 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3779 | Sema::AA_Converting, |
| 3780 | /*AllowExplicit=*/true) |
| 3781 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3782 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3783 | LastIteration64 = SemaRef.BuildBinOp( |
| 3784 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3785 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3786 | Sema::AA_Converting, |
| 3787 | /*AllowExplicit=*/true) |
| 3788 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | // Choose either the 32-bit or 64-bit version. |
| 3792 | ExprResult LastIteration = LastIteration64; |
| 3793 | if (LastIteration32.isUsable() && |
| 3794 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3795 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3796 | FitsInto( |
| 3797 | 32 /* Bits */, |
| 3798 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3799 | LastIteration64.get(), SemaRef))) |
| 3800 | LastIteration = LastIteration32; |
| 3801 | |
| 3802 | if (!LastIteration.isUsable()) |
| 3803 | return 0; |
| 3804 | |
| 3805 | // Save the number of iterations. |
| 3806 | ExprResult NumIterations = LastIteration; |
| 3807 | { |
| 3808 | LastIteration = SemaRef.BuildBinOp( |
| 3809 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3810 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3811 | if (!LastIteration.isUsable()) |
| 3812 | return 0; |
| 3813 | } |
| 3814 | |
| 3815 | // Calculate the last iteration number beforehand instead of doing this on |
| 3816 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3817 | llvm::APSInt Result; |
| 3818 | bool IsConstant = |
| 3819 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3820 | ExprResult CalcLastIteration; |
| 3821 | if (!IsConstant) { |
| 3822 | SourceLocation SaveLoc; |
| 3823 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3824 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3825 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3826 | ExprResult SaveRef = buildDeclRefExpr( |
| 3827 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3828 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3829 | SaveRef.get(), LastIteration.get()); |
| 3830 | LastIteration = SaveRef; |
| 3831 | |
| 3832 | // Prepare SaveRef + 1. |
| 3833 | NumIterations = SemaRef.BuildBinOp( |
| 3834 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3835 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3836 | if (!NumIterations.isUsable()) |
| 3837 | return 0; |
| 3838 | } |
| 3839 | |
| 3840 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3841 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3842 | QualType VType = LastIteration.get()->getType(); |
| 3843 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3844 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3845 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3846 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3847 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3848 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3849 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3850 | SemaRef.AddInitializerToDecl( |
| 3851 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3852 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3853 | |
| 3854 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3855 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3856 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3857 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3858 | /*DirectInit*/ false, |
| 3859 | /*TypeMayContainAuto*/ false); |
| 3860 | |
| 3861 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3862 | // This will be used to implement clause 'lastprivate'. |
| 3863 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3864 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3865 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3866 | SemaRef.AddInitializerToDecl( |
| 3867 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3868 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3869 | |
| 3870 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3871 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3872 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3873 | SemaRef.AddInitializerToDecl( |
| 3874 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3875 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3876 | |
| 3877 | // Build expression: UB = min(UB, LastIteration) |
| 3878 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3879 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3880 | UB.get(), LastIteration.get()); |
| 3881 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3882 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3883 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3884 | CondOp.get()); |
| 3885 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3886 | } |
| 3887 | |
| 3888 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3889 | ExprResult IV; |
| 3890 | ExprResult Init; |
| 3891 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3892 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3893 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3894 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3895 | isOpenMPTaskLoopDirective(DKind) || |
| 3896 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3897 | ? LB.get() |
| 3898 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3899 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3900 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3901 | } |
| 3902 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3903 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3904 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3905 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3906 | (isOpenMPWorksharingDirective(DKind) || |
| 3907 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3908 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3909 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3910 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3911 | |
| 3912 | // Loop increment (IV = IV + 1) |
| 3913 | SourceLocation IncLoc; |
| 3914 | ExprResult Inc = |
| 3915 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3916 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3917 | if (!Inc.isUsable()) |
| 3918 | return 0; |
| 3919 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3920 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3921 | if (!Inc.isUsable()) |
| 3922 | return 0; |
| 3923 | |
| 3924 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3925 | // Used for directives with static scheduling. |
| 3926 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3927 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3928 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3929 | // LB + ST |
| 3930 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3931 | if (!NextLB.isUsable()) |
| 3932 | return 0; |
| 3933 | // LB = LB + ST |
| 3934 | NextLB = |
| 3935 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3936 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3937 | if (!NextLB.isUsable()) |
| 3938 | return 0; |
| 3939 | // UB + ST |
| 3940 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3941 | if (!NextUB.isUsable()) |
| 3942 | return 0; |
| 3943 | // UB = UB + ST |
| 3944 | NextUB = |
| 3945 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3946 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3947 | if (!NextUB.isUsable()) |
| 3948 | return 0; |
| 3949 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3950 | |
| 3951 | // Build updates and final values of the loop counters. |
| 3952 | bool HasErrors = false; |
| 3953 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3954 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3955 | Built.Updates.resize(NestedLoopCount); |
| 3956 | Built.Finals.resize(NestedLoopCount); |
| 3957 | { |
| 3958 | ExprResult Div; |
| 3959 | // Go from inner nested loop to outer. |
| 3960 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3961 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3962 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3963 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3964 | // where Div is product of previous iterations' IS.NumIters. |
| 3965 | ExprResult Iter; |
| 3966 | if (Div.isUsable()) { |
| 3967 | Iter = |
| 3968 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3969 | } else { |
| 3970 | Iter = IV; |
| 3971 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3972 | "unusable div expected on first iteration only"); |
| 3973 | } |
| 3974 | |
| 3975 | if (Cnt != 0 && Iter.isUsable()) |
| 3976 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3977 | IS.NumIterations); |
| 3978 | if (!Iter.isUsable()) { |
| 3979 | HasErrors = true; |
| 3980 | break; |
| 3981 | } |
| 3982 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3983 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3984 | auto *CounterVar = buildDeclRefExpr( |
| 3985 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3986 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3987 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3988 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3989 | IS.CounterInit); |
| 3990 | if (!Init.isUsable()) { |
| 3991 | HasErrors = true; |
| 3992 | break; |
| 3993 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3994 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3995 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3996 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3997 | if (!Update.isUsable()) { |
| 3998 | HasErrors = true; |
| 3999 | break; |
| 4000 | } |
| 4001 | |
| 4002 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4003 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4004 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4005 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4006 | if (!Final.isUsable()) { |
| 4007 | HasErrors = true; |
| 4008 | break; |
| 4009 | } |
| 4010 | |
| 4011 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4012 | if (Cnt != 0) { |
| 4013 | if (Div.isUnset()) |
| 4014 | Div = IS.NumIterations; |
| 4015 | else |
| 4016 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4017 | IS.NumIterations); |
| 4018 | |
| 4019 | // Add parentheses (for debugging purposes only). |
| 4020 | if (Div.isUsable()) |
| 4021 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4022 | if (!Div.isUsable()) { |
| 4023 | HasErrors = true; |
| 4024 | break; |
| 4025 | } |
| 4026 | } |
| 4027 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4028 | HasErrors = true; |
| 4029 | break; |
| 4030 | } |
| 4031 | // Save results |
| 4032 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4033 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4034 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4035 | Built.Updates[Cnt] = Update.get(); |
| 4036 | Built.Finals[Cnt] = Final.get(); |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | if (HasErrors) |
| 4041 | return 0; |
| 4042 | |
| 4043 | // Save results |
| 4044 | Built.IterationVarRef = IV.get(); |
| 4045 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4046 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4047 | Built.CalcLastIteration = |
| 4048 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4049 | Built.PreCond = PreCond.get(); |
| 4050 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4051 | Built.Init = Init.get(); |
| 4052 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4053 | Built.LB = LB.get(); |
| 4054 | Built.UB = UB.get(); |
| 4055 | Built.IL = IL.get(); |
| 4056 | Built.ST = ST.get(); |
| 4057 | Built.EUB = EUB.get(); |
| 4058 | Built.NLB = NextLB.get(); |
| 4059 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4060 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4061 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4064 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4065 | auto CollapseClauses = |
| 4066 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4067 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4068 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4069 | return nullptr; |
| 4070 | } |
| 4071 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4072 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4073 | auto OrderedClauses = |
| 4074 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4075 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4076 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4077 | return nullptr; |
| 4078 | } |
| 4079 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4080 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4081 | const Expr *Safelen) { |
| 4082 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4083 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4084 | Simdlen->isInstantiationDependent() || |
| 4085 | Simdlen->containsUnexpandedParameterPack()) |
| 4086 | return false; |
| 4087 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4088 | Safelen->isInstantiationDependent() || |
| 4089 | Safelen->containsUnexpandedParameterPack()) |
| 4090 | return false; |
| 4091 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4092 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4093 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4094 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4095 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4096 | if (SimdlenRes > SafelenRes) { |
| 4097 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4098 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4099 | return true; |
| 4100 | } |
| 4101 | return false; |
| 4102 | } |
| 4103 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4104 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4105 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4106 | SourceLocation EndLoc, |
| 4107 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4108 | if (!AStmt) |
| 4109 | return StmtError(); |
| 4110 | |
| 4111 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4112 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4113 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4114 | // define the nested loops number. |
| 4115 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4116 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4117 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4118 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4119 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4120 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4121 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4122 | "omp simd loop exprs were not built"); |
| 4123 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4124 | if (!CurContext->isDependentContext()) { |
| 4125 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4126 | for (auto C : Clauses) { |
| 4127 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4128 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4129 | B.NumIterations, *this, CurScope)) |
| 4130 | return StmtError(); |
| 4131 | } |
| 4132 | } |
| 4133 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4134 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4135 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4136 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4137 | OMPSafelenClause *Safelen = nullptr; |
| 4138 | OMPSimdlenClause *Simdlen = nullptr; |
| 4139 | for (auto *Clause : Clauses) { |
| 4140 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4141 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4142 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4143 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4144 | if (Safelen && Simdlen) |
| 4145 | break; |
| 4146 | } |
| 4147 | if (Simdlen && Safelen && |
| 4148 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4149 | Safelen->getSafelen())) |
| 4150 | return StmtError(); |
| 4151 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4152 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4153 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4154 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4155 | } |
| 4156 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4157 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4158 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4159 | SourceLocation EndLoc, |
| 4160 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4161 | if (!AStmt) |
| 4162 | return StmtError(); |
| 4163 | |
| 4164 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4165 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4166 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4167 | // define the nested loops number. |
| 4168 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4169 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4170 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4171 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4172 | return StmtError(); |
| 4173 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4174 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4175 | "omp for loop exprs were not built"); |
| 4176 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4177 | if (!CurContext->isDependentContext()) { |
| 4178 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4179 | for (auto C : Clauses) { |
| 4180 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4181 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4182 | B.NumIterations, *this, CurScope)) |
| 4183 | return StmtError(); |
| 4184 | } |
| 4185 | } |
| 4186 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4187 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4188 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4189 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4192 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4193 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4194 | SourceLocation EndLoc, |
| 4195 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4196 | if (!AStmt) |
| 4197 | return StmtError(); |
| 4198 | |
| 4199 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4200 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4201 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4202 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4203 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4204 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4205 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4206 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4207 | if (NestedLoopCount == 0) |
| 4208 | return StmtError(); |
| 4209 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4210 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4211 | "omp for simd loop exprs were not built"); |
| 4212 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4213 | if (!CurContext->isDependentContext()) { |
| 4214 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4215 | for (auto C : Clauses) { |
| 4216 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4217 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4218 | B.NumIterations, *this, CurScope)) |
| 4219 | return StmtError(); |
| 4220 | } |
| 4221 | } |
| 4222 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4223 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4224 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4225 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4226 | OMPSafelenClause *Safelen = nullptr; |
| 4227 | OMPSimdlenClause *Simdlen = nullptr; |
| 4228 | for (auto *Clause : Clauses) { |
| 4229 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4230 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4231 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4232 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4233 | if (Safelen && Simdlen) |
| 4234 | break; |
| 4235 | } |
| 4236 | if (Simdlen && Safelen && |
| 4237 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4238 | Safelen->getSafelen())) |
| 4239 | return StmtError(); |
| 4240 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4241 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4242 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4243 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4246 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4247 | Stmt *AStmt, |
| 4248 | SourceLocation StartLoc, |
| 4249 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4250 | if (!AStmt) |
| 4251 | return StmtError(); |
| 4252 | |
| 4253 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4254 | auto BaseStmt = AStmt; |
| 4255 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4256 | BaseStmt = CS->getCapturedStmt(); |
| 4257 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4258 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4259 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4260 | return StmtError(); |
| 4261 | // All associated statements must be '#pragma omp section' except for |
| 4262 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4263 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4264 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4265 | if (SectionStmt) |
| 4266 | Diag(SectionStmt->getLocStart(), |
| 4267 | diag::err_omp_sections_substmt_not_section); |
| 4268 | return StmtError(); |
| 4269 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4270 | cast<OMPSectionDirective>(SectionStmt) |
| 4271 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4272 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4273 | } else { |
| 4274 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4275 | return StmtError(); |
| 4276 | } |
| 4277 | |
| 4278 | getCurFunction()->setHasBranchProtectedScope(); |
| 4279 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4280 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4281 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4284 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4285 | SourceLocation StartLoc, |
| 4286 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4287 | if (!AStmt) |
| 4288 | return StmtError(); |
| 4289 | |
| 4290 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4291 | |
| 4292 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4293 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4294 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4295 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4296 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4297 | } |
| 4298 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4299 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4300 | Stmt *AStmt, |
| 4301 | SourceLocation StartLoc, |
| 4302 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4303 | if (!AStmt) |
| 4304 | return StmtError(); |
| 4305 | |
| 4306 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4307 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4308 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4309 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4310 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4311 | // The copyprivate clause must not be used with the nowait clause. |
| 4312 | OMPClause *Nowait = nullptr; |
| 4313 | OMPClause *Copyprivate = nullptr; |
| 4314 | for (auto *Clause : Clauses) { |
| 4315 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4316 | Nowait = Clause; |
| 4317 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4318 | Copyprivate = Clause; |
| 4319 | if (Copyprivate && Nowait) { |
| 4320 | Diag(Copyprivate->getLocStart(), |
| 4321 | diag::err_omp_single_copyprivate_with_nowait); |
| 4322 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4323 | return StmtError(); |
| 4324 | } |
| 4325 | } |
| 4326 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4327 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4328 | } |
| 4329 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4330 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4331 | SourceLocation StartLoc, |
| 4332 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4333 | if (!AStmt) |
| 4334 | return StmtError(); |
| 4335 | |
| 4336 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4337 | |
| 4338 | getCurFunction()->setHasBranchProtectedScope(); |
| 4339 | |
| 4340 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4341 | } |
| 4342 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4343 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4344 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4345 | Stmt *AStmt, SourceLocation StartLoc, 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"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4350 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4351 | bool ErrorFound = false; |
| 4352 | llvm::APSInt Hint; |
| 4353 | SourceLocation HintLoc; |
| 4354 | bool DependentHint = false; |
| 4355 | for (auto *C : Clauses) { |
| 4356 | if (C->getClauseKind() == OMPC_hint) { |
| 4357 | if (!DirName.getName()) { |
| 4358 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4359 | ErrorFound = true; |
| 4360 | } |
| 4361 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4362 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4363 | E->isInstantiationDependent()) |
| 4364 | DependentHint = true; |
| 4365 | else { |
| 4366 | Hint = E->EvaluateKnownConstInt(Context); |
| 4367 | HintLoc = C->getLocStart(); |
| 4368 | } |
| 4369 | } |
| 4370 | } |
| 4371 | if (ErrorFound) |
| 4372 | return StmtError(); |
| 4373 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4374 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4375 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4376 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4377 | if (HintLoc.isValid()) { |
| 4378 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4379 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4380 | } else |
| 4381 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4382 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4383 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4384 | << 1 |
| 4385 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4386 | /*Radix=*/10, /*Signed=*/false); |
| 4387 | } else |
| 4388 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4389 | } |
| 4390 | } |
| 4391 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4392 | getCurFunction()->setHasBranchProtectedScope(); |
| 4393 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4394 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4395 | Clauses, AStmt); |
| 4396 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4397 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4398 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4401 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4402 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4403 | SourceLocation EndLoc, |
| 4404 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4405 | if (!AStmt) |
| 4406 | return StmtError(); |
| 4407 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4408 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4409 | // 1.2.2 OpenMP Language Terminology |
| 4410 | // Structured block - An executable statement with a single entry at the |
| 4411 | // top and a single exit at the bottom. |
| 4412 | // The point of exit cannot be a branch out of the structured block. |
| 4413 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4414 | CS->getCapturedDecl()->setNothrow(); |
| 4415 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4416 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4417 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4418 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4419 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4420 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4421 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4422 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4423 | if (NestedLoopCount == 0) |
| 4424 | return StmtError(); |
| 4425 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4426 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4427 | "omp parallel for loop exprs were not built"); |
| 4428 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4429 | if (!CurContext->isDependentContext()) { |
| 4430 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4431 | for (auto C : Clauses) { |
| 4432 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4433 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4434 | B.NumIterations, *this, CurScope)) |
| 4435 | return StmtError(); |
| 4436 | } |
| 4437 | } |
| 4438 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4439 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4440 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4441 | NestedLoopCount, Clauses, AStmt, B, |
| 4442 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4443 | } |
| 4444 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4445 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4446 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4447 | SourceLocation EndLoc, |
| 4448 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4449 | if (!AStmt) |
| 4450 | return StmtError(); |
| 4451 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4452 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4453 | // 1.2.2 OpenMP Language Terminology |
| 4454 | // Structured block - An executable statement with a single entry at the |
| 4455 | // top and a single exit at the bottom. |
| 4456 | // The point of exit cannot be a branch out of the structured block. |
| 4457 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4458 | CS->getCapturedDecl()->setNothrow(); |
| 4459 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4460 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4461 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4462 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4463 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4464 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4465 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4466 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4467 | if (NestedLoopCount == 0) |
| 4468 | return StmtError(); |
| 4469 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4470 | if (!CurContext->isDependentContext()) { |
| 4471 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4472 | for (auto C : Clauses) { |
| 4473 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4474 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4475 | B.NumIterations, *this, CurScope)) |
| 4476 | return StmtError(); |
| 4477 | } |
| 4478 | } |
| 4479 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4480 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4481 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4482 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4483 | OMPSafelenClause *Safelen = nullptr; |
| 4484 | OMPSimdlenClause *Simdlen = nullptr; |
| 4485 | for (auto *Clause : Clauses) { |
| 4486 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4487 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4488 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4489 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4490 | if (Safelen && Simdlen) |
| 4491 | break; |
| 4492 | } |
| 4493 | if (Simdlen && Safelen && |
| 4494 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4495 | Safelen->getSafelen())) |
| 4496 | return StmtError(); |
| 4497 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4498 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4499 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4500 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4503 | StmtResult |
| 4504 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4505 | Stmt *AStmt, SourceLocation StartLoc, |
| 4506 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4507 | if (!AStmt) |
| 4508 | return StmtError(); |
| 4509 | |
| 4510 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4511 | auto BaseStmt = AStmt; |
| 4512 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4513 | BaseStmt = CS->getCapturedStmt(); |
| 4514 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4515 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4516 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4517 | return StmtError(); |
| 4518 | // All associated statements must be '#pragma omp section' except for |
| 4519 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4520 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4521 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4522 | if (SectionStmt) |
| 4523 | Diag(SectionStmt->getLocStart(), |
| 4524 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4525 | return StmtError(); |
| 4526 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4527 | cast<OMPSectionDirective>(SectionStmt) |
| 4528 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4529 | } |
| 4530 | } else { |
| 4531 | Diag(AStmt->getLocStart(), |
| 4532 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4533 | return StmtError(); |
| 4534 | } |
| 4535 | |
| 4536 | getCurFunction()->setHasBranchProtectedScope(); |
| 4537 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4538 | return OMPParallelSectionsDirective::Create( |
| 4539 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4542 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4543 | Stmt *AStmt, SourceLocation StartLoc, |
| 4544 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4545 | if (!AStmt) |
| 4546 | return StmtError(); |
| 4547 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4548 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4549 | // 1.2.2 OpenMP Language Terminology |
| 4550 | // Structured block - An executable statement with a single entry at the |
| 4551 | // top and a single exit at the bottom. |
| 4552 | // The point of exit cannot be a branch out of the structured block. |
| 4553 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4554 | CS->getCapturedDecl()->setNothrow(); |
| 4555 | |
| 4556 | getCurFunction()->setHasBranchProtectedScope(); |
| 4557 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4558 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4559 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4560 | } |
| 4561 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4562 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4563 | SourceLocation EndLoc) { |
| 4564 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4565 | } |
| 4566 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4567 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4568 | SourceLocation EndLoc) { |
| 4569 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4570 | } |
| 4571 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4572 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4573 | SourceLocation EndLoc) { |
| 4574 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4575 | } |
| 4576 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4577 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4578 | SourceLocation StartLoc, |
| 4579 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4580 | if (!AStmt) |
| 4581 | return StmtError(); |
| 4582 | |
| 4583 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4584 | |
| 4585 | getCurFunction()->setHasBranchProtectedScope(); |
| 4586 | |
| 4587 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4588 | } |
| 4589 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4590 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4591 | SourceLocation StartLoc, |
| 4592 | SourceLocation EndLoc) { |
| 4593 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4594 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4595 | } |
| 4596 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4597 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4598 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4599 | SourceLocation StartLoc, |
| 4600 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4601 | OMPClause *DependFound = nullptr; |
| 4602 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4603 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4604 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4605 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4606 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4607 | for (auto *C : Clauses) { |
| 4608 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4609 | DependFound = C; |
| 4610 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4611 | if (DependSourceClause) { |
| 4612 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4613 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4614 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4615 | ErrorFound = true; |
| 4616 | } else |
| 4617 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4618 | if (DependSinkClause) { |
| 4619 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4620 | << 0; |
| 4621 | ErrorFound = true; |
| 4622 | } |
| 4623 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4624 | if (DependSourceClause) { |
| 4625 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4626 | << 1; |
| 4627 | ErrorFound = true; |
| 4628 | } |
| 4629 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4630 | } |
| 4631 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4632 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4633 | else if (C->getClauseKind() == OMPC_simd) |
| 4634 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4635 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4636 | if (!ErrorFound && !SC && |
| 4637 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4638 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4639 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4640 | // that can appear in the simd region. |
| 4641 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4642 | ErrorFound = true; |
| 4643 | } else if (DependFound && (TC || SC)) { |
| 4644 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4645 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4646 | ErrorFound = true; |
| 4647 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4648 | Diag(DependFound->getLocStart(), |
| 4649 | diag::err_omp_ordered_directive_without_param); |
| 4650 | ErrorFound = true; |
| 4651 | } else if (TC || Clauses.empty()) { |
| 4652 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4653 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4654 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4655 | << (TC != nullptr); |
| 4656 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4657 | ErrorFound = true; |
| 4658 | } |
| 4659 | } |
| 4660 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4661 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4662 | |
| 4663 | if (AStmt) { |
| 4664 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4665 | |
| 4666 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4667 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4668 | |
| 4669 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4672 | namespace { |
| 4673 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4674 | /// construct. |
| 4675 | class OpenMPAtomicUpdateChecker { |
| 4676 | /// \brief Error results for atomic update expressions. |
| 4677 | enum ExprAnalysisErrorCode { |
| 4678 | /// \brief A statement is not an expression statement. |
| 4679 | NotAnExpression, |
| 4680 | /// \brief Expression is not builtin binary or unary operation. |
| 4681 | NotABinaryOrUnaryExpression, |
| 4682 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4683 | NotAnUnaryIncDecExpression, |
| 4684 | /// \brief An expression is not of scalar type. |
| 4685 | NotAScalarType, |
| 4686 | /// \brief A binary operation is not an assignment operation. |
| 4687 | NotAnAssignmentOp, |
| 4688 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4689 | NotABinaryExpression, |
| 4690 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4691 | /// expression. |
| 4692 | NotABinaryOperator, |
| 4693 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4694 | /// part. |
| 4695 | NotAnUpdateExpression, |
| 4696 | /// \brief No errors is found. |
| 4697 | NoError |
| 4698 | }; |
| 4699 | /// \brief Reference to Sema. |
| 4700 | Sema &SemaRef; |
| 4701 | /// \brief A location for note diagnostics (when error is found). |
| 4702 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4703 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4704 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4705 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4706 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4707 | /// \brief Helper expression of the form |
| 4708 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4709 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4710 | Expr *UpdateExpr; |
| 4711 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4712 | /// important for non-associative operations. |
| 4713 | bool IsXLHSInRHSPart; |
| 4714 | BinaryOperatorKind Op; |
| 4715 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4716 | /// \brief true if the source expression is a postfix unary operation, false |
| 4717 | /// if it is a prefix unary operation. |
| 4718 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4719 | |
| 4720 | public: |
| 4721 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4722 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4723 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4724 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4725 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4726 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4727 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4728 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4729 | /// \param NoteId Diagnostic note for the main error message. |
| 4730 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4731 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4732 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4733 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4734 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4735 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4736 | /// \brief Return the update expression used in calculation of the updated |
| 4737 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4738 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4739 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4740 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4741 | /// false otherwise. |
| 4742 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4743 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4744 | /// \brief true if the source expression is a postfix unary operation, false |
| 4745 | /// if it is a prefix unary operation. |
| 4746 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4747 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4748 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4749 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4750 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4751 | }; |
| 4752 | } // namespace |
| 4753 | |
| 4754 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4755 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4756 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4757 | SourceLocation ErrorLoc, NoteLoc; |
| 4758 | SourceRange ErrorRange, NoteRange; |
| 4759 | // Allowed constructs are: |
| 4760 | // x = x binop expr; |
| 4761 | // x = expr binop x; |
| 4762 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4763 | X = AtomicBinOp->getLHS(); |
| 4764 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4765 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4766 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4767 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4768 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4769 | Op = AtomicInnerBinOp->getOpcode(); |
| 4770 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4771 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4772 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4773 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4774 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4775 | /*Canonical=*/true); |
| 4776 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4777 | /*Canonical=*/true); |
| 4778 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4779 | /*Canonical=*/true); |
| 4780 | if (XId == LHSId) { |
| 4781 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4782 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4783 | } else if (XId == RHSId) { |
| 4784 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4785 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4786 | } else { |
| 4787 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4788 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4789 | NoteLoc = X->getExprLoc(); |
| 4790 | NoteRange = X->getSourceRange(); |
| 4791 | ErrorFound = NotAnUpdateExpression; |
| 4792 | } |
| 4793 | } else { |
| 4794 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4795 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4796 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4797 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4798 | ErrorFound = NotABinaryOperator; |
| 4799 | } |
| 4800 | } else { |
| 4801 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4802 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4803 | ErrorFound = NotABinaryExpression; |
| 4804 | } |
| 4805 | } else { |
| 4806 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4807 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4808 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4809 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4810 | ErrorFound = NotAnAssignmentOp; |
| 4811 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4812 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4813 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4814 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4815 | return true; |
| 4816 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4817 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4818 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4822 | unsigned NoteId) { |
| 4823 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4824 | SourceLocation ErrorLoc, NoteLoc; |
| 4825 | SourceRange ErrorRange, NoteRange; |
| 4826 | // Allowed constructs are: |
| 4827 | // x++; |
| 4828 | // x--; |
| 4829 | // ++x; |
| 4830 | // --x; |
| 4831 | // x binop= expr; |
| 4832 | // x = x binop expr; |
| 4833 | // x = expr binop x; |
| 4834 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4835 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4836 | if (AtomicBody->getType()->isScalarType() || |
| 4837 | AtomicBody->isInstantiationDependent()) { |
| 4838 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4839 | AtomicBody->IgnoreParenImpCasts())) { |
| 4840 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4841 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4842 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4843 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4844 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4845 | X = AtomicCompAssignOp->getLHS(); |
| 4846 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4847 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4848 | AtomicBody->IgnoreParenImpCasts())) { |
| 4849 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4850 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4851 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4852 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4853 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4854 | // Check for Unary Operation |
| 4855 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4856 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4857 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4858 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4859 | X = AtomicUnaryOp->getSubExpr(); |
| 4860 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4861 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4862 | } else { |
| 4863 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4864 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4865 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4866 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4867 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4868 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4869 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4870 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4871 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4872 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4873 | } |
| 4874 | } else { |
| 4875 | ErrorFound = NotAScalarType; |
| 4876 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4877 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4878 | } |
| 4879 | } else { |
| 4880 | ErrorFound = NotAnExpression; |
| 4881 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4882 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4883 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4884 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4885 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4886 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4887 | return true; |
| 4888 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4889 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4890 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4891 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4892 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4893 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4894 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4895 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4896 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4897 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4898 | auto Update = |
| 4899 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4900 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4901 | if (Update.isInvalid()) |
| 4902 | return true; |
| 4903 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4904 | Sema::AA_Casting); |
| 4905 | if (Update.isInvalid()) |
| 4906 | return true; |
| 4907 | UpdateExpr = Update.get(); |
| 4908 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4909 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4912 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4913 | Stmt *AStmt, |
| 4914 | SourceLocation StartLoc, |
| 4915 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4916 | if (!AStmt) |
| 4917 | return StmtError(); |
| 4918 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4919 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4920 | // 1.2.2 OpenMP Language Terminology |
| 4921 | // Structured block - An executable statement with a single entry at the |
| 4922 | // top and a single exit at the bottom. |
| 4923 | // The point of exit cannot be a branch out of the structured block. |
| 4924 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4925 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4926 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4927 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4928 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4929 | C->getClauseKind() == OMPC_update || |
| 4930 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4931 | if (AtomicKind != OMPC_unknown) { |
| 4932 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4933 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4934 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4935 | << getOpenMPClauseName(AtomicKind); |
| 4936 | } else { |
| 4937 | AtomicKind = C->getClauseKind(); |
| 4938 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4942 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4943 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4944 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4945 | Body = EWC->getSubExpr(); |
| 4946 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4947 | Expr *X = nullptr; |
| 4948 | Expr *V = nullptr; |
| 4949 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4950 | Expr *UE = nullptr; |
| 4951 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4952 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4953 | // OpenMP [2.12.6, atomic Construct] |
| 4954 | // In the next expressions: |
| 4955 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4956 | // * During the execution of an atomic region, multiple syntactic |
| 4957 | // occurrences of x must designate the same storage location. |
| 4958 | // * Neither of v and expr (as applicable) may access the storage location |
| 4959 | // designated by x. |
| 4960 | // * Neither of x and expr (as applicable) may access the storage location |
| 4961 | // designated by v. |
| 4962 | // * expr is an expression with scalar type. |
| 4963 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4964 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4965 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4966 | // (expr). This requirement is satisfied if the operators in expr have |
| 4967 | // precedence greater than binop, or by using parentheses around expr or |
| 4968 | // subexpressions of expr. |
| 4969 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4970 | // binop x. This requirement is satisfied if the operators in expr have |
| 4971 | // precedence equal to or greater than binop, or by using parentheses around |
| 4972 | // expr or subexpressions of expr. |
| 4973 | // * For forms that allow multiple occurrences of x, the number of times |
| 4974 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4975 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4976 | enum { |
| 4977 | NotAnExpression, |
| 4978 | NotAnAssignmentOp, |
| 4979 | NotAScalarType, |
| 4980 | NotAnLValue, |
| 4981 | NoError |
| 4982 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4983 | SourceLocation ErrorLoc, NoteLoc; |
| 4984 | SourceRange ErrorRange, NoteRange; |
| 4985 | // If clause is read: |
| 4986 | // v = x; |
| 4987 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4988 | auto AtomicBinOp = |
| 4989 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4990 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4991 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4992 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4993 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4994 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4995 | if (!X->isLValue() || !V->isLValue()) { |
| 4996 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4997 | ErrorFound = NotAnLValue; |
| 4998 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4999 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5000 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5001 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5002 | } |
| 5003 | } else if (!X->isInstantiationDependent() || |
| 5004 | !V->isInstantiationDependent()) { |
| 5005 | auto NotScalarExpr = |
| 5006 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5007 | ? V |
| 5008 | : X; |
| 5009 | ErrorFound = NotAScalarType; |
| 5010 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5011 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5012 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5013 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5014 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5015 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5016 | ErrorFound = NotAnAssignmentOp; |
| 5017 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5018 | ErrorRange = AtomicBody->getSourceRange(); |
| 5019 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5020 | : AtomicBody->getExprLoc(); |
| 5021 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5022 | : AtomicBody->getSourceRange(); |
| 5023 | } |
| 5024 | } else { |
| 5025 | ErrorFound = NotAnExpression; |
| 5026 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5027 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5028 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5029 | if (ErrorFound != NoError) { |
| 5030 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5031 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5032 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5033 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5034 | return StmtError(); |
| 5035 | } else if (CurContext->isDependentContext()) |
| 5036 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5037 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5038 | enum { |
| 5039 | NotAnExpression, |
| 5040 | NotAnAssignmentOp, |
| 5041 | NotAScalarType, |
| 5042 | NotAnLValue, |
| 5043 | NoError |
| 5044 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5045 | SourceLocation ErrorLoc, NoteLoc; |
| 5046 | SourceRange ErrorRange, NoteRange; |
| 5047 | // If clause is write: |
| 5048 | // x = expr; |
| 5049 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5050 | auto AtomicBinOp = |
| 5051 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5052 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5053 | X = AtomicBinOp->getLHS(); |
| 5054 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5055 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5056 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5057 | if (!X->isLValue()) { |
| 5058 | ErrorFound = NotAnLValue; |
| 5059 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5060 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5061 | NoteLoc = X->getExprLoc(); |
| 5062 | NoteRange = X->getSourceRange(); |
| 5063 | } |
| 5064 | } else if (!X->isInstantiationDependent() || |
| 5065 | !E->isInstantiationDependent()) { |
| 5066 | auto NotScalarExpr = |
| 5067 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5068 | ? E |
| 5069 | : X; |
| 5070 | ErrorFound = NotAScalarType; |
| 5071 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5072 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5073 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5074 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5075 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5076 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5077 | ErrorFound = NotAnAssignmentOp; |
| 5078 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5079 | ErrorRange = AtomicBody->getSourceRange(); |
| 5080 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5081 | : AtomicBody->getExprLoc(); |
| 5082 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5083 | : AtomicBody->getSourceRange(); |
| 5084 | } |
| 5085 | } else { |
| 5086 | ErrorFound = NotAnExpression; |
| 5087 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5088 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5089 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5090 | if (ErrorFound != NoError) { |
| 5091 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5092 | << ErrorRange; |
| 5093 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5094 | << NoteRange; |
| 5095 | return StmtError(); |
| 5096 | } else if (CurContext->isDependentContext()) |
| 5097 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5098 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5099 | // If clause is update: |
| 5100 | // x++; |
| 5101 | // x--; |
| 5102 | // ++x; |
| 5103 | // --x; |
| 5104 | // x binop= expr; |
| 5105 | // x = x binop expr; |
| 5106 | // x = expr binop x; |
| 5107 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5108 | if (Checker.checkStatement( |
| 5109 | Body, (AtomicKind == OMPC_update) |
| 5110 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5111 | : diag::err_omp_atomic_not_expression_statement, |
| 5112 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5113 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5114 | if (!CurContext->isDependentContext()) { |
| 5115 | E = Checker.getExpr(); |
| 5116 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5117 | UE = Checker.getUpdateExpr(); |
| 5118 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5119 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5120 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5121 | enum { |
| 5122 | NotAnAssignmentOp, |
| 5123 | NotACompoundStatement, |
| 5124 | NotTwoSubstatements, |
| 5125 | NotASpecificExpression, |
| 5126 | NoError |
| 5127 | } ErrorFound = NoError; |
| 5128 | SourceLocation ErrorLoc, NoteLoc; |
| 5129 | SourceRange ErrorRange, NoteRange; |
| 5130 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5131 | // If clause is a capture: |
| 5132 | // v = x++; |
| 5133 | // v = x--; |
| 5134 | // v = ++x; |
| 5135 | // v = --x; |
| 5136 | // v = x binop= expr; |
| 5137 | // v = x = x binop expr; |
| 5138 | // v = x = expr binop x; |
| 5139 | auto *AtomicBinOp = |
| 5140 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5141 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5142 | V = AtomicBinOp->getLHS(); |
| 5143 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5144 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5145 | if (Checker.checkStatement( |
| 5146 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5147 | diag::note_omp_atomic_update)) |
| 5148 | return StmtError(); |
| 5149 | E = Checker.getExpr(); |
| 5150 | X = Checker.getX(); |
| 5151 | UE = Checker.getUpdateExpr(); |
| 5152 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5153 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5154 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5155 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5156 | ErrorRange = AtomicBody->getSourceRange(); |
| 5157 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5158 | : AtomicBody->getExprLoc(); |
| 5159 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5160 | : AtomicBody->getSourceRange(); |
| 5161 | ErrorFound = NotAnAssignmentOp; |
| 5162 | } |
| 5163 | if (ErrorFound != NoError) { |
| 5164 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5165 | << ErrorRange; |
| 5166 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5167 | return StmtError(); |
| 5168 | } else if (CurContext->isDependentContext()) { |
| 5169 | UE = V = E = X = nullptr; |
| 5170 | } |
| 5171 | } else { |
| 5172 | // If clause is a capture: |
| 5173 | // { v = x; x = expr; } |
| 5174 | // { v = x; x++; } |
| 5175 | // { v = x; x--; } |
| 5176 | // { v = x; ++x; } |
| 5177 | // { v = x; --x; } |
| 5178 | // { v = x; x binop= expr; } |
| 5179 | // { v = x; x = x binop expr; } |
| 5180 | // { v = x; x = expr binop x; } |
| 5181 | // { x++; v = x; } |
| 5182 | // { x--; v = x; } |
| 5183 | // { ++x; v = x; } |
| 5184 | // { --x; v = x; } |
| 5185 | // { x binop= expr; v = x; } |
| 5186 | // { x = x binop expr; v = x; } |
| 5187 | // { x = expr binop x; v = x; } |
| 5188 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5189 | // Check that this is { expr1; expr2; } |
| 5190 | if (CS->size() == 2) { |
| 5191 | auto *First = CS->body_front(); |
| 5192 | auto *Second = CS->body_back(); |
| 5193 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5194 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5195 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5196 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5197 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5198 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5199 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5200 | BinaryOperator *BinOp = nullptr; |
| 5201 | if (IsUpdateExprFound) { |
| 5202 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5203 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5204 | } |
| 5205 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5206 | // { v = x; x++; } |
| 5207 | // { v = x; x--; } |
| 5208 | // { v = x; ++x; } |
| 5209 | // { v = x; --x; } |
| 5210 | // { v = x; x binop= expr; } |
| 5211 | // { v = x; x = x binop expr; } |
| 5212 | // { v = x; x = expr binop x; } |
| 5213 | // Check that the first expression has form v = x. |
| 5214 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5215 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5216 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5217 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5218 | IsUpdateExprFound = XId == PossibleXId; |
| 5219 | if (IsUpdateExprFound) { |
| 5220 | V = BinOp->getLHS(); |
| 5221 | X = Checker.getX(); |
| 5222 | E = Checker.getExpr(); |
| 5223 | UE = Checker.getUpdateExpr(); |
| 5224 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5225 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5226 | } |
| 5227 | } |
| 5228 | if (!IsUpdateExprFound) { |
| 5229 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5230 | BinOp = nullptr; |
| 5231 | if (IsUpdateExprFound) { |
| 5232 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5233 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5234 | } |
| 5235 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5236 | // { x++; v = x; } |
| 5237 | // { x--; v = x; } |
| 5238 | // { ++x; v = x; } |
| 5239 | // { --x; v = x; } |
| 5240 | // { x binop= expr; v = x; } |
| 5241 | // { x = x binop expr; v = x; } |
| 5242 | // { x = expr binop x; v = x; } |
| 5243 | // Check that the second expression has form v = x. |
| 5244 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5245 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5246 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5247 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5248 | IsUpdateExprFound = XId == PossibleXId; |
| 5249 | if (IsUpdateExprFound) { |
| 5250 | V = BinOp->getLHS(); |
| 5251 | X = Checker.getX(); |
| 5252 | E = Checker.getExpr(); |
| 5253 | UE = Checker.getUpdateExpr(); |
| 5254 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5255 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5256 | } |
| 5257 | } |
| 5258 | } |
| 5259 | if (!IsUpdateExprFound) { |
| 5260 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5261 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5262 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5263 | if (!FirstExpr || !SecondExpr || |
| 5264 | !(FirstExpr->isInstantiationDependent() || |
| 5265 | SecondExpr->isInstantiationDependent())) { |
| 5266 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5267 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5268 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5269 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5270 | : First->getLocStart(); |
| 5271 | NoteRange = ErrorRange = FirstBinOp |
| 5272 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5273 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5274 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5275 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5276 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5277 | ErrorFound = NotAnAssignmentOp; |
| 5278 | NoteLoc = ErrorLoc = SecondBinOp |
| 5279 | ? SecondBinOp->getOperatorLoc() |
| 5280 | : Second->getLocStart(); |
| 5281 | NoteRange = ErrorRange = |
| 5282 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5283 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5284 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5285 | auto *PossibleXRHSInFirst = |
| 5286 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5287 | auto *PossibleXLHSInSecond = |
| 5288 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5289 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5290 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5291 | /*Canonical=*/true); |
| 5292 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5293 | /*Canonical=*/true); |
| 5294 | IsUpdateExprFound = X1Id == X2Id; |
| 5295 | if (IsUpdateExprFound) { |
| 5296 | V = FirstBinOp->getLHS(); |
| 5297 | X = SecondBinOp->getLHS(); |
| 5298 | E = SecondBinOp->getRHS(); |
| 5299 | UE = nullptr; |
| 5300 | IsXLHSInRHSPart = false; |
| 5301 | IsPostfixUpdate = true; |
| 5302 | } else { |
| 5303 | ErrorFound = NotASpecificExpression; |
| 5304 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5305 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5306 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5307 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5308 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5309 | } |
| 5310 | } |
| 5311 | } |
| 5312 | } |
| 5313 | } else { |
| 5314 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5315 | NoteRange = ErrorRange = |
| 5316 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5317 | ErrorFound = NotTwoSubstatements; |
| 5318 | } |
| 5319 | } else { |
| 5320 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5321 | NoteRange = ErrorRange = |
| 5322 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5323 | ErrorFound = NotACompoundStatement; |
| 5324 | } |
| 5325 | if (ErrorFound != NoError) { |
| 5326 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5327 | << ErrorRange; |
| 5328 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5329 | return StmtError(); |
| 5330 | } else if (CurContext->isDependentContext()) { |
| 5331 | UE = V = E = X = nullptr; |
| 5332 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5333 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5334 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5335 | |
| 5336 | getCurFunction()->setHasBranchProtectedScope(); |
| 5337 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5338 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5339 | X, V, E, UE, IsXLHSInRHSPart, |
| 5340 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5343 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5344 | Stmt *AStmt, |
| 5345 | SourceLocation StartLoc, |
| 5346 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5347 | if (!AStmt) |
| 5348 | return StmtError(); |
| 5349 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5350 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5351 | // 1.2.2 OpenMP Language Terminology |
| 5352 | // Structured block - An executable statement with a single entry at the |
| 5353 | // top and a single exit at the bottom. |
| 5354 | // The point of exit cannot be a branch out of the structured block. |
| 5355 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5356 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5357 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5358 | // OpenMP [2.16, Nesting of Regions] |
| 5359 | // If specified, a teams construct must be contained within a target |
| 5360 | // construct. That target construct must contain no statements or directives |
| 5361 | // outside of the teams construct. |
| 5362 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5363 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5364 | bool OMPTeamsFound = true; |
| 5365 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5366 | auto I = CS->body_begin(); |
| 5367 | while (I != CS->body_end()) { |
| 5368 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5369 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5370 | OMPTeamsFound = false; |
| 5371 | break; |
| 5372 | } |
| 5373 | ++I; |
| 5374 | } |
| 5375 | assert(I != CS->body_end() && "Not found statement"); |
| 5376 | S = *I; |
| 5377 | } |
| 5378 | if (!OMPTeamsFound) { |
| 5379 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5380 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5381 | diag::note_omp_nested_teams_construct_here); |
| 5382 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5383 | << isa<OMPExecutableDirective>(S); |
| 5384 | return StmtError(); |
| 5385 | } |
| 5386 | } |
| 5387 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5388 | getCurFunction()->setHasBranchProtectedScope(); |
| 5389 | |
| 5390 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5391 | } |
| 5392 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5393 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5394 | Stmt *AStmt, |
| 5395 | SourceLocation StartLoc, |
| 5396 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5397 | if (!AStmt) |
| 5398 | return StmtError(); |
| 5399 | |
| 5400 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5401 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5402 | getCurFunction()->setHasBranchProtectedScope(); |
| 5403 | |
| 5404 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5405 | AStmt); |
| 5406 | } |
| 5407 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5408 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5409 | Stmt *AStmt, SourceLocation StartLoc, |
| 5410 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5411 | if (!AStmt) |
| 5412 | return StmtError(); |
| 5413 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5414 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5415 | // 1.2.2 OpenMP Language Terminology |
| 5416 | // Structured block - An executable statement with a single entry at the |
| 5417 | // top and a single exit at the bottom. |
| 5418 | // The point of exit cannot be a branch out of the structured block. |
| 5419 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5420 | CS->getCapturedDecl()->setNothrow(); |
| 5421 | |
| 5422 | getCurFunction()->setHasBranchProtectedScope(); |
| 5423 | |
| 5424 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5425 | } |
| 5426 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5427 | StmtResult |
| 5428 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5429 | SourceLocation EndLoc, |
| 5430 | OpenMPDirectiveKind CancelRegion) { |
| 5431 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5432 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5433 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5434 | << getOpenMPDirectiveName(CancelRegion); |
| 5435 | return StmtError(); |
| 5436 | } |
| 5437 | if (DSAStack->isParentNowaitRegion()) { |
| 5438 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5439 | return StmtError(); |
| 5440 | } |
| 5441 | if (DSAStack->isParentOrderedRegion()) { |
| 5442 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5443 | return StmtError(); |
| 5444 | } |
| 5445 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5446 | CancelRegion); |
| 5447 | } |
| 5448 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5449 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5450 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5451 | SourceLocation EndLoc, |
| 5452 | OpenMPDirectiveKind CancelRegion) { |
| 5453 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5454 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5455 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5456 | << getOpenMPDirectiveName(CancelRegion); |
| 5457 | return StmtError(); |
| 5458 | } |
| 5459 | if (DSAStack->isParentNowaitRegion()) { |
| 5460 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5461 | return StmtError(); |
| 5462 | } |
| 5463 | if (DSAStack->isParentOrderedRegion()) { |
| 5464 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5465 | return StmtError(); |
| 5466 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5467 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5468 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5469 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5472 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5473 | ArrayRef<OMPClause *> Clauses) { |
| 5474 | OMPClause *PrevClause = nullptr; |
| 5475 | bool ErrorFound = false; |
| 5476 | for (auto *C : Clauses) { |
| 5477 | if (C->getClauseKind() == OMPC_grainsize || |
| 5478 | C->getClauseKind() == OMPC_num_tasks) { |
| 5479 | if (!PrevClause) |
| 5480 | PrevClause = C; |
| 5481 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5482 | S.Diag(C->getLocStart(), |
| 5483 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5484 | << getOpenMPClauseName(C->getClauseKind()) |
| 5485 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5486 | S.Diag(PrevClause->getLocStart(), |
| 5487 | diag::note_omp_previous_grainsize_num_tasks) |
| 5488 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5489 | ErrorFound = true; |
| 5490 | } |
| 5491 | } |
| 5492 | } |
| 5493 | return ErrorFound; |
| 5494 | } |
| 5495 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5496 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5497 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5498 | SourceLocation EndLoc, |
| 5499 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5500 | if (!AStmt) |
| 5501 | return StmtError(); |
| 5502 | |
| 5503 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5504 | OMPLoopDirective::HelperExprs B; |
| 5505 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5506 | // define the nested loops number. |
| 5507 | unsigned NestedLoopCount = |
| 5508 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5509 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5510 | VarsWithImplicitDSA, B); |
| 5511 | if (NestedLoopCount == 0) |
| 5512 | return StmtError(); |
| 5513 | |
| 5514 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5515 | "omp for loop exprs were not built"); |
| 5516 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5517 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5518 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5519 | // not appear on the same taskloop directive. |
| 5520 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5521 | return StmtError(); |
| 5522 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5523 | getCurFunction()->setHasBranchProtectedScope(); |
| 5524 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5525 | NestedLoopCount, Clauses, AStmt, B); |
| 5526 | } |
| 5527 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5528 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5529 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5530 | SourceLocation EndLoc, |
| 5531 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5532 | if (!AStmt) |
| 5533 | return StmtError(); |
| 5534 | |
| 5535 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5536 | OMPLoopDirective::HelperExprs B; |
| 5537 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5538 | // define the nested loops number. |
| 5539 | unsigned NestedLoopCount = |
| 5540 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5541 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5542 | VarsWithImplicitDSA, B); |
| 5543 | if (NestedLoopCount == 0) |
| 5544 | return StmtError(); |
| 5545 | |
| 5546 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5547 | "omp for loop exprs were not built"); |
| 5548 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5549 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5550 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5551 | // not appear on the same taskloop directive. |
| 5552 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5553 | return StmtError(); |
| 5554 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5555 | getCurFunction()->setHasBranchProtectedScope(); |
| 5556 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5557 | NestedLoopCount, Clauses, AStmt, B); |
| 5558 | } |
| 5559 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5560 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5561 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5562 | SourceLocation EndLoc, |
| 5563 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5564 | if (!AStmt) |
| 5565 | return StmtError(); |
| 5566 | |
| 5567 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5568 | OMPLoopDirective::HelperExprs B; |
| 5569 | // In presence of clause 'collapse' with number of loops, it will |
| 5570 | // define the nested loops number. |
| 5571 | unsigned NestedLoopCount = |
| 5572 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5573 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5574 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5575 | if (NestedLoopCount == 0) |
| 5576 | return StmtError(); |
| 5577 | |
| 5578 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5579 | "omp for loop exprs were not built"); |
| 5580 | |
| 5581 | getCurFunction()->setHasBranchProtectedScope(); |
| 5582 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5583 | NestedLoopCount, Clauses, AStmt, B); |
| 5584 | } |
| 5585 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5586 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5587 | SourceLocation StartLoc, |
| 5588 | SourceLocation LParenLoc, |
| 5589 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5590 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5591 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5592 | case OMPC_final: |
| 5593 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5594 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5595 | case OMPC_num_threads: |
| 5596 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5597 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5598 | case OMPC_safelen: |
| 5599 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5600 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5601 | case OMPC_simdlen: |
| 5602 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5603 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5604 | case OMPC_collapse: |
| 5605 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5606 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5607 | case OMPC_ordered: |
| 5608 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5609 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5610 | case OMPC_device: |
| 5611 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5612 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5613 | case OMPC_num_teams: |
| 5614 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5615 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5616 | case OMPC_thread_limit: |
| 5617 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5618 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5619 | case OMPC_priority: |
| 5620 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5621 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5622 | case OMPC_grainsize: |
| 5623 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5624 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5625 | case OMPC_num_tasks: |
| 5626 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5627 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5628 | case OMPC_hint: |
| 5629 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5630 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5631 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5632 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5633 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5634 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5635 | case OMPC_private: |
| 5636 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5637 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5638 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5639 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5640 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5641 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5642 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5643 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5644 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5645 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5646 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5647 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5648 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5649 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5650 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5651 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5652 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5653 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5654 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5655 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5656 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5657 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5658 | case OMPC_nogroup: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5659 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5660 | llvm_unreachable("Clause is not allowed."); |
| 5661 | } |
| 5662 | return Res; |
| 5663 | } |
| 5664 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5665 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5666 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5667 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5668 | SourceLocation NameModifierLoc, |
| 5669 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5670 | SourceLocation EndLoc) { |
| 5671 | Expr *ValExpr = Condition; |
| 5672 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5673 | !Condition->isInstantiationDependent() && |
| 5674 | !Condition->containsUnexpandedParameterPack()) { |
| 5675 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5676 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5677 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5678 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5679 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5680 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5683 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5684 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5685 | } |
| 5686 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5687 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5688 | SourceLocation StartLoc, |
| 5689 | SourceLocation LParenLoc, |
| 5690 | SourceLocation EndLoc) { |
| 5691 | Expr *ValExpr = Condition; |
| 5692 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5693 | !Condition->isInstantiationDependent() && |
| 5694 | !Condition->containsUnexpandedParameterPack()) { |
| 5695 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5696 | Condition->getExprLoc(), Condition); |
| 5697 | if (Val.isInvalid()) |
| 5698 | return nullptr; |
| 5699 | |
| 5700 | ValExpr = Val.get(); |
| 5701 | } |
| 5702 | |
| 5703 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5704 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5705 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5706 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5707 | if (!Op) |
| 5708 | return ExprError(); |
| 5709 | |
| 5710 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5711 | public: |
| 5712 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5713 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5714 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5715 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5716 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5717 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5718 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5719 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5720 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5721 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5722 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5723 | QualType T, |
| 5724 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5725 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5726 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5727 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5728 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5729 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5730 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5731 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5732 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5733 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5734 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5735 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5736 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5737 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5738 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5739 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5740 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5741 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5742 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5743 | llvm_unreachable("conversion functions are permitted"); |
| 5744 | } |
| 5745 | } ConvertDiagnoser; |
| 5746 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5747 | } |
| 5748 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5749 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5750 | OpenMPClauseKind CKind, |
| 5751 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5752 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5753 | !ValExpr->isInstantiationDependent()) { |
| 5754 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5755 | ExprResult Value = |
| 5756 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5757 | if (Value.isInvalid()) |
| 5758 | return false; |
| 5759 | |
| 5760 | ValExpr = Value.get(); |
| 5761 | // The expression must evaluate to a non-negative integer value. |
| 5762 | llvm::APSInt Result; |
| 5763 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5764 | Result.isSigned() && |
| 5765 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5766 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5767 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5768 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5769 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5770 | return false; |
| 5771 | } |
| 5772 | } |
| 5773 | return true; |
| 5774 | } |
| 5775 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5776 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5777 | SourceLocation StartLoc, |
| 5778 | SourceLocation LParenLoc, |
| 5779 | SourceLocation EndLoc) { |
| 5780 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5781 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5782 | // OpenMP [2.5, Restrictions] |
| 5783 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5784 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5785 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5786 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5787 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5788 | return new (Context) |
| 5789 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5792 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5793 | OpenMPClauseKind CKind, |
| 5794 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5795 | if (!E) |
| 5796 | return ExprError(); |
| 5797 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5798 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5799 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5800 | llvm::APSInt Result; |
| 5801 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5802 | if (ICE.isInvalid()) |
| 5803 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5804 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 5805 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5806 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5807 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5808 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5809 | return ExprError(); |
| 5810 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5811 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5812 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5813 | << E->getSourceRange(); |
| 5814 | return ExprError(); |
| 5815 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5816 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 5817 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5818 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5819 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5820 | return ICE; |
| 5821 | } |
| 5822 | |
| 5823 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5824 | SourceLocation LParenLoc, |
| 5825 | SourceLocation EndLoc) { |
| 5826 | // OpenMP [2.8.1, simd construct, Description] |
| 5827 | // The parameter of the safelen clause must be a constant |
| 5828 | // positive integer expression. |
| 5829 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5830 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5831 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5832 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5833 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5836 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5837 | SourceLocation LParenLoc, |
| 5838 | SourceLocation EndLoc) { |
| 5839 | // OpenMP [2.8.1, simd construct, Description] |
| 5840 | // The parameter of the simdlen clause must be a constant |
| 5841 | // positive integer expression. |
| 5842 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5843 | if (Simdlen.isInvalid()) |
| 5844 | return nullptr; |
| 5845 | return new (Context) |
| 5846 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5847 | } |
| 5848 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5849 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5850 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5851 | SourceLocation LParenLoc, |
| 5852 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5853 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5854 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5855 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5856 | // The parameter of the collapse clause must be a constant |
| 5857 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5858 | ExprResult NumForLoopsResult = |
| 5859 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5860 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5861 | return nullptr; |
| 5862 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5863 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5866 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5867 | SourceLocation EndLoc, |
| 5868 | SourceLocation LParenLoc, |
| 5869 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5870 | // OpenMP [2.7.1, loop construct, Description] |
| 5871 | // OpenMP [2.8.1, simd construct, Description] |
| 5872 | // OpenMP [2.9.6, distribute construct, Description] |
| 5873 | // The parameter of the ordered clause must be a constant |
| 5874 | // positive integer expression if any. |
| 5875 | if (NumForLoops && LParenLoc.isValid()) { |
| 5876 | ExprResult NumForLoopsResult = |
| 5877 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5878 | if (NumForLoopsResult.isInvalid()) |
| 5879 | return nullptr; |
| 5880 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5881 | } else |
| 5882 | NumForLoops = nullptr; |
| 5883 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5884 | return new (Context) |
| 5885 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5886 | } |
| 5887 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5888 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5889 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5890 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5891 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5892 | switch (Kind) { |
| 5893 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5894 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5895 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5896 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5897 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5898 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5899 | Res = ActOnOpenMPProcBindClause( |
| 5900 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5901 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5902 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5903 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5904 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5905 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5906 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5907 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5908 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5909 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5910 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5911 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5912 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5913 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5914 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5915 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5916 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5917 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5918 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5919 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5920 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5921 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5922 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5923 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5924 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5925 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5926 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5927 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5928 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5929 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5930 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5931 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5932 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5933 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5934 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5935 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5936 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5937 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5938 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5939 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5940 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5941 | case OMPC_hint: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5942 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5943 | llvm_unreachable("Clause is not allowed."); |
| 5944 | } |
| 5945 | return Res; |
| 5946 | } |
| 5947 | |
| 5948 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5949 | SourceLocation KindKwLoc, |
| 5950 | SourceLocation StartLoc, |
| 5951 | SourceLocation LParenLoc, |
| 5952 | SourceLocation EndLoc) { |
| 5953 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5954 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5955 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5956 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5957 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5958 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5959 | Values += "'"; |
| 5960 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5961 | Values += "'"; |
| 5962 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5963 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5964 | Values += " or "; |
| 5965 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5966 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5967 | break; |
| 5968 | default: |
| 5969 | Values += Sep; |
| 5970 | break; |
| 5971 | } |
| 5972 | } |
| 5973 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5974 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5975 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5976 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5977 | switch (Kind) { |
| 5978 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5979 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5980 | break; |
| 5981 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5982 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5983 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5984 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5985 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5986 | break; |
| 5987 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5988 | return new (Context) |
| 5989 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5992 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5993 | SourceLocation KindKwLoc, |
| 5994 | SourceLocation StartLoc, |
| 5995 | SourceLocation LParenLoc, |
| 5996 | SourceLocation EndLoc) { |
| 5997 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5998 | std::string Values; |
| 5999 | std::string Sep(", "); |
| 6000 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 6001 | Values += "'"; |
| 6002 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 6003 | Values += "'"; |
| 6004 | switch (i) { |
| 6005 | case OMPC_PROC_BIND_unknown - 2: |
| 6006 | Values += " or "; |
| 6007 | break; |
| 6008 | case OMPC_PROC_BIND_unknown - 1: |
| 6009 | break; |
| 6010 | default: |
| 6011 | Values += Sep; |
| 6012 | break; |
| 6013 | } |
| 6014 | } |
| 6015 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6016 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6017 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6018 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6019 | return new (Context) |
| 6020 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6023 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 6024 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 6025 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6026 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6027 | SourceLocation EndLoc) { |
| 6028 | OMPClause *Res = nullptr; |
| 6029 | switch (Kind) { |
| 6030 | case OMPC_schedule: |
| 6031 | Res = ActOnOpenMPScheduleClause( |
| 6032 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6033 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6034 | break; |
| 6035 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6036 | Res = |
| 6037 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 6038 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 6039 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6040 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6041 | case OMPC_num_threads: |
| 6042 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6043 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6044 | case OMPC_collapse: |
| 6045 | case OMPC_default: |
| 6046 | case OMPC_proc_bind: |
| 6047 | case OMPC_private: |
| 6048 | case OMPC_firstprivate: |
| 6049 | case OMPC_lastprivate: |
| 6050 | case OMPC_shared: |
| 6051 | case OMPC_reduction: |
| 6052 | case OMPC_linear: |
| 6053 | case OMPC_aligned: |
| 6054 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6055 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6056 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6057 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6058 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6059 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6060 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6061 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6062 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6063 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6064 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6065 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6066 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6067 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6068 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6069 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6070 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6071 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6072 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6073 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6074 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6075 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6076 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6077 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6078 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6079 | case OMPC_unknown: |
| 6080 | llvm_unreachable("Clause is not allowed."); |
| 6081 | } |
| 6082 | return Res; |
| 6083 | } |
| 6084 | |
| 6085 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 6086 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 6087 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 6088 | SourceLocation EndLoc) { |
| 6089 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6090 | std::string Values; |
| 6091 | std::string Sep(", "); |
| 6092 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 6093 | Values += "'"; |
| 6094 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 6095 | Values += "'"; |
| 6096 | switch (i) { |
| 6097 | case OMPC_SCHEDULE_unknown - 2: |
| 6098 | Values += " or "; |
| 6099 | break; |
| 6100 | case OMPC_SCHEDULE_unknown - 1: |
| 6101 | break; |
| 6102 | default: |
| 6103 | Values += Sep; |
| 6104 | break; |
| 6105 | } |
| 6106 | } |
| 6107 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6108 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6109 | return nullptr; |
| 6110 | } |
| 6111 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6112 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6113 | if (ChunkSize) { |
| 6114 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6115 | !ChunkSize->isInstantiationDependent() && |
| 6116 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6117 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6118 | ExprResult Val = |
| 6119 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6120 | if (Val.isInvalid()) |
| 6121 | return nullptr; |
| 6122 | |
| 6123 | ValExpr = Val.get(); |
| 6124 | |
| 6125 | // OpenMP [2.7.1, Restrictions] |
| 6126 | // chunk_size must be a loop invariant integer expression with a positive |
| 6127 | // value. |
| 6128 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6129 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6130 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6131 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6132 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6133 | return nullptr; |
| 6134 | } |
| 6135 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6136 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6137 | ChunkSize->getType(), ".chunk."); |
| 6138 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6139 | ChunkSize->getExprLoc(), |
| 6140 | /*RefersToCapture=*/true); |
| 6141 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6142 | } |
| 6143 | } |
| 6144 | } |
| 6145 | |
| 6146 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6147 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6148 | } |
| 6149 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6150 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6151 | SourceLocation StartLoc, |
| 6152 | SourceLocation EndLoc) { |
| 6153 | OMPClause *Res = nullptr; |
| 6154 | switch (Kind) { |
| 6155 | case OMPC_ordered: |
| 6156 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6157 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6158 | case OMPC_nowait: |
| 6159 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6160 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6161 | case OMPC_untied: |
| 6162 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6163 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6164 | case OMPC_mergeable: |
| 6165 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6166 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6167 | case OMPC_read: |
| 6168 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6169 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6170 | case OMPC_write: |
| 6171 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6172 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6173 | case OMPC_update: |
| 6174 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6175 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6176 | case OMPC_capture: |
| 6177 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6178 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6179 | case OMPC_seq_cst: |
| 6180 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6181 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6182 | case OMPC_threads: |
| 6183 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6184 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6185 | case OMPC_simd: |
| 6186 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6187 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6188 | case OMPC_nogroup: |
| 6189 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6190 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6191 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6192 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6193 | case OMPC_num_threads: |
| 6194 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6195 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6196 | case OMPC_collapse: |
| 6197 | case OMPC_schedule: |
| 6198 | case OMPC_private: |
| 6199 | case OMPC_firstprivate: |
| 6200 | case OMPC_lastprivate: |
| 6201 | case OMPC_shared: |
| 6202 | case OMPC_reduction: |
| 6203 | case OMPC_linear: |
| 6204 | case OMPC_aligned: |
| 6205 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6206 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6207 | case OMPC_default: |
| 6208 | case OMPC_proc_bind: |
| 6209 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6210 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6211 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6212 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6213 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6214 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6215 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6216 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6217 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6218 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6219 | case OMPC_hint: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6220 | case OMPC_unknown: |
| 6221 | llvm_unreachable("Clause is not allowed."); |
| 6222 | } |
| 6223 | return Res; |
| 6224 | } |
| 6225 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6226 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6227 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6228 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6229 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6230 | } |
| 6231 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6232 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6233 | SourceLocation EndLoc) { |
| 6234 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6235 | } |
| 6236 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6237 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6238 | SourceLocation EndLoc) { |
| 6239 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6240 | } |
| 6241 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6242 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6243 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6244 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6245 | } |
| 6246 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6247 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6248 | SourceLocation EndLoc) { |
| 6249 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6250 | } |
| 6251 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6252 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6253 | SourceLocation EndLoc) { |
| 6254 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6255 | } |
| 6256 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6257 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6258 | SourceLocation EndLoc) { |
| 6259 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6260 | } |
| 6261 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6262 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6263 | SourceLocation EndLoc) { |
| 6264 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6265 | } |
| 6266 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6267 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6268 | SourceLocation EndLoc) { |
| 6269 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6270 | } |
| 6271 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6272 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6273 | SourceLocation EndLoc) { |
| 6274 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6275 | } |
| 6276 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6277 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6278 | SourceLocation EndLoc) { |
| 6279 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6280 | } |
| 6281 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6282 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6283 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6284 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6285 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6286 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6287 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6288 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6289 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6290 | switch (Kind) { |
| 6291 | case OMPC_private: |
| 6292 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6293 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6294 | case OMPC_firstprivate: |
| 6295 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6296 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6297 | case OMPC_lastprivate: |
| 6298 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6299 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6300 | case OMPC_shared: |
| 6301 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6302 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6303 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6304 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6305 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6306 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6307 | case OMPC_linear: |
| 6308 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6309 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6310 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6311 | case OMPC_aligned: |
| 6312 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6313 | ColonLoc, EndLoc); |
| 6314 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6315 | case OMPC_copyin: |
| 6316 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6317 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6318 | case OMPC_copyprivate: |
| 6319 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6320 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6321 | case OMPC_flush: |
| 6322 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6323 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6324 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6325 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6326 | StartLoc, LParenLoc, EndLoc); |
| 6327 | break; |
| 6328 | case OMPC_map: |
| 6329 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 6330 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6331 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6332 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6333 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6334 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6335 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6336 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6337 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6338 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6339 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6340 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6341 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6342 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6343 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6344 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6345 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6346 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6347 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6348 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6349 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6350 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6351 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6352 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6353 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6354 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6355 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6356 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6357 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6358 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6359 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6360 | case OMPC_hint: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6361 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6362 | llvm_unreachable("Clause is not allowed."); |
| 6363 | } |
| 6364 | return Res; |
| 6365 | } |
| 6366 | |
| 6367 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6368 | SourceLocation StartLoc, |
| 6369 | SourceLocation LParenLoc, |
| 6370 | SourceLocation EndLoc) { |
| 6371 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6372 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6373 | for (auto &RefExpr : VarList) { |
| 6374 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6375 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6376 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6377 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6378 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6379 | continue; |
| 6380 | } |
| 6381 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6382 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6383 | // OpenMP [2.1, C/C++] |
| 6384 | // A list item is a variable name. |
| 6385 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6386 | // A variable that is part of another variable (as an array or |
| 6387 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6388 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6389 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6390 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6391 | continue; |
| 6392 | } |
| 6393 | Decl *D = DE->getDecl(); |
| 6394 | VarDecl *VD = cast<VarDecl>(D); |
| 6395 | |
| 6396 | QualType Type = VD->getType(); |
| 6397 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6398 | // It will be analyzed later. |
| 6399 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6400 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6401 | continue; |
| 6402 | } |
| 6403 | |
| 6404 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6405 | // A variable that appears in a private clause must not have an incomplete |
| 6406 | // type or a reference type. |
| 6407 | if (RequireCompleteType(ELoc, Type, |
| 6408 | diag::err_omp_private_incomplete_type)) { |
| 6409 | continue; |
| 6410 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6411 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6412 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6413 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6414 | // in a Construct] |
| 6415 | // Variables with the predetermined data-sharing attributes may not be |
| 6416 | // listed in data-sharing attributes clauses, except for the cases |
| 6417 | // listed below. For these exceptions only, listing a predetermined |
| 6418 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6419 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6420 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6421 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6422 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6423 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6424 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6425 | continue; |
| 6426 | } |
| 6427 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6428 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6429 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6430 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6431 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6432 | << getOpenMPClauseName(OMPC_private) << Type |
| 6433 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6434 | bool IsDecl = |
| 6435 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6436 | Diag(VD->getLocation(), |
| 6437 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6438 | << VD; |
| 6439 | continue; |
| 6440 | } |
| 6441 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6442 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6443 | // A variable of class type (or array thereof) that appears in a private |
| 6444 | // clause requires an accessible, unambiguous default constructor for the |
| 6445 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6446 | // Generate helper private variable and initialize it with the default |
| 6447 | // value. The address of the original variable is replaced by the address of |
| 6448 | // the new private variable in CodeGen. This new variable is not added to |
| 6449 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6450 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6451 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6452 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6453 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6454 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6455 | if (VDPrivate->isInvalidDecl()) |
| 6456 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6457 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6458 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6459 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6460 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6461 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6462 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6465 | if (Vars.empty()) |
| 6466 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6467 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6468 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6469 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6470 | } |
| 6471 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6472 | namespace { |
| 6473 | class DiagsUninitializedSeveretyRAII { |
| 6474 | private: |
| 6475 | DiagnosticsEngine &Diags; |
| 6476 | SourceLocation SavedLoc; |
| 6477 | bool IsIgnored; |
| 6478 | |
| 6479 | public: |
| 6480 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6481 | bool IsIgnored) |
| 6482 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6483 | if (!IsIgnored) { |
| 6484 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6485 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6486 | } |
| 6487 | } |
| 6488 | ~DiagsUninitializedSeveretyRAII() { |
| 6489 | if (!IsIgnored) |
| 6490 | Diags.popMappings(SavedLoc); |
| 6491 | } |
| 6492 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6493 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6494 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6495 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6496 | SourceLocation StartLoc, |
| 6497 | SourceLocation LParenLoc, |
| 6498 | SourceLocation EndLoc) { |
| 6499 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6500 | SmallVector<Expr *, 8> PrivateCopies; |
| 6501 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6502 | bool IsImplicitClause = |
| 6503 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6504 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6505 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6506 | for (auto &RefExpr : VarList) { |
| 6507 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6508 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6509 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6510 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6511 | PrivateCopies.push_back(nullptr); |
| 6512 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6513 | continue; |
| 6514 | } |
| 6515 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6516 | SourceLocation ELoc = |
| 6517 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6518 | // OpenMP [2.1, C/C++] |
| 6519 | // A list item is a variable name. |
| 6520 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6521 | // A variable that is part of another variable (as an array or |
| 6522 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6523 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6524 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6525 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6526 | continue; |
| 6527 | } |
| 6528 | Decl *D = DE->getDecl(); |
| 6529 | VarDecl *VD = cast<VarDecl>(D); |
| 6530 | |
| 6531 | QualType Type = VD->getType(); |
| 6532 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6533 | // It will be analyzed later. |
| 6534 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6535 | PrivateCopies.push_back(nullptr); |
| 6536 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6537 | continue; |
| 6538 | } |
| 6539 | |
| 6540 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6541 | // A variable that appears in a private clause must not have an incomplete |
| 6542 | // type or a reference type. |
| 6543 | if (RequireCompleteType(ELoc, Type, |
| 6544 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6545 | continue; |
| 6546 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6547 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6548 | |
| 6549 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6550 | // 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] | 6551 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6552 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6553 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6554 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6555 | // If an implicit firstprivate variable found it was checked already. |
| 6556 | if (!IsImplicitClause) { |
| 6557 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6558 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6559 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6560 | // A list item that specifies a given variable may not appear in more |
| 6561 | // than one clause on the same directive, except that a variable may be |
| 6562 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6563 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6564 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6565 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6566 | << getOpenMPClauseName(DVar.CKind) |
| 6567 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6568 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6569 | continue; |
| 6570 | } |
| 6571 | |
| 6572 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6573 | // in a Construct] |
| 6574 | // Variables with the predetermined data-sharing attributes may not be |
| 6575 | // listed in data-sharing attributes clauses, except for the cases |
| 6576 | // listed below. For these exceptions only, listing a predetermined |
| 6577 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6578 | // the variable's predetermined data-sharing attributes. |
| 6579 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6580 | // in a Construct, C/C++, p.2] |
| 6581 | // Variables with const-qualified type having no mutable member may be |
| 6582 | // listed in a firstprivate clause, even if they are static data members. |
| 6583 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6584 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6585 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6586 | << getOpenMPClauseName(DVar.CKind) |
| 6587 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6588 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6589 | continue; |
| 6590 | } |
| 6591 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6592 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6593 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6594 | // A list item that is private within a parallel region must not appear |
| 6595 | // in a firstprivate clause on a worksharing construct if any of the |
| 6596 | // worksharing regions arising from the worksharing construct ever bind |
| 6597 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6598 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6599 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6600 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6601 | if (DVar.CKind != OMPC_shared && |
| 6602 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6603 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6604 | Diag(ELoc, diag::err_omp_required_access) |
| 6605 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6606 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6607 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6608 | continue; |
| 6609 | } |
| 6610 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6611 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6612 | // A list item that appears in a reduction clause of a parallel construct |
| 6613 | // must not appear in a firstprivate clause on a worksharing or task |
| 6614 | // construct if any of the worksharing or task regions arising from the |
| 6615 | // worksharing or task construct ever bind to any of the parallel regions |
| 6616 | // arising from the parallel construct. |
| 6617 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6618 | // A list item that appears in a reduction clause in worksharing |
| 6619 | // construct must not appear in a firstprivate clause in a task construct |
| 6620 | // encountered during execution of any of the worksharing regions arising |
| 6621 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6622 | if (CurrDir == OMPD_task) { |
| 6623 | DVar = |
| 6624 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6625 | [](OpenMPDirectiveKind K) -> bool { |
| 6626 | return isOpenMPParallelDirective(K) || |
| 6627 | isOpenMPWorksharingDirective(K); |
| 6628 | }, |
| 6629 | false); |
| 6630 | if (DVar.CKind == OMPC_reduction && |
| 6631 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6632 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6633 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6634 | << getOpenMPDirectiveName(DVar.DKind); |
| 6635 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6636 | continue; |
| 6637 | } |
| 6638 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6639 | |
| 6640 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6641 | // A list item that is private within a teams region must not appear in a |
| 6642 | // firstprivate clause on a distribute construct if any of the distribute |
| 6643 | // regions arising from the distribute construct ever bind to any of the |
| 6644 | // teams regions arising from the teams construct. |
| 6645 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6646 | // A list item that appears in a reduction clause of a teams construct |
| 6647 | // must not appear in a firstprivate clause on a distribute construct if |
| 6648 | // any of the distribute regions arising from the distribute construct |
| 6649 | // ever bind to any of the teams regions arising from the teams construct. |
| 6650 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6651 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6652 | // both. |
| 6653 | if (CurrDir == OMPD_distribute) { |
| 6654 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6655 | [](OpenMPDirectiveKind K) -> bool { |
| 6656 | return isOpenMPTeamsDirective(K); |
| 6657 | }, |
| 6658 | false); |
| 6659 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6660 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6661 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6662 | continue; |
| 6663 | } |
| 6664 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6665 | [](OpenMPDirectiveKind K) -> bool { |
| 6666 | return isOpenMPTeamsDirective(K); |
| 6667 | }, |
| 6668 | false); |
| 6669 | if (DVar.CKind == OMPC_reduction && |
| 6670 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6671 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6672 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6673 | continue; |
| 6674 | } |
| 6675 | DVar = DSAStack->getTopDSA(VD, false); |
| 6676 | if (DVar.CKind == OMPC_lastprivate) { |
| 6677 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6678 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6679 | continue; |
| 6680 | } |
| 6681 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6682 | } |
| 6683 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6684 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6685 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6686 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6687 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6688 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6689 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6690 | bool IsDecl = |
| 6691 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6692 | Diag(VD->getLocation(), |
| 6693 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6694 | << VD; |
| 6695 | continue; |
| 6696 | } |
| 6697 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6698 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6699 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6700 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6701 | // Generate helper private variable and initialize it with the value of the |
| 6702 | // original variable. The address of the original variable is replaced by |
| 6703 | // the address of the new private variable in the CodeGen. This new variable |
| 6704 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6705 | // original variable for proper diagnostics and variable capturing. |
| 6706 | Expr *VDInitRefExpr = nullptr; |
| 6707 | // For arrays generate initializer for single element and replace it by the |
| 6708 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6709 | if (Type->isArrayType()) { |
| 6710 | auto VDInit = |
| 6711 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6712 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6713 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6714 | ElemType = ElemType.getUnqualifiedType(); |
| 6715 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6716 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6717 | InitializedEntity Entity = |
| 6718 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6719 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6720 | |
| 6721 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6722 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6723 | if (Result.isInvalid()) |
| 6724 | VDPrivate->setInvalidDecl(); |
| 6725 | else |
| 6726 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6727 | // Remove temp variable declaration. |
| 6728 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6729 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6730 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6731 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6732 | VDInitRefExpr = |
| 6733 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6734 | AddInitializerToDecl(VDPrivate, |
| 6735 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6736 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6737 | } |
| 6738 | if (VDPrivate->isInvalidDecl()) { |
| 6739 | if (IsImplicitClause) { |
| 6740 | Diag(DE->getExprLoc(), |
| 6741 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6742 | } |
| 6743 | continue; |
| 6744 | } |
| 6745 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6746 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6747 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6748 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6749 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6750 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6751 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6754 | if (Vars.empty()) |
| 6755 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6756 | |
| 6757 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6758 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6759 | } |
| 6760 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6761 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6762 | SourceLocation StartLoc, |
| 6763 | SourceLocation LParenLoc, |
| 6764 | SourceLocation EndLoc) { |
| 6765 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6766 | SmallVector<Expr *, 8> SrcExprs; |
| 6767 | SmallVector<Expr *, 8> DstExprs; |
| 6768 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6769 | for (auto &RefExpr : VarList) { |
| 6770 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6771 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6772 | // It will be analyzed later. |
| 6773 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6774 | SrcExprs.push_back(nullptr); |
| 6775 | DstExprs.push_back(nullptr); |
| 6776 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6777 | continue; |
| 6778 | } |
| 6779 | |
| 6780 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6781 | // OpenMP [2.1, C/C++] |
| 6782 | // A list item is a variable name. |
| 6783 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6784 | // A variable that is part of another variable (as an array or structure |
| 6785 | // element) cannot appear in a lastprivate clause. |
| 6786 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6787 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6788 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6789 | continue; |
| 6790 | } |
| 6791 | Decl *D = DE->getDecl(); |
| 6792 | VarDecl *VD = cast<VarDecl>(D); |
| 6793 | |
| 6794 | QualType Type = VD->getType(); |
| 6795 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6796 | // It will be analyzed later. |
| 6797 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6798 | SrcExprs.push_back(nullptr); |
| 6799 | DstExprs.push_back(nullptr); |
| 6800 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6801 | continue; |
| 6802 | } |
| 6803 | |
| 6804 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6805 | // A variable that appears in a lastprivate clause must not have an |
| 6806 | // incomplete type or a reference type. |
| 6807 | if (RequireCompleteType(ELoc, Type, |
| 6808 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6809 | continue; |
| 6810 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6811 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6812 | |
| 6813 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6814 | // in a Construct] |
| 6815 | // Variables with the predetermined data-sharing attributes may not be |
| 6816 | // listed in data-sharing attributes clauses, except for the cases |
| 6817 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6818 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6819 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6820 | DVar.CKind != OMPC_firstprivate && |
| 6821 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6822 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6823 | << getOpenMPClauseName(DVar.CKind) |
| 6824 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6825 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6826 | continue; |
| 6827 | } |
| 6828 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6829 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6830 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6831 | // A list item that is private within a parallel region, or that appears in |
| 6832 | // the reduction clause of a parallel construct, must not appear in a |
| 6833 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6834 | // worksharing regions ever binds to any of the corresponding parallel |
| 6835 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6836 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6837 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6838 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6839 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6840 | if (DVar.CKind != OMPC_shared) { |
| 6841 | Diag(ELoc, diag::err_omp_required_access) |
| 6842 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6843 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6844 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6845 | continue; |
| 6846 | } |
| 6847 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6848 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6849 | // A variable of class type (or array thereof) that appears in a |
| 6850 | // lastprivate clause requires an accessible, unambiguous default |
| 6851 | // constructor for the class type, unless the list item is also specified |
| 6852 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6853 | // A variable of class type (or array thereof) that appears in a |
| 6854 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6855 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6856 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6857 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6858 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6859 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6860 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6861 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6862 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6863 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6864 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6865 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6866 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6867 | // For arrays generate assignment operation for single element and replace |
| 6868 | // it by the original array element in CodeGen. |
| 6869 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6870 | PseudoDstExpr, PseudoSrcExpr); |
| 6871 | if (AssignmentOp.isInvalid()) |
| 6872 | continue; |
| 6873 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6874 | /*DiscardedValue=*/true); |
| 6875 | if (AssignmentOp.isInvalid()) |
| 6876 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6877 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6878 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6879 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6880 | // both. |
| 6881 | if (CurrDir == OMPD_distribute) { |
| 6882 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 6883 | if (DVar.CKind == OMPC_firstprivate) { |
| 6884 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6885 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6886 | continue; |
| 6887 | } |
| 6888 | } |
| 6889 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6890 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6891 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6892 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6893 | SrcExprs.push_back(PseudoSrcExpr); |
| 6894 | DstExprs.push_back(PseudoDstExpr); |
| 6895 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | if (Vars.empty()) |
| 6899 | return nullptr; |
| 6900 | |
| 6901 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6902 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6903 | } |
| 6904 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6905 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6906 | SourceLocation StartLoc, |
| 6907 | SourceLocation LParenLoc, |
| 6908 | SourceLocation EndLoc) { |
| 6909 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6910 | for (auto &RefExpr : VarList) { |
| 6911 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6912 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6913 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6914 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6915 | continue; |
| 6916 | } |
| 6917 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6918 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6919 | // OpenMP [2.1, C/C++] |
| 6920 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6921 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6922 | // A variable that is part of another variable (as an array or structure |
| 6923 | // element) cannot appear in a shared unless it is a static data member |
| 6924 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6925 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6926 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6927 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6928 | continue; |
| 6929 | } |
| 6930 | Decl *D = DE->getDecl(); |
| 6931 | VarDecl *VD = cast<VarDecl>(D); |
| 6932 | |
| 6933 | QualType Type = VD->getType(); |
| 6934 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6935 | // It will be analyzed later. |
| 6936 | Vars.push_back(DE); |
| 6937 | continue; |
| 6938 | } |
| 6939 | |
| 6940 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6941 | // in a Construct] |
| 6942 | // Variables with the predetermined data-sharing attributes may not be |
| 6943 | // listed in data-sharing attributes clauses, except for the cases |
| 6944 | // listed below. For these exceptions only, listing a predetermined |
| 6945 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6946 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6947 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6948 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6949 | DVar.RefExpr) { |
| 6950 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6951 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6952 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6953 | continue; |
| 6954 | } |
| 6955 | |
| 6956 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6957 | Vars.push_back(DE); |
| 6958 | } |
| 6959 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6960 | if (Vars.empty()) |
| 6961 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6962 | |
| 6963 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6964 | } |
| 6965 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6966 | namespace { |
| 6967 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6968 | DSAStackTy *Stack; |
| 6969 | |
| 6970 | public: |
| 6971 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6972 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6973 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6974 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6975 | return false; |
| 6976 | if (DVar.CKind != OMPC_unknown) |
| 6977 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6978 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6979 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6980 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6981 | return true; |
| 6982 | return false; |
| 6983 | } |
| 6984 | return false; |
| 6985 | } |
| 6986 | bool VisitStmt(Stmt *S) { |
| 6987 | for (auto Child : S->children()) { |
| 6988 | if (Child && Visit(Child)) |
| 6989 | return true; |
| 6990 | } |
| 6991 | return false; |
| 6992 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6993 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6994 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6995 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6996 | |
| 6997 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6998 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6999 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7000 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7001 | const DeclarationNameInfo &ReductionId) { |
| 7002 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7003 | // supported. |
| 7004 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7005 | "No support for scoped reduction identifiers yet."); |
| 7006 | |
| 7007 | auto DN = ReductionId.getName(); |
| 7008 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7009 | BinaryOperatorKind BOK = BO_Comma; |
| 7010 | |
| 7011 | // OpenMP [2.14.3.6, reduction clause] |
| 7012 | // C |
| 7013 | // reduction-identifier is either an identifier or one of the following |
| 7014 | // operators: +, -, *, &, |, ^, && and || |
| 7015 | // C++ |
| 7016 | // reduction-identifier is either an id-expression or one of the following |
| 7017 | // operators: +, -, *, &, |, ^, && and || |
| 7018 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7019 | switch (OOK) { |
| 7020 | case OO_Plus: |
| 7021 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7022 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7023 | break; |
| 7024 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7025 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7026 | break; |
| 7027 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7028 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7029 | break; |
| 7030 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7031 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7032 | break; |
| 7033 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7034 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7035 | break; |
| 7036 | case OO_AmpAmp: |
| 7037 | BOK = BO_LAnd; |
| 7038 | break; |
| 7039 | case OO_PipePipe: |
| 7040 | BOK = BO_LOr; |
| 7041 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7042 | case OO_New: |
| 7043 | case OO_Delete: |
| 7044 | case OO_Array_New: |
| 7045 | case OO_Array_Delete: |
| 7046 | case OO_Slash: |
| 7047 | case OO_Percent: |
| 7048 | case OO_Tilde: |
| 7049 | case OO_Exclaim: |
| 7050 | case OO_Equal: |
| 7051 | case OO_Less: |
| 7052 | case OO_Greater: |
| 7053 | case OO_LessEqual: |
| 7054 | case OO_GreaterEqual: |
| 7055 | case OO_PlusEqual: |
| 7056 | case OO_MinusEqual: |
| 7057 | case OO_StarEqual: |
| 7058 | case OO_SlashEqual: |
| 7059 | case OO_PercentEqual: |
| 7060 | case OO_CaretEqual: |
| 7061 | case OO_AmpEqual: |
| 7062 | case OO_PipeEqual: |
| 7063 | case OO_LessLess: |
| 7064 | case OO_GreaterGreater: |
| 7065 | case OO_LessLessEqual: |
| 7066 | case OO_GreaterGreaterEqual: |
| 7067 | case OO_EqualEqual: |
| 7068 | case OO_ExclaimEqual: |
| 7069 | case OO_PlusPlus: |
| 7070 | case OO_MinusMinus: |
| 7071 | case OO_Comma: |
| 7072 | case OO_ArrowStar: |
| 7073 | case OO_Arrow: |
| 7074 | case OO_Call: |
| 7075 | case OO_Subscript: |
| 7076 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7077 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7078 | case NUM_OVERLOADED_OPERATORS: |
| 7079 | llvm_unreachable("Unexpected reduction identifier"); |
| 7080 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7081 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7082 | if (II->isStr("max")) |
| 7083 | BOK = BO_GT; |
| 7084 | else if (II->isStr("min")) |
| 7085 | BOK = BO_LT; |
| 7086 | } |
| 7087 | break; |
| 7088 | } |
| 7089 | SourceRange ReductionIdRange; |
| 7090 | if (ReductionIdScopeSpec.isValid()) { |
| 7091 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7092 | } |
| 7093 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7094 | if (BOK == BO_Comma) { |
| 7095 | // Not allowed reduction identifier is found. |
| 7096 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7097 | << ReductionIdRange; |
| 7098 | return nullptr; |
| 7099 | } |
| 7100 | |
| 7101 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7102 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7103 | SmallVector<Expr *, 8> LHSs; |
| 7104 | SmallVector<Expr *, 8> RHSs; |
| 7105 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7106 | for (auto RefExpr : VarList) { |
| 7107 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7108 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7109 | // It will be analyzed later. |
| 7110 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7111 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7112 | LHSs.push_back(nullptr); |
| 7113 | RHSs.push_back(nullptr); |
| 7114 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7115 | continue; |
| 7116 | } |
| 7117 | |
| 7118 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7119 | RefExpr->isInstantiationDependent() || |
| 7120 | RefExpr->containsUnexpandedParameterPack()) { |
| 7121 | // It will be analyzed later. |
| 7122 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7123 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7124 | LHSs.push_back(nullptr); |
| 7125 | RHSs.push_back(nullptr); |
| 7126 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7127 | continue; |
| 7128 | } |
| 7129 | |
| 7130 | auto ELoc = RefExpr->getExprLoc(); |
| 7131 | auto ERange = RefExpr->getSourceRange(); |
| 7132 | // OpenMP [2.1, C/C++] |
| 7133 | // A list item is a variable or array section, subject to the restrictions |
| 7134 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7135 | // describing clauses and directives for which a list appears. |
| 7136 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7137 | // A variable that is part of another variable (as an array or |
| 7138 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7139 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7140 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7141 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7142 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 7143 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7144 | continue; |
| 7145 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7146 | QualType Type; |
| 7147 | VarDecl *VD = nullptr; |
| 7148 | if (DE) { |
| 7149 | auto D = DE->getDecl(); |
| 7150 | VD = cast<VarDecl>(D); |
| 7151 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7152 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7153 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7154 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7155 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7156 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7157 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7158 | if (DE) |
| 7159 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7160 | if (!VD) { |
| 7161 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7162 | << 0 << Base->getSourceRange(); |
| 7163 | continue; |
| 7164 | } |
| 7165 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7166 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7167 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7168 | Type = ATy->getElementType(); |
| 7169 | else |
| 7170 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7171 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7172 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7173 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7174 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7175 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7176 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7177 | if (DE) |
| 7178 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7179 | if (!VD) { |
| 7180 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7181 | << 1 << Base->getSourceRange(); |
| 7182 | continue; |
| 7183 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7186 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7187 | // A variable that appears in a private clause must not have an incomplete |
| 7188 | // type or a reference type. |
| 7189 | if (RequireCompleteType(ELoc, Type, |
| 7190 | diag::err_omp_reduction_incomplete_type)) |
| 7191 | continue; |
| 7192 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7193 | // Arrays may not appear in a reduction clause. |
| 7194 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7195 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7196 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7197 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7198 | VarDecl::DeclarationOnly; |
| 7199 | Diag(VD->getLocation(), |
| 7200 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7201 | << VD; |
| 7202 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7203 | continue; |
| 7204 | } |
| 7205 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7206 | // A list item that appears in a reduction clause must not be |
| 7207 | // const-qualified. |
| 7208 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7209 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7210 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7211 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7212 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7213 | VarDecl::DeclarationOnly; |
| 7214 | Diag(VD->getLocation(), |
| 7215 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7216 | << VD; |
| 7217 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7218 | continue; |
| 7219 | } |
| 7220 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7221 | // If a list-item is a reference type then it must bind to the same object |
| 7222 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7223 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7224 | VarDecl *VDDef = VD->getDefinition(); |
| 7225 | if (Type->isReferenceType() && VDDef) { |
| 7226 | DSARefChecker Check(DSAStack); |
| 7227 | if (Check.Visit(VDDef->getInit())) { |
| 7228 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7229 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7230 | continue; |
| 7231 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7232 | } |
| 7233 | } |
| 7234 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7235 | // The type of a list item that appears in a reduction clause must be valid |
| 7236 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7237 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7238 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7239 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7240 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7241 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7242 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7243 | !(Type->isScalarType() || |
| 7244 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7245 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7246 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7247 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7248 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7249 | VarDecl::DeclarationOnly; |
| 7250 | Diag(VD->getLocation(), |
| 7251 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7252 | << VD; |
| 7253 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7254 | continue; |
| 7255 | } |
| 7256 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7257 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7258 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7259 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7260 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7261 | VarDecl::DeclarationOnly; |
| 7262 | Diag(VD->getLocation(), |
| 7263 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7264 | << VD; |
| 7265 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7266 | continue; |
| 7267 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7268 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7269 | // in a Construct] |
| 7270 | // Variables with the predetermined data-sharing attributes may not be |
| 7271 | // listed in data-sharing attributes clauses, except for the cases |
| 7272 | // listed below. For these exceptions only, listing a predetermined |
| 7273 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7274 | // the variable's predetermined data-sharing attributes. |
| 7275 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7276 | // Any number of reduction clauses can be specified on the directive, |
| 7277 | // but a list item can appear only once in the reduction clauses for that |
| 7278 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7279 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7280 | DVar = DSAStack->getTopDSA(VD, false); |
| 7281 | if (DVar.CKind == OMPC_reduction) { |
| 7282 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7283 | << getOpenMPClauseName(OMPC_reduction); |
| 7284 | if (DVar.RefExpr) { |
| 7285 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7286 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7287 | } else if (DVar.CKind != OMPC_unknown) { |
| 7288 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7289 | << getOpenMPClauseName(DVar.CKind) |
| 7290 | << getOpenMPClauseName(OMPC_reduction); |
| 7291 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7292 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7293 | } |
| 7294 | |
| 7295 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7296 | // A list item that appears in a reduction clause of a worksharing |
| 7297 | // construct must be shared in the parallel regions to which any of the |
| 7298 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7299 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7300 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7301 | !isOpenMPParallelDirective(CurrDir)) { |
| 7302 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7303 | if (DVar.CKind != OMPC_shared) { |
| 7304 | Diag(ELoc, diag::err_omp_required_access) |
| 7305 | << getOpenMPClauseName(OMPC_reduction) |
| 7306 | << getOpenMPClauseName(OMPC_shared); |
| 7307 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7308 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7309 | } |
| 7310 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7311 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7312 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7313 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7314 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7315 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7316 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7317 | auto PrivateTy = Type; |
| 7318 | if (OASE) { |
| 7319 | // For array sections only: |
| 7320 | // Create pseudo array type for private copy. The size for this array will |
| 7321 | // be generated during codegen. |
| 7322 | // For array subscripts or single variables Private Ty is the same as Type |
| 7323 | // (type of the variable or single array element). |
| 7324 | PrivateTy = Context.getVariableArrayType( |
| 7325 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7326 | Context.getSizeType(), VK_RValue), |
| 7327 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7328 | } |
| 7329 | // Private copy. |
| 7330 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7331 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7332 | // Add initializer for private variable. |
| 7333 | Expr *Init = nullptr; |
| 7334 | switch (BOK) { |
| 7335 | case BO_Add: |
| 7336 | case BO_Xor: |
| 7337 | case BO_Or: |
| 7338 | case BO_LOr: |
| 7339 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7340 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7341 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7342 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7343 | break; |
| 7344 | case BO_Mul: |
| 7345 | case BO_LAnd: |
| 7346 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7347 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7348 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7349 | } |
| 7350 | break; |
| 7351 | case BO_And: { |
| 7352 | // '&' reduction op - initializer is '~0'. |
| 7353 | QualType OrigType = Type; |
| 7354 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7355 | Type = ComplexTy->getElementType(); |
| 7356 | } |
| 7357 | if (Type->isRealFloatingType()) { |
| 7358 | llvm::APFloat InitValue = |
| 7359 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7360 | /*isIEEE=*/true); |
| 7361 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7362 | Type, ELoc); |
| 7363 | } else if (Type->isScalarType()) { |
| 7364 | auto Size = Context.getTypeSize(Type); |
| 7365 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7366 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7367 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7368 | } |
| 7369 | if (Init && OrigType->isAnyComplexType()) { |
| 7370 | // Init = 0xFFFF + 0xFFFFi; |
| 7371 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7372 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7373 | } |
| 7374 | Type = OrigType; |
| 7375 | break; |
| 7376 | } |
| 7377 | case BO_LT: |
| 7378 | case BO_GT: { |
| 7379 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7380 | // the reduction list item type'. |
| 7381 | // 'max' reduction op - initializer is 'Least representable number in |
| 7382 | // the reduction list item type'. |
| 7383 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7384 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7385 | auto Size = Context.getTypeSize(Type); |
| 7386 | QualType IntTy = |
| 7387 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7388 | llvm::APInt InitValue = |
| 7389 | (BOK != BO_LT) |
| 7390 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7391 | : llvm::APInt::getMinValue(Size) |
| 7392 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7393 | : llvm::APInt::getMaxValue(Size); |
| 7394 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7395 | if (Type->isPointerType()) { |
| 7396 | // Cast to pointer type. |
| 7397 | auto CastExpr = BuildCStyleCastExpr( |
| 7398 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7399 | SourceLocation(), Init); |
| 7400 | if (CastExpr.isInvalid()) |
| 7401 | continue; |
| 7402 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7403 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7404 | } else if (Type->isRealFloatingType()) { |
| 7405 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7406 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7407 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7408 | Type, ELoc); |
| 7409 | } |
| 7410 | break; |
| 7411 | } |
| 7412 | case BO_PtrMemD: |
| 7413 | case BO_PtrMemI: |
| 7414 | case BO_MulAssign: |
| 7415 | case BO_Div: |
| 7416 | case BO_Rem: |
| 7417 | case BO_Sub: |
| 7418 | case BO_Shl: |
| 7419 | case BO_Shr: |
| 7420 | case BO_LE: |
| 7421 | case BO_GE: |
| 7422 | case BO_EQ: |
| 7423 | case BO_NE: |
| 7424 | case BO_AndAssign: |
| 7425 | case BO_XorAssign: |
| 7426 | case BO_OrAssign: |
| 7427 | case BO_Assign: |
| 7428 | case BO_AddAssign: |
| 7429 | case BO_SubAssign: |
| 7430 | case BO_DivAssign: |
| 7431 | case BO_RemAssign: |
| 7432 | case BO_ShlAssign: |
| 7433 | case BO_ShrAssign: |
| 7434 | case BO_Comma: |
| 7435 | llvm_unreachable("Unexpected reduction operation"); |
| 7436 | } |
| 7437 | if (Init) { |
| 7438 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7439 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7440 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7441 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7442 | if (!RHSVD->hasInit()) { |
| 7443 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7444 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7445 | if (VD) { |
| 7446 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7447 | VarDecl::DeclarationOnly; |
| 7448 | Diag(VD->getLocation(), |
| 7449 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7450 | << VD; |
| 7451 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7452 | continue; |
| 7453 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7454 | // Store initializer for single element in private copy. Will be used during |
| 7455 | // codegen. |
| 7456 | PrivateVD->setInit(RHSVD->getInit()); |
| 7457 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7458 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7459 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7460 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7461 | ExprResult ReductionOp = |
| 7462 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7463 | LHSDRE, RHSDRE); |
| 7464 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7465 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7466 | ReductionOp = |
| 7467 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7468 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7469 | } else { |
| 7470 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7471 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7472 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7473 | ReductionOp = |
| 7474 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7475 | BO_Assign, LHSDRE, ConditionalOp); |
| 7476 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7477 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7478 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7479 | if (ReductionOp.isInvalid()) |
| 7480 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7481 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7482 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7483 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7484 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7485 | LHSs.push_back(LHSDRE); |
| 7486 | RHSs.push_back(RHSDRE); |
| 7487 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | if (Vars.empty()) |
| 7491 | return nullptr; |
| 7492 | |
| 7493 | return OMPReductionClause::Create( |
| 7494 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7495 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7496 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7497 | } |
| 7498 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7499 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7500 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7501 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7502 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7503 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7504 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7505 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7506 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7507 | LinKind == OMPC_LINEAR_unknown) { |
| 7508 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7509 | LinKind = OMPC_LINEAR_val; |
| 7510 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7511 | for (auto &RefExpr : VarList) { |
| 7512 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7513 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7514 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7515 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7516 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7517 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7518 | continue; |
| 7519 | } |
| 7520 | |
| 7521 | // OpenMP [2.14.3.7, linear clause] |
| 7522 | // A list item that appears in a linear clause is subject to the private |
| 7523 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7524 | // noted. In addition, the value of the new list item on each iteration |
| 7525 | // of the associated loop(s) corresponds to the value of the original |
| 7526 | // list item before entering the construct plus the logical number of |
| 7527 | // the iteration times linear-step. |
| 7528 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7529 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7530 | // OpenMP [2.1, C/C++] |
| 7531 | // A list item is a variable name. |
| 7532 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7533 | // A variable that is part of another variable (as an array or |
| 7534 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7535 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7536 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7537 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7538 | continue; |
| 7539 | } |
| 7540 | |
| 7541 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7542 | |
| 7543 | // OpenMP [2.14.3.7, linear clause] |
| 7544 | // A list-item cannot appear in more than one linear clause. |
| 7545 | // A list-item that appears in a linear clause cannot appear in any |
| 7546 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7547 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7548 | if (DVar.RefExpr) { |
| 7549 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7550 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7551 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7552 | continue; |
| 7553 | } |
| 7554 | |
| 7555 | QualType QType = VD->getType(); |
| 7556 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7557 | // It will be analyzed later. |
| 7558 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7559 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7560 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7561 | continue; |
| 7562 | } |
| 7563 | |
| 7564 | // A variable must not have an incomplete type or a reference type. |
| 7565 | if (RequireCompleteType(ELoc, QType, |
| 7566 | diag::err_omp_linear_incomplete_type)) { |
| 7567 | continue; |
| 7568 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7569 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7570 | !QType->isReferenceType()) { |
| 7571 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7572 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7573 | continue; |
| 7574 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7575 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7576 | |
| 7577 | // A list item must not be const-qualified. |
| 7578 | if (QType.isConstant(Context)) { |
| 7579 | Diag(ELoc, diag::err_omp_const_variable) |
| 7580 | << getOpenMPClauseName(OMPC_linear); |
| 7581 | bool IsDecl = |
| 7582 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7583 | Diag(VD->getLocation(), |
| 7584 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7585 | << VD; |
| 7586 | continue; |
| 7587 | } |
| 7588 | |
| 7589 | // A list item must be of integral or pointer type. |
| 7590 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7591 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7592 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7593 | !Ty->isPointerType())) { |
| 7594 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7595 | bool IsDecl = |
| 7596 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7597 | Diag(VD->getLocation(), |
| 7598 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7599 | << VD; |
| 7600 | continue; |
| 7601 | } |
| 7602 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7603 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7604 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7605 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7606 | auto *PrivateRef = buildDeclRefExpr( |
| 7607 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7608 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7609 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7610 | Expr *InitExpr; |
| 7611 | if (LinKind == OMPC_LINEAR_uval) |
| 7612 | InitExpr = VD->getInit(); |
| 7613 | else |
| 7614 | InitExpr = DE; |
| 7615 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7616 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7617 | auto InitRef = buildDeclRefExpr( |
| 7618 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7619 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7620 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7621 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7622 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7623 | } |
| 7624 | |
| 7625 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7626 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7627 | |
| 7628 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7629 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7630 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7631 | !Step->isInstantiationDependent() && |
| 7632 | !Step->containsUnexpandedParameterPack()) { |
| 7633 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7634 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7635 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7636 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7637 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7638 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7639 | // Build var to save the step value. |
| 7640 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7641 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7642 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7643 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7644 | ExprResult CalcStep = |
| 7645 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7646 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7647 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7648 | // Warn about zero linear step (it would be probably better specified as |
| 7649 | // making corresponding variables 'const'). |
| 7650 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7651 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7652 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7653 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7654 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7655 | if (!IsConstant && CalcStep.isUsable()) { |
| 7656 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7657 | // (This is not used if the number of iterations may be kfold-ed). |
| 7658 | CalcStepExpr = CalcStep.get(); |
| 7659 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7660 | } |
| 7661 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7662 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7663 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7664 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7665 | } |
| 7666 | |
| 7667 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7668 | Expr *NumIterations, Sema &SemaRef, |
| 7669 | Scope *S) { |
| 7670 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7671 | SmallVector<Expr *, 8> Updates; |
| 7672 | SmallVector<Expr *, 8> Finals; |
| 7673 | Expr *Step = Clause.getStep(); |
| 7674 | Expr *CalcStep = Clause.getCalcStep(); |
| 7675 | // OpenMP [2.14.3.7, linear clause] |
| 7676 | // If linear-step is not specified it is assumed to be 1. |
| 7677 | if (Step == nullptr) |
| 7678 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7679 | else if (CalcStep) |
| 7680 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7681 | bool HasErrors = false; |
| 7682 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7683 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7684 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7685 | for (auto &RefExpr : Clause.varlists()) { |
| 7686 | Expr *InitExpr = *CurInit; |
| 7687 | |
| 7688 | // Build privatized reference to the current linear var. |
| 7689 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7690 | Expr *CapturedRef; |
| 7691 | if (LinKind == OMPC_LINEAR_uval) |
| 7692 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7693 | else |
| 7694 | CapturedRef = |
| 7695 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7696 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7697 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7698 | |
| 7699 | // Build update: Var = InitExpr + IV * Step |
| 7700 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7701 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7702 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7703 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7704 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7705 | |
| 7706 | // Build final: Var = InitExpr + NumIterations * Step |
| 7707 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7708 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7709 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7710 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7711 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7712 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7713 | Updates.push_back(nullptr); |
| 7714 | Finals.push_back(nullptr); |
| 7715 | HasErrors = true; |
| 7716 | } else { |
| 7717 | Updates.push_back(Update.get()); |
| 7718 | Finals.push_back(Final.get()); |
| 7719 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7720 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7721 | } |
| 7722 | Clause.setUpdates(Updates); |
| 7723 | Clause.setFinals(Finals); |
| 7724 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7725 | } |
| 7726 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7727 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7728 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7729 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7730 | |
| 7731 | SmallVector<Expr *, 8> Vars; |
| 7732 | for (auto &RefExpr : VarList) { |
| 7733 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7734 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7735 | // It will be analyzed later. |
| 7736 | Vars.push_back(RefExpr); |
| 7737 | continue; |
| 7738 | } |
| 7739 | |
| 7740 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7741 | // OpenMP [2.1, C/C++] |
| 7742 | // A list item is a variable name. |
| 7743 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7744 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7745 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7746 | continue; |
| 7747 | } |
| 7748 | |
| 7749 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7750 | |
| 7751 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7752 | // The type of list items appearing in the aligned clause must be |
| 7753 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7754 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7755 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7756 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7757 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7758 | !Ty->isPointerType())) { |
| 7759 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7760 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7761 | bool IsDecl = |
| 7762 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7763 | Diag(VD->getLocation(), |
| 7764 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7765 | << VD; |
| 7766 | continue; |
| 7767 | } |
| 7768 | |
| 7769 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7770 | // A list-item cannot appear in more than one aligned clause. |
| 7771 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7772 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7773 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7774 | << getOpenMPClauseName(OMPC_aligned); |
| 7775 | continue; |
| 7776 | } |
| 7777 | |
| 7778 | Vars.push_back(DE); |
| 7779 | } |
| 7780 | |
| 7781 | // OpenMP [2.8.1, simd construct, Description] |
| 7782 | // The parameter of the aligned clause, alignment, must be a constant |
| 7783 | // positive integer expression. |
| 7784 | // If no optional parameter is specified, implementation-defined default |
| 7785 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7786 | if (Alignment != nullptr) { |
| 7787 | ExprResult AlignResult = |
| 7788 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7789 | if (AlignResult.isInvalid()) |
| 7790 | return nullptr; |
| 7791 | Alignment = AlignResult.get(); |
| 7792 | } |
| 7793 | if (Vars.empty()) |
| 7794 | return nullptr; |
| 7795 | |
| 7796 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7797 | EndLoc, Vars, Alignment); |
| 7798 | } |
| 7799 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7800 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7801 | SourceLocation StartLoc, |
| 7802 | SourceLocation LParenLoc, |
| 7803 | SourceLocation EndLoc) { |
| 7804 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7805 | SmallVector<Expr *, 8> SrcExprs; |
| 7806 | SmallVector<Expr *, 8> DstExprs; |
| 7807 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7808 | for (auto &RefExpr : VarList) { |
| 7809 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7810 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7811 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7812 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7813 | SrcExprs.push_back(nullptr); |
| 7814 | DstExprs.push_back(nullptr); |
| 7815 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7816 | continue; |
| 7817 | } |
| 7818 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7819 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7820 | // OpenMP [2.1, C/C++] |
| 7821 | // A list item is a variable name. |
| 7822 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7823 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7824 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7825 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7826 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7827 | continue; |
| 7828 | } |
| 7829 | |
| 7830 | Decl *D = DE->getDecl(); |
| 7831 | VarDecl *VD = cast<VarDecl>(D); |
| 7832 | |
| 7833 | QualType Type = VD->getType(); |
| 7834 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7835 | // It will be analyzed later. |
| 7836 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7837 | SrcExprs.push_back(nullptr); |
| 7838 | DstExprs.push_back(nullptr); |
| 7839 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7840 | continue; |
| 7841 | } |
| 7842 | |
| 7843 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7844 | // A list item that appears in a copyin clause must be threadprivate. |
| 7845 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7846 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7847 | << getOpenMPClauseName(OMPC_copyin) |
| 7848 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7849 | continue; |
| 7850 | } |
| 7851 | |
| 7852 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7853 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7854 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7855 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7856 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7857 | auto *SrcVD = |
| 7858 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7859 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7860 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7861 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7862 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7863 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7864 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7865 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7866 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7867 | // For arrays generate assignment operation for single element and replace |
| 7868 | // it by the original array element in CodeGen. |
| 7869 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7870 | PseudoDstExpr, PseudoSrcExpr); |
| 7871 | if (AssignmentOp.isInvalid()) |
| 7872 | continue; |
| 7873 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7874 | /*DiscardedValue=*/true); |
| 7875 | if (AssignmentOp.isInvalid()) |
| 7876 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7877 | |
| 7878 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7879 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7880 | SrcExprs.push_back(PseudoSrcExpr); |
| 7881 | DstExprs.push_back(PseudoDstExpr); |
| 7882 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7883 | } |
| 7884 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7885 | if (Vars.empty()) |
| 7886 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7887 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7888 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7889 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7890 | } |
| 7891 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7892 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7893 | SourceLocation StartLoc, |
| 7894 | SourceLocation LParenLoc, |
| 7895 | SourceLocation EndLoc) { |
| 7896 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7897 | SmallVector<Expr *, 8> SrcExprs; |
| 7898 | SmallVector<Expr *, 8> DstExprs; |
| 7899 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7900 | for (auto &RefExpr : VarList) { |
| 7901 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7902 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7903 | // It will be analyzed later. |
| 7904 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7905 | SrcExprs.push_back(nullptr); |
| 7906 | DstExprs.push_back(nullptr); |
| 7907 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7908 | continue; |
| 7909 | } |
| 7910 | |
| 7911 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7912 | // OpenMP [2.1, C/C++] |
| 7913 | // A list item is a variable name. |
| 7914 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7915 | // A list item that appears in a copyin clause must be threadprivate. |
| 7916 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7917 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7918 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7919 | continue; |
| 7920 | } |
| 7921 | |
| 7922 | Decl *D = DE->getDecl(); |
| 7923 | VarDecl *VD = cast<VarDecl>(D); |
| 7924 | |
| 7925 | QualType Type = VD->getType(); |
| 7926 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7927 | // It will be analyzed later. |
| 7928 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7929 | SrcExprs.push_back(nullptr); |
| 7930 | DstExprs.push_back(nullptr); |
| 7931 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7932 | continue; |
| 7933 | } |
| 7934 | |
| 7935 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7936 | // A list item that appears in a copyprivate clause may not appear in a |
| 7937 | // private or firstprivate clause on the single construct. |
| 7938 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7939 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7940 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7941 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7942 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7943 | << getOpenMPClauseName(DVar.CKind) |
| 7944 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7945 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7946 | continue; |
| 7947 | } |
| 7948 | |
| 7949 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7950 | // All list items that appear in a copyprivate clause must be either |
| 7951 | // threadprivate or private in the enclosing context. |
| 7952 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7953 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7954 | if (DVar.CKind == OMPC_shared) { |
| 7955 | Diag(ELoc, diag::err_omp_required_access) |
| 7956 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7957 | << "threadprivate or private in the enclosing context"; |
| 7958 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7959 | continue; |
| 7960 | } |
| 7961 | } |
| 7962 | } |
| 7963 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7964 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7965 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7966 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7967 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7968 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7969 | bool IsDecl = |
| 7970 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7971 | Diag(VD->getLocation(), |
| 7972 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7973 | << VD; |
| 7974 | continue; |
| 7975 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7976 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7977 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7978 | // A variable of class type (or array thereof) that appears in a |
| 7979 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7980 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7981 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7982 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7983 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7984 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7985 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7986 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7987 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7988 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7989 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7990 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7991 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7992 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7993 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7994 | PseudoDstExpr, PseudoSrcExpr); |
| 7995 | if (AssignmentOp.isInvalid()) |
| 7996 | continue; |
| 7997 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7998 | /*DiscardedValue=*/true); |
| 7999 | if (AssignmentOp.isInvalid()) |
| 8000 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8001 | |
| 8002 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8003 | // implicitly private. |
| 8004 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8005 | SrcExprs.push_back(PseudoSrcExpr); |
| 8006 | DstExprs.push_back(PseudoDstExpr); |
| 8007 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8008 | } |
| 8009 | |
| 8010 | if (Vars.empty()) |
| 8011 | return nullptr; |
| 8012 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8013 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8014 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8015 | } |
| 8016 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8017 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8018 | SourceLocation StartLoc, |
| 8019 | SourceLocation LParenLoc, |
| 8020 | SourceLocation EndLoc) { |
| 8021 | if (VarList.empty()) |
| 8022 | return nullptr; |
| 8023 | |
| 8024 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8025 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8026 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8027 | OMPClause * |
| 8028 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8029 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8030 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8031 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8032 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8033 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8034 | std::string Values = "'"; |
| 8035 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, OMPC_DEPEND_source); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8036 | Values += "' or '"; |
| 8037 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, OMPC_DEPEND_sink); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8038 | Values += "'"; |
| 8039 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 8040 | << Values << getOpenMPClauseName(OMPC_depend); |
| 8041 | return nullptr; |
| 8042 | } |
| 8043 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8044 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8045 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8046 | std::string Values; |
| 8047 | std::string Sep(", "); |
| 8048 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8049 | if (i == OMPC_DEPEND_source || i == OMPC_DEPEND_sink) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8050 | continue; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8051 | Values += "'"; |
| 8052 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 8053 | Values += "'"; |
| 8054 | switch (i) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8055 | case OMPC_DEPEND_unknown - 4: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8056 | Values += " or "; |
| 8057 | break; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8058 | case OMPC_DEPEND_unknown - 3: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8059 | break; |
| 8060 | default: |
| 8061 | Values += Sep; |
| 8062 | break; |
| 8063 | } |
| 8064 | } |
| 8065 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 8066 | << Values << getOpenMPClauseName(OMPC_depend); |
| 8067 | return nullptr; |
| 8068 | } |
| 8069 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8070 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8071 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8072 | if (DepKind == OMPC_DEPEND_sink) { |
| 8073 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8074 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8075 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8076 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8077 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8078 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8079 | DSAStack->getParentOrderedRegionParam()) { |
| 8080 | for (auto &RefExpr : VarList) { |
| 8081 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8082 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8083 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8084 | // It will be analyzed later. |
| 8085 | Vars.push_back(RefExpr); |
| 8086 | continue; |
| 8087 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8088 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8089 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8090 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8091 | if (DepKind == OMPC_DEPEND_sink) { |
| 8092 | if (DepCounter >= TotalDepCount) { |
| 8093 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8094 | continue; |
| 8095 | } |
| 8096 | ++DepCounter; |
| 8097 | // OpenMP [2.13.9, Summary] |
| 8098 | // depend(dependence-type : vec), where dependence-type is: |
| 8099 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8100 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8101 | // where n is the value specified by the ordered clause in the loop |
| 8102 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8103 | // loop associated with the loop directive, and di is a constant |
| 8104 | // non-negative integer. |
| 8105 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8106 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8107 | if (!DE) { |
| 8108 | OverloadedOperatorKind OOK = OO_None; |
| 8109 | SourceLocation OOLoc; |
| 8110 | Expr *LHS, *RHS; |
| 8111 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8112 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8113 | OOLoc = BO->getOperatorLoc(); |
| 8114 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8115 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8116 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8117 | OOK = OCE->getOperator(); |
| 8118 | OOLoc = OCE->getOperatorLoc(); |
| 8119 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8120 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8121 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8122 | OOK = MCE->getMethodDecl() |
| 8123 | ->getNameInfo() |
| 8124 | .getName() |
| 8125 | .getCXXOverloadedOperator(); |
| 8126 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8127 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8128 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8129 | } else { |
| 8130 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8131 | continue; |
| 8132 | } |
| 8133 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8134 | if (!DE) { |
| 8135 | Diag(LHS->getExprLoc(), |
| 8136 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8137 | << DSAStack->getParentLoopControlVariable( |
| 8138 | DepCounter.getZExtValue()); |
| 8139 | continue; |
| 8140 | } |
| 8141 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8142 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8143 | continue; |
| 8144 | } |
| 8145 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8146 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8147 | if (Res.isInvalid()) |
| 8148 | continue; |
| 8149 | } |
| 8150 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8151 | if (!CurContext->isDependentContext() && |
| 8152 | DSAStack->getParentOrderedRegionParam() && |
| 8153 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8154 | Diag(DE->getExprLoc(), |
| 8155 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8156 | << DSAStack->getParentLoopControlVariable( |
| 8157 | DepCounter.getZExtValue()); |
| 8158 | continue; |
| 8159 | } |
| 8160 | } else { |
| 8161 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8162 | // A variable that is part of another variable (such as a field of a |
| 8163 | // structure) but is not an array element or an array section cannot |
| 8164 | // appear in a depend clause. |
| 8165 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8166 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8167 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8168 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8169 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8170 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8171 | !ASE->getBase()->getType()->isArrayType())) { |
| 8172 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8173 | << RefExpr->getSourceRange(); |
| 8174 | continue; |
| 8175 | } |
| 8176 | } |
| 8177 | |
| 8178 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8179 | } |
| 8180 | |
| 8181 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8182 | TotalDepCount > VarList.size() && |
| 8183 | DSAStack->getParentOrderedRegionParam()) { |
| 8184 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8185 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8186 | } |
| 8187 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8188 | Vars.empty()) |
| 8189 | return nullptr; |
| 8190 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8191 | |
| 8192 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8193 | DepLoc, ColonLoc, Vars); |
| 8194 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8195 | |
| 8196 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8197 | SourceLocation LParenLoc, |
| 8198 | SourceLocation EndLoc) { |
| 8199 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8200 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8201 | // OpenMP [2.9.1, Restrictions] |
| 8202 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8203 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8204 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8205 | return nullptr; |
| 8206 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8207 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8208 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8209 | |
| 8210 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8211 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8212 | if (!RD || RD->isInvalidDecl()) |
| 8213 | return true; |
| 8214 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8215 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8216 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8217 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8218 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8219 | if (RD->isDynamicClass()) { |
| 8220 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8221 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8222 | return false; |
| 8223 | } |
| 8224 | auto *DC = RD; |
| 8225 | bool IsCorrect = true; |
| 8226 | for (auto *I : DC->decls()) { |
| 8227 | if (I) { |
| 8228 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8229 | if (MD->isStatic()) { |
| 8230 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8231 | SemaRef.Diag(MD->getLocation(), |
| 8232 | diag::note_omp_static_member_in_target); |
| 8233 | IsCorrect = false; |
| 8234 | } |
| 8235 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8236 | if (VD->isStaticDataMember()) { |
| 8237 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8238 | SemaRef.Diag(VD->getLocation(), |
| 8239 | diag::note_omp_static_member_in_target); |
| 8240 | IsCorrect = false; |
| 8241 | } |
| 8242 | } |
| 8243 | } |
| 8244 | } |
| 8245 | |
| 8246 | for (auto &I : RD->bases()) { |
| 8247 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8248 | I.getType()->getAsCXXRecordDecl())) |
| 8249 | IsCorrect = false; |
| 8250 | } |
| 8251 | return IsCorrect; |
| 8252 | } |
| 8253 | |
| 8254 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8255 | DSAStackTy *Stack, QualType QTy) { |
| 8256 | NamedDecl *ND; |
| 8257 | if (QTy->isIncompleteType(&ND)) { |
| 8258 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8259 | return false; |
| 8260 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8261 | if (!RD->isInvalidDecl() && |
| 8262 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8263 | return false; |
| 8264 | } |
| 8265 | return true; |
| 8266 | } |
| 8267 | |
| 8268 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 8269 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 8270 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 8271 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 8272 | SmallVector<Expr *, 4> Vars; |
| 8273 | |
| 8274 | for (auto &RE : VarList) { |
| 8275 | assert(RE && "Null expr in omp map"); |
| 8276 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8277 | // It will be analyzed later. |
| 8278 | Vars.push_back(RE); |
| 8279 | continue; |
| 8280 | } |
| 8281 | SourceLocation ELoc = RE->getExprLoc(); |
| 8282 | |
| 8283 | // OpenMP [2.14.5, Restrictions] |
| 8284 | // A variable that is part of another variable (such as field of a |
| 8285 | // structure) but is not an array element or an array section cannot appear |
| 8286 | // in a map clause. |
| 8287 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8288 | |
| 8289 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8290 | VE->isInstantiationDependent() || |
| 8291 | VE->containsUnexpandedParameterPack()) { |
| 8292 | // It will be analyzed later. |
| 8293 | Vars.push_back(RE); |
| 8294 | continue; |
| 8295 | } |
| 8296 | |
| 8297 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8298 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8299 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8300 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8301 | |
| 8302 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8303 | (!OASE && !ASE && !DE) || |
| 8304 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8305 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8306 | !ASE->getBase()->getType()->isArrayType())) { |
| 8307 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8308 | << RE->getSourceRange(); |
| 8309 | continue; |
| 8310 | } |
| 8311 | |
| 8312 | Decl *D = nullptr; |
| 8313 | if (DE) { |
| 8314 | D = DE->getDecl(); |
| 8315 | } else if (ASE) { |
| 8316 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8317 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8318 | } else if (OASE) { |
| 8319 | auto *B = OASE->getBase(); |
| 8320 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8321 | } |
| 8322 | assert(D && "Null decl on map clause."); |
| 8323 | auto *VD = cast<VarDecl>(D); |
| 8324 | |
| 8325 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8326 | // threadprivate variables cannot appear in a map clause. |
| 8327 | if (DSAStack->isThreadPrivate(VD)) { |
| 8328 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8329 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8330 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8331 | continue; |
| 8332 | } |
| 8333 | |
| 8334 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8335 | // At most one list item can be an array item derived from a given variable |
| 8336 | // in map clauses of the same construct. |
| 8337 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8338 | // List items of map clauses in the same construct must not share original |
| 8339 | // storage. |
| 8340 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8341 | // A variable for which the type is pointer, reference to array, or |
| 8342 | // reference to pointer and an array section derived from that variable |
| 8343 | // must not appear as list items of map clauses of the same construct. |
| 8344 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8345 | if (MI.RefExpr) { |
| 8346 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8347 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8348 | << MI.RefExpr->getSourceRange(); |
| 8349 | continue; |
| 8350 | } |
| 8351 | |
| 8352 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8353 | // A variable for which the type is pointer, reference to array, or |
| 8354 | // reference to pointer must not appear as a list item if the enclosing |
| 8355 | // device data environment already contains an array section derived from |
| 8356 | // that variable. |
| 8357 | // An array section derived from a variable for which the type is pointer, |
| 8358 | // reference to array, or reference to pointer must not appear as a list |
| 8359 | // item if the enclosing device data environment already contains that |
| 8360 | // variable. |
| 8361 | QualType Type = VD->getType(); |
| 8362 | MI = DSAStack->getMapInfoForVar(VD); |
| 8363 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8364 | isa<DeclRefExpr>(VE)) && |
| 8365 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8366 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8367 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8368 | << MI.RefExpr->getSourceRange(); |
| 8369 | continue; |
| 8370 | } |
| 8371 | |
| 8372 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8373 | // A list item must have a mappable type. |
| 8374 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8375 | DSAStack, Type)) |
| 8376 | continue; |
| 8377 | |
| 8378 | Vars.push_back(RE); |
| 8379 | MI.RefExpr = RE; |
| 8380 | DSAStack->addMapInfoForVar(VD, MI); |
| 8381 | } |
| 8382 | if (Vars.empty()) |
| 8383 | return nullptr; |
| 8384 | |
| 8385 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8386 | MapTypeModifier, MapType, MapLoc); |
| 8387 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8388 | |
| 8389 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8390 | SourceLocation StartLoc, |
| 8391 | SourceLocation LParenLoc, |
| 8392 | SourceLocation EndLoc) { |
| 8393 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8394 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8395 | // OpenMP [teams Constrcut, Restrictions] |
| 8396 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8397 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8398 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8399 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8400 | |
| 8401 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8402 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8403 | |
| 8404 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8405 | SourceLocation StartLoc, |
| 8406 | SourceLocation LParenLoc, |
| 8407 | SourceLocation EndLoc) { |
| 8408 | Expr *ValExpr = ThreadLimit; |
| 8409 | |
| 8410 | // OpenMP [teams Constrcut, Restrictions] |
| 8411 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8412 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8413 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8414 | return nullptr; |
| 8415 | |
| 8416 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8417 | EndLoc); |
| 8418 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8419 | |
| 8420 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8421 | SourceLocation StartLoc, |
| 8422 | SourceLocation LParenLoc, |
| 8423 | SourceLocation EndLoc) { |
| 8424 | Expr *ValExpr = Priority; |
| 8425 | |
| 8426 | // OpenMP [2.9.1, task Constrcut] |
| 8427 | // The priority-value is a non-negative numerical scalar expression. |
| 8428 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8429 | /*StrictlyPositive=*/false)) |
| 8430 | return nullptr; |
| 8431 | |
| 8432 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8433 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8434 | |
| 8435 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8436 | SourceLocation StartLoc, |
| 8437 | SourceLocation LParenLoc, |
| 8438 | SourceLocation EndLoc) { |
| 8439 | Expr *ValExpr = Grainsize; |
| 8440 | |
| 8441 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8442 | // The parameter of the grainsize clause must be a positive integer |
| 8443 | // expression. |
| 8444 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8445 | /*StrictlyPositive=*/true)) |
| 8446 | return nullptr; |
| 8447 | |
| 8448 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8449 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8450 | |
| 8451 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 8452 | SourceLocation StartLoc, |
| 8453 | SourceLocation LParenLoc, |
| 8454 | SourceLocation EndLoc) { |
| 8455 | Expr *ValExpr = NumTasks; |
| 8456 | |
| 8457 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8458 | // The parameter of the num_tasks clause must be a positive integer |
| 8459 | // expression. |
| 8460 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 8461 | /*StrictlyPositive=*/true)) |
| 8462 | return nullptr; |
| 8463 | |
| 8464 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8465 | } |
| 8466 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8467 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 8468 | SourceLocation LParenLoc, |
| 8469 | SourceLocation EndLoc) { |
| 8470 | // OpenMP [2.13.2, critical construct, Description] |
| 8471 | // ... where hint-expression is an integer constant expression that evaluates |
| 8472 | // to a valid lock hint. |
| 8473 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 8474 | if (HintExpr.isInvalid()) |
| 8475 | return nullptr; |
| 8476 | return new (Context) |
| 8477 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 8478 | } |
| 8479 | |